Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,16 @@ object SettingsGeneralScreen : SearchableSettings {
}.sortedBy { fromTagToLanguageName(it) ?: it }

return persistentListOf(
Preference.PreferenceGroup(
title = stringResource(R.string.image_loading_options_title),
preferenceItems = persistentListOf(
Preference.PreferenceItem.ListPreference(
preference = settings.general.imageDecodingMode,
title = stringResource(R.string.image_decoding_title),
entries = mapOf("auto" to stringResource(R.string.image_decoding_automatic), "software" to stringResource(R.string.image_decoding_software)),
),
),
),
Preference.PreferenceGroup(title = stringResource(R.string.extension_language), preferenceItems = persistentListOf(
Preference.PreferenceItem.ListPreference(
preference = settings.general.locale,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lagradost.cloudstream3.utils

import android.graphics.Bitmap
import androidx.preference.PreferenceManager
import coil3.intercept.Interceptor
import coil3.request.ImageResult
import coil3.request.allowHardware
import coil3.request.bitmapConfig

internal class ImageDecodingPreferenceInterceptor : Interceptor {
override suspend fun intercept(chain: Interceptor.Chain): ImageResult {
val request = chain.request
val softwareSelected = PreferenceManager.getDefaultSharedPreferences(request.context)
.getString("image_decoding_mode", "auto") == "software"
if (!softwareSelected || !request.allowHardware) return chain.proceed()
return chain.withRequest(request.newBuilder().allowHardware(false)
.bitmapConfig(Bitmap.Config.ARGB_8888).build()).proceed()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import coil3.request.ImageRequest
import coil3.request.allowHardware
import coil3.request.bitmapConfig
import coil3.request.crossfade
import coil3.request.error
import coil3.request.fallback
import coil3.request.placeholder
import coil3.util.DebugLogger
import com.lagradost.cloudstream3.BuildConfig
import com.lagradost.cloudstream3.USER_AGENT
Expand Down Expand Up @@ -58,6 +61,7 @@ object ImageLoader {
/** Pass interceptors with care, unnecessary passing tokens to servers
or image hosting services causes unauthorized exceptions **/
.components {
add(ImageDecodingPreferenceInterceptor())
add(OkHttpNetworkFetcherFactory(callFactory = { buildDefaultClient(context) }))
if (isBrokenHardware) {
add(BitmapFactoryDecoder.Factory())
Expand Down Expand Up @@ -98,13 +102,19 @@ object ImageLoader {
) {
// clear image to avoid loading & flickering issue at fast scrolling (~recycler view/lazy column)
this.dispose()
if (imageData == null) return
if (imageData == null || (imageData is String && imageData.isBlank())) {
this.setImageResource(com.lagradost.cloudstream3.R.drawable.default_cover)
return
}
// setImageResource is better than coil3 on resources due to attr
if (imageData is Int) {
this.setImageResource(imageData); return
}
// headers can be overridden by extensions.
this.load(imageData, SingletonImageLoader.get(context)) {
placeholder { getImageFromDrawable(context, com.lagradost.cloudstream3.R.drawable.default_cover) }
error { getImageFromDrawable(context, com.lagradost.cloudstream3.R.drawable.default_cover) }
fallback { getImageFromDrawable(context, com.lagradost.cloudstream3.R.drawable.default_cover) }
this.httpHeaders(NetworkHeaders.Builder().also { headerBuilder ->
headerBuilder["User-Agent"] = USER_AGENT
headers?.forEach { (key, value) ->
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values-es/image_loading_options.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<resources>
<string name="image_loading_options_title">Carga de imágenes</string>
<string name="image_decoding_title">Decodificación de imágenes</string>
<string name="image_decoding_automatic">Automática</string>
<string name="image_decoding_software">Compatibilidad por software</string>
<string name="image_decoding_summary">Choose software decoding for hardware compatibility problems. Automatic keeps the current image loader behavior.</string>
</resources>
9 changes: 9 additions & 0 deletions app/src/main/res/values/image_loading_options.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<resources>
<string name="image_loading_options_title">Image loading</string>
<string name="image_decoding_title">Image decoding</string>
<string name="image_decoding_automatic">Automatic</string>
<string name="image_decoding_software">Software compatibility</string>
<string name="image_decoding_summary">Choose software decoding for hardware compatibility problems. Automatic keeps the current image loader behavior.</string>
<string-array name="image_decoding_entries"><item>@string/image_decoding_automatic</item><item>@string/image_decoding_software</item></string-array>
<string-array name="image_decoding_values"><item>auto</item><item>software</item></string-array>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/xml/settings_general.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/image_loading_options_title">
<ListPreference android:key="image_decoding_mode" android:title="@string/image_decoding_title" android:summary="@string/image_decoding_summary" android:defaultValue="auto" android:entries="@array/image_decoding_entries" android:entryValues="@array/image_decoding_values" />
</PreferenceCategory>
<Preference
android:icon="@drawable/ic_baseline_language_24"
android:key="@string/locale_key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class PlayerPreferences(preferences: PreferenceStore) {
}

class GeneralPreferences(preferences: PreferenceStore) {
val imageDecodingMode = preferences.getString("image_decoding_mode", "auto")
val locale = preferences.getString("app_locale", "")
val bananas = preferences.getInt("benene_count", 0)
val parallelDownloads = preferences.getInt("download_parallel_key", 3)
Expand Down
Loading