From e3f3686b8a90fffe5140129a40f67b435c7d71a8 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 22 Jan 2022 14:53:12 -0500 Subject: [PATCH] Allow Samsung devices on Android 12+ to use dynamic theme Since it seems to work fine, regardless of what the Material Components library seems to dictate. --- .../eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt | 3 +-- .../tachiyomi/ui/setting/SettingsAppearanceController.kt | 4 ++-- .../main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 49a8410f3..8c3740c78 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -6,7 +6,6 @@ import android.os.Environment import androidx.core.content.edit import androidx.core.net.toUri import androidx.preference.PreferenceManager -import com.google.android.material.color.DynamicColors import com.tfcporciuncula.flow.FlowSharedPreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga @@ -73,7 +72,7 @@ class PreferencesHelper(val context: Context) { fun appTheme() = flowPrefs.getEnum( "pref_app_theme", - if (DynamicColors.isDynamicColorAvailable()) { Values.AppTheme.MONET } else { Values.AppTheme.DEFAULT } + if (DeviceUtil.isDynamicColorAvailable) { Values.AppTheme.MONET } else { Values.AppTheme.DEFAULT } ) fun themeDarkAmoled() = flowPrefs.getBoolean("pref_theme_dark_amoled_key", false) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt index bb3f6d85b..0fb1990ee 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAppearanceController.kt @@ -5,7 +5,6 @@ import android.os.Bundle import android.view.View import androidx.core.app.ActivityCompat import androidx.preference.PreferenceScreen -import com.google.android.material.color.DynamicColors import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.util.preference.bindTo import eu.kanade.tachiyomi.util.preference.defaultValue @@ -17,6 +16,7 @@ import eu.kanade.tachiyomi.util.preference.onChange import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.preference.switchPreference import eu.kanade.tachiyomi.util.preference.titleRes +import eu.kanade.tachiyomi.util.system.DeviceUtil import eu.kanade.tachiyomi.util.system.isTablet import eu.kanade.tachiyomi.widget.preference.ThemesPreference import java.util.Date @@ -67,7 +67,7 @@ class SettingsAppearanceController : SettingsController() { val appThemes = Values.AppTheme.values().filter { val monetFilter = if (it == Values.AppTheme.MONET) { - DynamicColors.isDynamicColorAvailable() + DeviceUtil.isDynamicColorAvailable } else { true } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt index 33a132408..c2b62d8fd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/system/DeviceUtil.kt @@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.util.system import android.annotation.SuppressLint import android.os.Build +import com.google.android.material.color.DynamicColors import logcat.LogPriority object DeviceUtil { @@ -30,6 +31,10 @@ object DeviceUtil { Build.MANUFACTURER.equals("samsung", ignoreCase = true) } + val isDynamicColorAvailable by lazy { + DynamicColors.isDynamicColorAvailable() || (isSamsung && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) + } + @SuppressLint("PrivateApi") private fun getSystemProperty(key: String?): String? { return try {