Skip to content

Commit

Permalink
fix: reapply theme to each init call (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedUmbrellaX authored Mar 11, 2024
1 parent dbce7c5 commit a0f0592
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
11 changes: 6 additions & 5 deletions app/src/main/java/ani/dantotsu/Functions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ fun initActivity(a: Activity) {
navBarHeight = insets.bottom
}
}
if (a !is MainActivity) a.setNavigationTheme()
}

fun Activity.hideSystemBars() {
Expand All @@ -178,11 +179,11 @@ fun Activity.hideSystemBars() {
}

fun Activity.setNavigationTheme() {
val a = TypedValue()
theme.resolveAttribute(android.R.attr.colorBackground, a, true)
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && a.isColorType)
|| (a.type >= TypedValue.TYPE_FIRST_COLOR_INT && a.type <= TypedValue.TYPE_LAST_COLOR_INT)) {
window.navigationBarColor = a.data
val tv = TypedValue()
theme.resolveAttribute(android.R.attr.colorBackground, tv, true)
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && tv.isColorType)
|| (tv.type >= TypedValue.TYPE_FIRST_COLOR_INT && tv.type <= TypedValue.TYPE_LAST_COLOR_INT)) {
window.navigationBarColor = tv.data
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,8 @@ class AnimeWatchFragment : Fragment() {
super.onResume()
binding.mediaInfoProgressBar.visibility = progress
binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state)

requireActivity().setNavigationTheme()
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,7 @@ open class MangaReadFragment : Fragment(), ScanlatorSelectionListener {
super.onResume()
binding.mediaInfoProgressBar.visibility = progress
binding.animeSourceRecycler.layoutManager?.onRestoreInstanceState(state)

requireActivity().setNavigationTheme()
}

Expand Down
8 changes: 6 additions & 2 deletions app/src/main/java/ani/dantotsu/themes/ThemeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.content.res.Configuration
import android.graphics.Bitmap
import android.os.Build
import android.view.Window
import android.view.WindowManager
import ani.dantotsu.R
Expand Down Expand Up @@ -54,7 +55,10 @@ class ThemeManager(private val context: Activity) {
}

val window = context.window
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
@Suppress("DEPRECATION")
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = 0x00000000
context.setTheme(themeToApply)
Expand Down Expand Up @@ -137,7 +141,7 @@ class ThemeManager(private val context: Activity) {

companion object {
fun fromString(value: String): Theme {
return values().find { it.theme == value } ?: PURPLE
return entries.find { it.theme == value } ?: PURPLE
}
}
}
Expand Down

0 comments on commit a0f0592

Please sign in to comment.