Skip to content

Commit

Permalink
fix: wrong navigation bar color
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed May 1, 2024
1 parent 6b82d95 commit afdbf09
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
29 changes: 12 additions & 17 deletions app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.graphics.Color
import android.os.Build
import android.text.Spanned
import android.view.Window
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.text.HtmlCompat
Expand All @@ -24,24 +25,21 @@ object ThemeHelper {
/**
* Set the colors of the system bars (status bat and navigation bar)
*/
fun setSystemBarColors(context: Context, window: Window, isBottomNavVisible: Boolean) {
fun setSystemBarColors(context: Context, window: Window, @ColorInt bottomNavColor: Int? = null) {

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:28: error: Parameter should start on a newline (standard:parameter-list-wrapping)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected after opening parenthesis Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:28: error: Newline expected after opening parenthesis (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:46: error: Parameter should start on a newline (standard:parameter-list-wrapping)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:46: error: Parameter should start on a newline (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:62: error: Parameter should start on a newline (standard:parameter-list-wrapping)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Parameter should start on a newline Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:62: error: Parameter should start on a newline (standard:function-signature)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing newline before ")" Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:99: error: Missing newline before ")" (standard:parameter-list-wrapping)

Check failure on line 28 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Newline expected before closing parenthesis Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:28:99: error: Newline expected before closing parenthesis (standard:function-signature)
setStatusBarColor(context, window)
setNavigationBarColor(context, window, isBottomNavVisible)
setNavigationBarColor(context, window, bottomNavColor)
}

/**
* 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 {
window.statusBarColor =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) {
getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
} else {
getThemeColor(context, android.R.attr.colorBackground)
}
}
}

/**
Expand All @@ -50,17 +48,14 @@ object ThemeHelper {
private fun setNavigationBarColor(
context: Context,
window: Window,
isBottomNavVisible: Boolean
@ColorInt bottomNavColor: Int?

Check failure on line 51 in app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt

View workflow job for this annotation

GitHub Actions / Check Code Quality

[ktlint] reported by reviewdog 🐶 Missing trailing comma before ")" Raw Output: app/src/main/java/com/github/libretube/helpers/ThemeHelper.kt:51:39: error: Missing trailing comma before ")" (standard:trailing-comma-on-declaration-site)
) {
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)
window.navigationBarColor =
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M && !isDarkMode(context)) {
getThemeColor(context, com.google.android.material.R.attr.colorOnBackground)
} else {
getThemeColor(context, android.R.attr.colorBackground)
bottomNavColor ?: getThemeColor(context, android.R.attr.colorBackground)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ import com.github.libretube.ui.models.PlayerViewModel
import com.github.libretube.ui.models.SearchViewModel
import com.github.libretube.ui.models.SubscriptionsViewModel
import com.github.libretube.util.UpdateChecker
import com.google.android.material.elevation.SurfaceColors
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import okhttp3.internal.toHexString

class MainActivity : BaseActivity() {
lateinit var binding: ActivityMainBinding
Expand Down Expand Up @@ -111,7 +113,10 @@ class MainActivity : BaseActivity() {
}

// sets the color if the navigation bar is visible
ThemeHelper.setSystemBarColors(this, window, binding.bottomNav.menu.size() > 0)
val bottomNavColor = SurfaceColors.getColorForElevation(this, binding.bottomNav.elevation).takeIf {
binding.bottomNav.menu.size() > 0
}
ThemeHelper.setSystemBarColors(this, window, bottomNavColor)

// set default tab as start fragment
navController.graph = navController.navInflater.inflate(R.navigation.nav).also {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ open class BaseActivity : AppCompatActivity() {

// Set the navigation and statusBar color if SDK < 23
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
ThemeHelper.setSystemBarColors(this, window, false)
ThemeHelper.setSystemBarColors(this, window)
}

// set the apps language
Expand Down

0 comments on commit afdbf09

Please sign in to comment.