Skip to content

Commit

Permalink
Convert navigation bar color functions to extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
naveensingh committed Jun 13, 2024
1 parent f056aa7 commit 2b8133e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,7 @@ abstract class BaseSimpleActivity : AppCompatActivity() {
}

fun updateNavigationBarColor(color: Int) {
window.navigationBarColor = color
updateNavigationBarButtons(color)
}

fun updateNavigationBarButtons(color: Int) {
if (isOreoPlus()) {
if (color.getContrastColor() == DARK_GREY) {
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.addBit(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
} else {
window.decorView.systemUiVisibility = window.decorView.systemUiVisibility.removeBit(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
}
}
window.updateNavigationBarBackgroundColor(color)
}

// use translucent navigation bar, set the background color to action and status bars
Expand Down
21 changes: 21 additions & 0 deletions commons/src/main/kotlin/org/fossify/commons/extensions/Window.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.fossify.commons.extensions

import android.view.View
import android.view.Window
import org.fossify.commons.helpers.DARK_GREY
import org.fossify.commons.helpers.isOreoPlus

fun Window.updateNavigationBarBackgroundColor(color: Int) {
navigationBarColor = color
updateNavigationBarForegroundColor(color)
}

fun Window.updateNavigationBarForegroundColor(color: Int) {
if (isOreoPlus()) {
if (color.getContrastColor() == DARK_GREY) {
decorView.systemUiVisibility = decorView.systemUiVisibility.addBit(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
} else {
decorView.systemUiVisibility = decorView.systemUiVisibility.removeBit(View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
}
}
}

0 comments on commit 2b8133e

Please sign in to comment.