Use an attributed value for coloredActionBars

This commit is contained in:
Jays2Kings 2021-09-03 13:33:36 -04:00
parent e0b38b0877
commit bece81e69e
6 changed files with 23 additions and 12 deletions

View file

@ -70,12 +70,11 @@ import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.storage.getUriCompat
import eu.kanade.tachiyomi.util.system.GLUtil
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.contextCompatColor
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
import eu.kanade.tachiyomi.util.system.getPrefTheme
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.hasColoredActionBar
import eu.kanade.tachiyomi.util.system.hasSideNavBar
import eu.kanade.tachiyomi.util.system.isBottomTappable
import eu.kanade.tachiyomi.util.system.isLTR
@ -255,7 +254,7 @@ class ReaderActivity :
}
binding.chaptersSheet.chaptersBottomSheet.setup(this)
if (ThemeUtil.isColoredTheme(getPrefTheme(preferences))) {
if (hasColoredActionBar) {
binding.chaptersSheet.chapterRecycler.setBackgroundColor(getResourceColor(R.attr.background))
}
config = ReaderConfig()

View file

@ -45,11 +45,10 @@ import eu.kanade.tachiyomi.ui.manga.MangaDetailsController
import eu.kanade.tachiyomi.ui.reader.ReaderActivity
import eu.kanade.tachiyomi.ui.recents.options.TabbedRecentsOptionsSheet
import eu.kanade.tachiyomi.ui.source.browse.ProgressItem
import eu.kanade.tachiyomi.util.system.ThemeUtil
import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.system.getBottomGestureInsets
import eu.kanade.tachiyomi.util.system.getPrefTheme
import eu.kanade.tachiyomi.util.system.getResourceColor
import eu.kanade.tachiyomi.util.system.hasColoredActionBar
import eu.kanade.tachiyomi.util.system.isLTR
import eu.kanade.tachiyomi.util.system.spToPx
import eu.kanade.tachiyomi.util.system.toInt
@ -730,10 +729,8 @@ class RecentsController(bundle: Bundle? = null) :
}
})
(activity as? MainActivity)?.showTabBar(true)
activity?.let {
if (ThemeUtil.isColoredTheme(it.getPrefTheme(presenter.preferences))) {
updateTitleAndMenu()
}
if (activity?.hasColoredActionBar == true) {
updateTitleAndMenu()
}
}
} else {

View file

@ -320,6 +320,15 @@ fun Context.getCustomTabsPackages(): ArrayList<ResolveInfo> {
return packagesSupportingCustomTabs
}
val Context.hasColoredActionBar: Boolean
get() {
val hasColoredActionBar: Boolean
val a = obtainStyledAttributes(intArrayOf(R.attr.hasColoredActionBar))
hasColoredActionBar = a.getBoolean(0, false)
a.recycle()
return hasColoredActionBar
}
fun Context.isInNightMode(): Boolean {
val currentNightMode = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
return currentNightMode == Configuration.UI_MODE_NIGHT_YES

View file

@ -99,12 +99,15 @@ fun AppCompatActivity.setThemeAndNight(preferences: PreferencesHelper) {
}
fun AppCompatActivity.getThemeWithExtras(theme: Resources.Theme, preferences: PreferencesHelper, oldTheme: Resources.Theme?): Resources.Theme {
val useAmoled = (isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES) &&
preferences.themeDarkAmoled().get()
val useAmoled =
(isInNightMode() || preferences.nightMode().get() == AppCompatDelegate.MODE_NIGHT_YES) &&
preferences.themeDarkAmoled().get()
if (oldTheme != null) {
val array = oldTheme.obtainStyledAttributes(intArrayOf(R.attr.background))
val bg = array.getColor(0, 0)
if (bg == Color.BLACK && useAmoled) { return oldTheme }
if (bg == Color.BLACK && useAmoled) {
return oldTheme
}
}
if (useAmoled) {
theme.applyStyle(R.style.ThemeOverlay_Tachiyomi_Amoled, true)

View file

@ -19,6 +19,7 @@
<attr name="tabBarIconColor" format="reference|integer"/>
<attr name="tabBarIconInactive" format="reference|integer"/>
<attr name="tabHighlightBackground" format="color"/>
<attr name="hasColoredActionBar" format="boolean">false</attr>
<declare-styleable name="MaterialSpinnerView">
<attr name="title" format="reference|string"/>

View file

@ -68,6 +68,7 @@
<style name="Theme.Tachiyomi" parent="Theme.Base"/>
<style name="Theme.Tachiyomi.AllBlue">
<item name="hasColoredActionBar">true</item>
<item name="colorPrimaryVariant">@color/primaryTachiyomi</item>
<item name="tabBarIconColor">@color/md_white_1000</item>
<item name="colorSurface">@color/primaryTachiyomi</item>
@ -83,6 +84,7 @@
</style>
<style name="ThemeOverlay.Tachiyomi.AllBlue" parent="">
<item name="hasColoredActionBar">true</item>
<item name="colorPrimaryVariant">@color/primaryTachiyomi</item>
<item name="colorSurface">@color/primaryTachiyomi</item>
<item name="colorBackgroundFloating">?android:colorBackground</item>