This commit is contained in:
Finnley Somdahl 2023-12-01 01:22:15 -06:00
parent 1df528c0dc
commit afa960c808
171 changed files with 3458 additions and 1915 deletions

View file

@ -4,41 +4,42 @@ import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.util.Log
import ani.dantotsu.FileUrl
import ani.dantotsu.R
import ani.dantotsu.logger
import ani.dantotsu.media.manga.mangareader.BaseImageAdapter.Companion.loadBitmap
import ani.dantotsu.media.manga.mangareader.BaseImageAdapter.Companion.loadBitmap_old
import com.google.android.material.color.DynamicColors
import com.google.android.material.color.DynamicColorsOptions
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import kotlinx.coroutines.withTimeout
class ThemeManager(private val context: Context) {
fun applyTheme(fromImage: Bitmap? = null) {
val useOLED = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("use_oled", false) && isDarkThemeActive(context)
val useCustomTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("use_custom_theme", false)
val customTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getInt("custom_theme_int", 16712221)
val useSource = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("use_source_theme", false)
val useMaterial = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getBoolean("use_material_you", false)
if(useSource){
val returnedEarly = applyDynamicColors(useMaterial, context, useOLED, fromImage, useCustom = if(useCustomTheme) customTheme else null)
if(!returnedEarly) return
val useOLED = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_oled", false) && isDarkThemeActive(context)
val useCustomTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_custom_theme", false)
val customTheme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getInt("custom_theme_int", 16712221)
val useSource = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_source_theme", false)
val useMaterial = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getBoolean("use_material_you", false)
if (useSource) {
val returnedEarly = applyDynamicColors(
useMaterial,
context,
useOLED,
fromImage,
useCustom = if (useCustomTheme) customTheme else null
)
if (!returnedEarly) return
} else if (useCustomTheme) {
val returnedEarly = applyDynamicColors(useMaterial, context, useOLED, useCustom = customTheme)
if(!returnedEarly) return
val returnedEarly =
applyDynamicColors(useMaterial, context, useOLED, useCustom = customTheme)
if (!returnedEarly) return
} else {
val returnedEarly = applyDynamicColors(useMaterial, context, useOLED, useCustom = null)
if(!returnedEarly) return
if (!returnedEarly) return
}
val theme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE).getString("theme", "PURPLE")!!
val theme = context.getSharedPreferences("Dantotsu", Context.MODE_PRIVATE)
.getString("theme", "PURPLE")!!
val themeToApply = when (theme) {
"PURPLE" -> if (useOLED) R.style.Theme_Dantotsu_PurpleOLED else R.style.Theme_Dantotsu_Purple
@ -55,7 +56,13 @@ class ThemeManager(private val context: Context) {
context.setTheme(themeToApply)
}
private fun applyDynamicColors(useMaterialYou: Boolean, context: Context, useOLED: Boolean, bitmap: Bitmap? = null, useCustom: Int? = null): Boolean {
private fun applyDynamicColors(
useMaterialYou: Boolean,
context: Context,
useOLED: Boolean,
bitmap: Bitmap? = null,
useCustom: Int? = null
): Boolean {
val builder = DynamicColorsOptions.Builder()
var needMaterial = true
@ -63,7 +70,7 @@ class ThemeManager(private val context: Context) {
if (bitmap != null) {
builder.setContentBasedSource(bitmap)
needMaterial = false
}else if (useCustom != null){
} else if (useCustom != null) {
builder.setContentBasedSource(useCustom)
needMaterial = false
}
@ -71,7 +78,7 @@ class ThemeManager(private val context: Context) {
if (useOLED) {
builder.setThemeOverlay(R.style.AppTheme_Amoled)
}
if(needMaterial && !useMaterialYou) return true
if (needMaterial && !useMaterialYou) return true
// Build the options
val options = builder.build()
@ -100,7 +107,7 @@ class ThemeManager(private val context: Context) {
}
companion object{
companion object {
enum class Theme(val theme: String) {
PURPLE("PURPLE"),
BLUE("BLUE"),