mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-28 16:00:31 +05:30
Merge pull request #5575 from nik-conder/fix
fix: correctly display colors in system panel
This commit is contained in:
commit
6948d48612
@ -6,7 +6,9 @@ import android.content.Context
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Build
|
||||
import android.text.Spanned
|
||||
import android.view.Window
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.app.AppCompatDelegate
|
||||
import androidx.core.text.HtmlCompat
|
||||
@ -19,6 +21,38 @@ import com.google.android.material.color.MaterialColors
|
||||
|
||||
object ThemeHelper {
|
||||
|
||||
/**
|
||||
* Set the colors of the system bars (status bat and navigation bar)
|
||||
*/
|
||||
fun setSystemBarColors(context: Context, window: Window, isBottomNavVisible: Boolean) {
|
||||
setStatusBarColor(context, window)
|
||||
setNavigationBarColor(context, window, isBottomNavVisible)
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of the status bar
|
||||
*/
|
||||
private fun setStatusBarColor(context: Context, window: Window) {
|
||||
window.statusBarColor = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
getThemeColor(context, android.R.attr.colorBackground)
|
||||
} else {
|
||||
if (isDarkMode(context)) getThemeColor(context, android.R.attr.colorBackground)
|
||||
else getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of the navigation bar
|
||||
*/
|
||||
private fun setNavigationBarColor(context: Context, window: Window, isBottomNavVisible: Boolean) {
|
||||
window.navigationBarColor = if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) {
|
||||
getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
|
||||
} else {
|
||||
if (isBottomNavVisible) getThemeColor(context, com.google.android.material.R.attr.colorSurfaceContainer)
|
||||
else getThemeColor(context, android.R.attr.colorBackground)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the theme, including accent color and night mode
|
||||
*/
|
||||
@ -129,7 +163,8 @@ object ThemeHelper {
|
||||
}
|
||||
|
||||
fun isDarkMode(context: Context): Boolean {
|
||||
val darkModeFlag = context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
val darkModeFlag =
|
||||
context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK
|
||||
return darkModeFlag == Configuration.UI_MODE_NIGHT_YES
|
||||
}
|
||||
}
|
||||
|
@ -94,12 +94,8 @@ class MainActivity : BaseActivity() {
|
||||
R.id.homeFragment
|
||||
}
|
||||
|
||||
// sets the navigation bar color to the previously calculated color
|
||||
window.navigationBarColor = if (binding.bottomNav.menu.size() > 0) {
|
||||
ThemeHelper.getThemeColor(this, com.google.android.material.R.attr.colorSurfaceContainer)
|
||||
} else {
|
||||
ThemeHelper.getThemeColor(this, android.R.attr.colorBackground)
|
||||
}
|
||||
// sets the color if the navigation bar is visible
|
||||
ThemeHelper.setSystemBarColors(this, window, binding.bottomNav.menu.size() > 0)
|
||||
|
||||
// set default tab as start fragment
|
||||
navController.graph = navController.navInflater.inflate(R.navigation.nav).also {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.github.libretube.ui.base
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import com.github.libretube.R
|
||||
@ -38,6 +39,10 @@ open class BaseActivity : AppCompatActivity() {
|
||||
// set the app theme (e.g. Material You)
|
||||
ThemeHelper.updateTheme(this)
|
||||
|
||||
// Set the navigation and statusBar color if SDK < 23
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
|
||||
ThemeHelper.setSystemBarColors(this, window, false)
|
||||
|
||||
// set the apps language
|
||||
LocaleHelper.updateLanguage(this)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user