Change color of navigation bar based on theme

This commit is contained in:
Moez Bhatti
2018-04-02 23:58:58 -04:00
parent 30506ce4a4
commit c8c5dd3aad
9 changed files with 43 additions and 4 deletions
@@ -65,13 +65,17 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { res -> setTheme(res) } .subscribe { res -> setTheme(res) }
colors.statusBarIcons colors.systemBarIcons
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { systemUiVisibility -> window.decorView.systemUiVisibility = systemUiVisibility } .subscribe { systemUiVisibility -> window.decorView.systemUiVisibility = systemUiVisibility }
colors.statusBar colors.statusBar
.autoDisposable(scope()) .autoDisposable(scope())
.subscribe { color -> window.statusBarColor = color } .subscribe { color -> window.statusBarColor = color }
colors.background
.autoDisposable(scope())
.subscribe { color -> window.navigationBarColor = color }
} }
override fun onPostCreate(savedInstanceState: Bundle?) { override fun onPostCreate(savedInstanceState: Bundle?) {
@@ -105,7 +109,8 @@ abstract class QkThemedActivity<VM : QkViewModel<*, *>> : QkActivity<VM>() {
colors.toolbarColor colors.toolbarColor
.doOnNext { color -> toolbar?.setBackgroundTint(color) } .doOnNext { color -> toolbar?.setBackgroundTint(color) }
.doOnNext { color -> // Set the color for the recent apps title .doOnNext { color ->
// Set the color for the recent apps title
val icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher) val icon = BitmapFactory.decodeResource(resources, R.mipmap.ic_launcher)
val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), icon, color) val taskDesc = ActivityManager.TaskDescription(getString(R.string.app_name), icon, color)
setTaskDescription(taskDesc) setTaskDescription(taskDesc)
@@ -93,9 +93,9 @@ class Colors @Inject constructor(private val context: Context, private val prefs
}) })
@SuppressLint("InlinedApi") @SuppressLint("InlinedApi")
val statusBarIcons: Observable<Int> = prefs.night.asObservable() val systemBarIcons: Observable<Int> = prefs.night.asObservable()
.map { night -> night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M } .map { night -> night || Build.VERSION.SDK_INT < Build.VERSION_CODES.M }
.map { lightIcons -> if (lightIcons) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR } .map { lightIcons -> if (lightIcons) 0 else View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR}
.distinctUntilChanged() .distinctUntilChanged()
val statusBar: Observable<Int> = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(), val statusBar: Observable<Int> = Observables.combineLatest(prefs.night.asObservable(), prefs.black.asObservable(),
@@ -214,4 +214,9 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" /> app:layout_constraintTop_toBottomOf="@id/toolbar" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
@@ -122,4 +122,9 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" /> app:layout_constraintTop_toBottomOf="@id/toolbar" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
@@ -135,6 +135,11 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" /> app:layout_constraintTop_toBottomOf="@id/toolbar" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
<include <include
@@ -73,6 +73,11 @@
android:layout_height="8dp" android:layout_height="8dp"
android:background="@drawable/ab_shadow" /> android:background="@drawable/ab_shadow" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>
@@ -199,4 +199,9 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/toolbar" /> app:layout_constraintTop_toBottomOf="@id/toolbar" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
@@ -83,4 +83,8 @@
</LinearLayout> </LinearLayout>
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp" />
</LinearLayout> </LinearLayout>
@@ -62,6 +62,11 @@
android:layout_height="8dp" android:layout_height="8dp"
android:background="@drawable/ab_shadow" /> android:background="@drawable/ab_shadow" />
<common.widget.Separator
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_gravity="bottom" />
</FrameLayout> </FrameLayout>
</LinearLayout> </LinearLayout>