mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-24 14:01:53 +01:00
parent
4b46c0f6a7
commit
d0bc413581
@ -1,11 +1,13 @@
|
|||||||
package eu.kanade.tachiyomi.util.system
|
package eu.kanade.tachiyomi.util.system
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.appcompat.app.AppCompatDelegate
|
import androidx.appcompat.app.AppCompatDelegate
|
||||||
|
import androidx.lifecycle.coroutineScope
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
|
|
||||||
object ThemeUtil {
|
object ThemeUtil {
|
||||||
|
|
||||||
@ -36,8 +38,9 @@ object ThemeUtil {
|
|||||||
return theme.styleRes == R.style.Theme_Tachiyomi_AllBlue
|
return theme.styleRes == R.style.Theme_Tachiyomi_AllBlue
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isPitchBlack(context: Context, theme: Themes): Boolean {
|
fun isPitchBlack(context: Context): Boolean {
|
||||||
return context.isInNightMode() && theme.darkBackground == Color.BLACK
|
val preferences: PreferencesHelper by injectLazy()
|
||||||
|
return context.isInNightMode() && preferences.themeDarkAmoled().get()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun hasDarkActionBarInLight(context: Context, theme: Themes): Boolean {
|
fun hasDarkActionBarInLight(context: Context, theme: Themes): Boolean {
|
||||||
@ -52,11 +55,10 @@ object ThemeUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Activity.setThemeAndNight(preferences: PreferencesHelper) {
|
fun AppCompatActivity.setThemeAndNight(preferences: PreferencesHelper) {
|
||||||
if (preferences.nightMode().isNotSet()) {
|
if (preferences.nightMode().isNotSet()) {
|
||||||
ThemeUtil.convertTheme(preferences, preferences.oldTheme())
|
ThemeUtil.convertTheme(preferences, preferences.oldTheme())
|
||||||
}
|
}
|
||||||
AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get())
|
|
||||||
val theme = getPrefTheme(preferences)
|
val theme = getPrefTheme(preferences)
|
||||||
setTheme(theme.styleRes)
|
setTheme(theme.styleRes)
|
||||||
|
|
||||||
@ -66,6 +68,9 @@ fun Activity.setThemeAndNight(preferences: PreferencesHelper) {
|
|||||||
setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue)
|
setTheme(R.style.ThemeOverlay_Tachiyomi_AllBlue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
lifecycle.coroutineScope.launchWhenCreated {
|
||||||
|
AppCompatDelegate.setDefaultNightMode(preferences.nightMode().get())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {
|
fun Context.getPrefTheme(preferences: PreferencesHelper): Themes {
|
||||||
|
@ -42,11 +42,9 @@ import eu.kanade.tachiyomi.R
|
|||||||
import eu.kanade.tachiyomi.util.lang.tintText
|
import eu.kanade.tachiyomi.util.lang.tintText
|
||||||
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
import eu.kanade.tachiyomi.util.system.ThemeUtil
|
||||||
import eu.kanade.tachiyomi.util.system.contextCompatColor
|
import eu.kanade.tachiyomi.util.system.contextCompatColor
|
||||||
import eu.kanade.tachiyomi.util.system.getPrefTheme
|
|
||||||
import eu.kanade.tachiyomi.util.system.getResourceColor
|
import eu.kanade.tachiyomi.util.system.getResourceColor
|
||||||
import eu.kanade.tachiyomi.util.system.pxToDp
|
import eu.kanade.tachiyomi.util.system.pxToDp
|
||||||
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
import eu.kanade.tachiyomi.widget.AutofitRecyclerView
|
||||||
import uy.kohesive.injekt.Injekt
|
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.pow
|
import kotlin.math.pow
|
||||||
@ -76,8 +74,7 @@ fun View.snack(
|
|||||||
if (f != null) {
|
if (f != null) {
|
||||||
snack.f()
|
snack.f()
|
||||||
}
|
}
|
||||||
val theme = context.getPrefTheme(Injekt.get())
|
if (ThemeUtil.isPitchBlack(context)) {
|
||||||
if (ThemeUtil.isPitchBlack(context, theme)) {
|
|
||||||
val textView: TextView =
|
val textView: TextView =
|
||||||
snack.view.findViewById(com.google.android.material.R.id.snackbar_text)
|
snack.view.findViewById(com.google.android.material.R.id.snackbar_text)
|
||||||
val button: Button? =
|
val button: Button? =
|
||||||
|
Loading…
Reference in New Issue
Block a user