Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Closes #438: Adds dynamic nav bar color
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz authored and colintheshots committed Feb 12, 2019
1 parent 616af42 commit d543d77
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 6 deletions.
19 changes: 15 additions & 4 deletions app/src/main/java/org/mozilla/fenix/ThemeManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,25 @@ class DefaultThemeManager : ThemeManager {
}

// Handles status bar theme change since the window does not dynamically recreate
fun applyStatusBarTheme(window: Window, themeManager: ThemeManager, context: Context) {
fun applyStatusBarTheme(
window: Window,
themeManager: ThemeManager,
context: Context,
onHomeScreen: Boolean = true
) {
window.statusBarColor = ContextCompat
.getColor(context, DefaultThemeManager
.resolveAttribute(android.R.attr.statusBarColor, context))

window.navigationBarColor = ContextCompat
.getColor(context, DefaultThemeManager
.resolveAttribute(android.R.attr.navigationBarColor, context))
if (onHomeScreen) {
window.navigationBarColor = ContextCompat
.getColor(context, DefaultThemeManager
.resolveAttribute(R.attr.navigationBarColorHome, context))
} else {
window.navigationBarColor = ContextCompat
.getColor(context, DefaultThemeManager
.resolveAttribute(R.attr.navigationBarColorBrowser, context))
}

when (themeManager.currentTheme) {
ThemeManager.Theme.Light -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import mozilla.components.feature.session.SessionUseCases
import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.components.FindInPageIntegration
import org.mozilla.fenix.ext.requireComponents
Expand Down Expand Up @@ -89,6 +90,9 @@ class BrowserFragment : Fragment(), BackHandler {
}
}

val activity = activity as HomeActivity
DefaultThemeManager.applyStatusBarTheme(activity.window, activity.themeManager, activity, false)

return view
}

Expand Down
3 changes: 3 additions & 0 deletions app/src/main/java/org/mozilla/fenix/home/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.android.synthetic.main.fragment_home.view.*
import kotlinx.android.synthetic.main.tab_list_header.view.*
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionManager
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.increaseTapArea
Expand Down Expand Up @@ -49,6 +50,8 @@ class HomeFragment : Fragment() {
TabsComponent(view.homeLayout, bus, TabsState(requireComponents.core.sessionManager.sessions))
SessionsComponent(view.homeLayout, bus)
ActionBusFactory.get(this).logMergedObservables()
val activity = activity as HomeActivity
DefaultThemeManager.applyStatusBarTheme(activity.window, activity.themeManager, activity)
return view
}

Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<attr name="menuButtonTint" format="reference"/>
<attr name="toolbarWrapperBackground" format="reference"/>
<attr name="toolbarTextColor" format="reference"/>
<attr name="navigationBarColorHome" format="reference"/>

<!-- Search fragment -->
<attr name="searchBackground" format="reference"/>
Expand All @@ -32,4 +33,5 @@
<attr name="browserToolbarBackground" format="reference"/>
<attr name="browserToolbarIcons" format="reference"/>
<attr name="browserToolbarHomeIcon" format="reference"/>
<attr name="navigationBarColorBrowser" format="reference"/>
</resources>
6 changes: 4 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
<item name="android:colorPrimary">@color/off_white</item>

<!-- Style the navigation bar -->
<item name="android:navigationBarColor">@android:color/transparent</item>
<item name="navigationBarColorHome">@android:color/transparent</item>
<item name="navigationBarColorBrowser">@android:color/transparent</item>

<!-- Home fragment colors -->
<item name="homeBackgroundTopGradient">@color/off_white</item>
Expand Down Expand Up @@ -48,7 +49,8 @@
<item name="android:colorPrimary">@color/private_browsing_primary</item>

<!-- Style the navigation bar -->
<item name="android:navigationBarColor">@color/private_browsing_top_gradient</item>
<item name="navigationBarColorHome">@color/private_browsing_bottom_gradient</item>
<item name="navigationBarColorBrowser">@color/private_browsing_top_gradient</item>

<!-- Home fragment colors -->
<item name="homeBackgroundTopGradient">@color/private_browsing_top_gradient</item>
Expand Down

0 comments on commit d543d77

Please sign in to comment.