refactor(color-scheme): Remove manual contrast level handling (#1370)
- Remove manual `contrastLevel` - Simplify color scheme generation
This commit is contained in:
parent
bbb460bfd5
commit
259b682527
3 changed files with 22 additions and 69 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
package eu.kanade.presentation.theme
|
package eu.kanade.presentation.theme
|
||||||
|
|
||||||
import android.app.UiModeManager
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.ColorScheme
|
import androidx.compose.material3.ColorScheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
|
@ -11,8 +9,6 @@ import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import com.materialkolor.Contrast
|
|
||||||
import com.materialkolor.DynamicMaterialTheme
|
import com.materialkolor.DynamicMaterialTheme
|
||||||
import eu.kanade.domain.ui.UiPreferences
|
import eu.kanade.domain.ui.UiPreferences
|
||||||
import eu.kanade.domain.ui.model.AppTheme
|
import eu.kanade.domain.ui.model.AppTheme
|
||||||
|
|
@ -55,6 +51,8 @@ fun TachiyomiTheme(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// KMK -->
|
||||||
|
/** Theme based on Cover */
|
||||||
@Composable
|
@Composable
|
||||||
fun TachiyomiTheme(
|
fun TachiyomiTheme(
|
||||||
seedColor: Color?,
|
seedColor: Color?,
|
||||||
|
|
@ -63,10 +61,11 @@ fun TachiyomiTheme(
|
||||||
typography: Typography = MaterialTheme.typography,
|
typography: Typography = MaterialTheme.typography,
|
||||||
content: @Composable () -> Unit,
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
|
if (seedColor == null) {
|
||||||
|
TachiyomiTheme(appTheme, amoled, content)
|
||||||
|
} else {
|
||||||
val uiPreferences = Injekt.get<UiPreferences>()
|
val uiPreferences = Injekt.get<UiPreferences>()
|
||||||
val context = LocalContext.current
|
|
||||||
val isAmoled = amoled ?: uiPreferences.themeDarkAmoled().get()
|
val isAmoled = amoled ?: uiPreferences.themeDarkAmoled().get()
|
||||||
if (seedColor != null) {
|
|
||||||
DynamicMaterialTheme(
|
DynamicMaterialTheme(
|
||||||
seedColor = seedColor,
|
seedColor = seedColor,
|
||||||
isAmoled = isAmoled,
|
isAmoled = isAmoled,
|
||||||
|
|
@ -74,20 +73,10 @@ fun TachiyomiTheme(
|
||||||
typography = typography,
|
typography = typography,
|
||||||
animate = true,
|
animate = true,
|
||||||
content = content,
|
content = content,
|
||||||
contrastLevel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
context.getSystemService<UiModeManager>()?.contrast?.toDouble() ?: Contrast.Default.value
|
|
||||||
} else {
|
|
||||||
Contrast.Default.value
|
|
||||||
},
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
BaseTachiyomiTheme(
|
|
||||||
appTheme = appTheme ?: uiPreferences.appTheme().get(),
|
|
||||||
isAmoled = isAmoled,
|
|
||||||
content = content,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// KMK <--
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TachiyomiPreviewTheme(
|
fun TachiyomiPreviewTheme(
|
||||||
|
|
@ -131,8 +120,7 @@ private fun getThemeColorScheme(
|
||||||
AppTheme.CUSTOM -> {
|
AppTheme.CUSTOM -> {
|
||||||
val uiPreferences = Injekt.get<UiPreferences>()
|
val uiPreferences = Injekt.get<UiPreferences>()
|
||||||
CustomColorScheme(
|
CustomColorScheme(
|
||||||
context = context,
|
seed = Color(uiPreferences.colorTheme().get()),
|
||||||
seed = uiPreferences.colorTheme().get(),
|
|
||||||
style = uiPreferences.customThemeStyle().get(),
|
style = uiPreferences.customThemeStyle().get(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,5 @@
|
||||||
package eu.kanade.presentation.theme.colorscheme
|
package eu.kanade.presentation.theme.colorscheme
|
||||||
|
|
||||||
import android.app.UiModeManager
|
|
||||||
import android.content.Context
|
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
|
@ -11,55 +9,29 @@ import androidx.compose.material3.surfaceColorAtElevation
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.core.content.getSystemService
|
|
||||||
import com.google.android.material.progressindicator.LinearProgressIndicator
|
import com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
import com.google.android.material.textfield.TextInputEditText
|
import com.google.android.material.textfield.TextInputEditText
|
||||||
import com.google.android.material.textfield.TextInputLayout
|
import com.google.android.material.textfield.TextInputLayout
|
||||||
import com.materialkolor.Contrast
|
|
||||||
import com.materialkolor.PaletteStyle
|
import com.materialkolor.PaletteStyle
|
||||||
import com.materialkolor.dynamicColorScheme
|
import com.materialkolor.dynamicColorScheme
|
||||||
|
|
||||||
internal class CustomColorScheme(
|
internal class CustomColorScheme(
|
||||||
context: Context,
|
seed: Color,
|
||||||
seed: Int,
|
|
||||||
style: PaletteStyle,
|
style: PaletteStyle,
|
||||||
) : BaseColorScheme() {
|
) : BaseColorScheme() {
|
||||||
private val custom = CustomCompatColorScheme(context, seed, style)
|
override val lightScheme = generateColorSchemeFromSeed(seed = seed, style = style, dark = false)
|
||||||
|
override val darkScheme = generateColorSchemeFromSeed(seed = seed, style = style, dark = true)
|
||||||
|
|
||||||
override val darkScheme
|
companion object {
|
||||||
get() = custom.darkScheme
|
fun generateColorSchemeFromSeed(seed: Color, style: PaletteStyle, dark: Boolean): ColorScheme {
|
||||||
|
return dynamicColorScheme(
|
||||||
override val lightScheme
|
seedColor = seed,
|
||||||
get() = custom.lightScheme
|
isDark = dark,
|
||||||
|
isAmoled = false,
|
||||||
|
style = style,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class CustomCompatColorScheme(
|
|
||||||
context: Context,
|
|
||||||
seed: Int,
|
|
||||||
style: PaletteStyle,
|
|
||||||
) : BaseColorScheme() {
|
|
||||||
override val lightScheme = dynamicColorScheme(
|
|
||||||
seedColor = Color(seed),
|
|
||||||
isDark = false,
|
|
||||||
isAmoled = false,
|
|
||||||
style = style,
|
|
||||||
contrastLevel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
context.getSystemService<UiModeManager>()?.contrast?.toDouble() ?: Contrast.Default.value
|
|
||||||
} else {
|
|
||||||
Contrast.Default.value
|
|
||||||
},
|
|
||||||
)
|
|
||||||
override val darkScheme = dynamicColorScheme(
|
|
||||||
seedColor = Color(seed),
|
|
||||||
isDark = true,
|
|
||||||
isAmoled = false,
|
|
||||||
style = style,
|
|
||||||
contrastLevel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
context.getSystemService<UiModeManager>()?.contrast?.toDouble() ?: Contrast.Default.value
|
|
||||||
} else {
|
|
||||||
Contrast.Default.value
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class AndroidViewColorScheme(
|
class AndroidViewColorScheme(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.ui.reader
|
||||||
|
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.UiModeManager
|
|
||||||
import android.app.assist.AssistContent
|
import android.app.assist.AssistContent
|
||||||
import android.content.ClipData
|
import android.content.ClipData
|
||||||
import android.content.ClipboardManager
|
import android.content.ClipboardManager
|
||||||
|
|
@ -59,7 +58,6 @@ import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import com.google.android.material.elevation.SurfaceColors
|
import com.google.android.material.elevation.SurfaceColors
|
||||||
import com.google.android.material.transition.platform.MaterialContainerTransform
|
import com.google.android.material.transition.platform.MaterialContainerTransform
|
||||||
import com.hippo.unifile.UniFile
|
import com.hippo.unifile.UniFile
|
||||||
import com.materialkolor.Contrast
|
|
||||||
import com.materialkolor.dynamicColorScheme
|
import com.materialkolor.dynamicColorScheme
|
||||||
import dev.chrisbanes.insetter.applyInsetter
|
import dev.chrisbanes.insetter.applyInsetter
|
||||||
import eu.kanade.core.util.ifSourcesLoaded
|
import eu.kanade.core.util.ifSourcesLoaded
|
||||||
|
|
@ -769,11 +767,6 @@ class ReaderActivity : BaseActivity() {
|
||||||
isDark = isNightMode(),
|
isDark = isNightMode(),
|
||||||
isAmoled = themeDarkAmoled,
|
isAmoled = themeDarkAmoled,
|
||||||
style = themeCoverBasedStyle,
|
style = themeCoverBasedStyle,
|
||||||
contrastLevel = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
|
||||||
getSystemService<UiModeManager>()?.contrast?.toDouble() ?: Contrast.Default.value
|
|
||||||
} else {
|
|
||||||
Contrast.Default.value
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
// KMK <--
|
// KMK <--
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue