Allow Samsung devices on Android 12+ to use dynamic theme

This commit is contained in:
Zakhar Timoshenko
2022-01-26 00:50:38 +03:00
parent e8bb4bac66
commit 1253ca07cc
2 changed files with 18 additions and 1 deletions

View File

@@ -14,6 +14,7 @@ import org.koitharu.kotatsu.core.model.MangaSource
import org.koitharu.kotatsu.core.prefs.AppSettings
import org.koitharu.kotatsu.core.prefs.ListMode
import org.koitharu.kotatsu.settings.protect.ProtectSetupActivity
import org.koitharu.kotatsu.utils.DeviceUtil
import org.koitharu.kotatsu.utils.ext.getStorageName
import org.koitharu.kotatsu.utils.ext.names
import org.koitharu.kotatsu.utils.ext.setDefaultValueCompat
@@ -57,7 +58,7 @@ class MainSettingsFragment : BasePreferenceFragment(R.string.settings),
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
findPreference<SwitchPreference>(AppSettings.KEY_DYNAMIC_THEME)?.isVisible =
DynamicColors.isDynamicColorAvailable()
DeviceUtil.isDynamicColorAvailable
findPreference<Preference>(AppSettings.KEY_LOCAL_STORAGE)?.run {
summary = settings.getStorageDir(context)?.getStorageName(context)
?: getString(R.string.not_available)

View File

@@ -0,0 +1,16 @@
package org.koitharu.kotatsu.utils
import android.os.Build
import com.google.android.material.color.DynamicColors
object DeviceUtil {
private val isSamsung by lazy {
Build.MANUFACTURER.equals("samsung", ignoreCase = true)
}
val isDynamicColorAvailable by lazy {
DynamicColors.isDynamicColorAvailable() || (isSamsung && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
}
}