pull/600/head
Colin Lee 6 years ago committed by Jeff Boek
parent c997ebd1ed
commit f6a05938ca

@ -5,6 +5,8 @@
package org.mozilla.fenix.ext package org.mozilla.fenix.ext
import android.content.Context import android.content.Context
import androidx.core.content.ContextCompat
import org.mozilla.fenix.DefaultThemeManager import org.mozilla.fenix.DefaultThemeManager
fun Int.getColorFromAttr(context: Context): Int = DefaultThemeManager.resolveAttribute(this, context) fun Int.getColorIntFromAttr(context: Context): Int = DefaultThemeManager.resolveAttribute(this, context)
fun Int.getColorFromAttr(context: Context): Int = ContextCompat.getColor(context, this.getColorIntFromAttr(context))

@ -40,13 +40,12 @@ import mozilla.components.concept.sync.Profile
import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.BackHandler
import org.mozilla.fenix.BrowserDirection import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BrowsingModeManager import org.mozilla.fenix.BrowsingModeManager
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.components.FenixSnackbar import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.components.metrics.Event import org.mozilla.fenix.components.metrics.Event
import org.mozilla.fenix.ext.allowUndo import org.mozilla.fenix.ext.allowUndo
import org.mozilla.fenix.ext.getColorFromAttr import org.mozilla.fenix.ext.getColorIntFromAttr
import org.mozilla.fenix.ext.requireComponents import org.mozilla.fenix.ext.requireComponents
import org.mozilla.fenix.ext.share import org.mozilla.fenix.ext.share
import org.mozilla.fenix.ext.urlToHost import org.mozilla.fenix.ext.urlToHost
@ -104,17 +103,32 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
?: getManagedEmitter<SignInChange>().onNext(SignInChange.SignedOut) ?: getManagedEmitter<SignInChange>().onNext(SignInChange.SignedOut)
} }
override fun onDestroy() { fun setToolbarColors(foreground: Int, background: Int) {
super.onDestroy()
job.cancel()
// Reset the toolbar color
val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar) val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar)
val colorFilter = PorterDuffColorFilter( val colorFilter = PorterDuffColorFilter(
R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN) ContextCompat.getColor(context!!, foreground), PorterDuff.Mode.SRC_IN
)
toolbar.setBackgroundColor(ContextCompat.getColor(context!!, background))
toolbar.setTitleTextColor(ContextCompat.getColor(context!!, foreground))
themeToolbar(
toolbar, foreground,
background, colorFilter
)
}
themeToolbar(toolbar, DefaultThemeManager.resolveAttribute(R.attr.primaryText, context!!), override fun onStop() {
DefaultThemeManager.resolveAttribute(R.attr.foundation, context!!), colorFilter) super.onStop()
// Reset the toolbar color
setToolbarColors(
R.attr.primaryText.getColorIntFromAttr(context!!),
R.attr.foundation.getColorIntFromAttr(context!!)
)
}
override fun onDestroy() {
super.onDestroy()
job.cancel()
} }
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
@ -128,25 +142,28 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
null null
) )
) getString(R.string.library_bookmarks) else currentRoot!!.title ) getString(R.string.library_bookmarks) else currentRoot!!.title
toolbar.setBackgroundColor(R.attr.foundation.getColorFromAttr(context!!))
toolbar.setTitleTextColor(R.attr.primaryText.getColorFromAttr(context!!)) setToolbarColors(
R.attr.primaryText.getColorIntFromAttr(context!!),
R.attr.foundation.getColorIntFromAttr(context!!)
)
} }
is BookmarkState.Mode.Selecting -> { is BookmarkState.Mode.Selecting -> {
inflater.inflate(R.menu.bookmarks_select_multi, menu) inflater.inflate(R.menu.bookmarks_select_multi, menu)
val colorFilter = PorterDuffColorFilter(
ContextCompat.getColor(context!!, R.color.white_color), PorterDuff.Mode.SRC_IN)
val enableEditButton = mode.selectedItems.size == 1
menu.findItem(R.id.edit_bookmark_multi_select).run { menu.findItem(R.id.edit_bookmark_multi_select).run {
isVisible = enableEditButton isVisible = mode.selectedItems.size == 1
if (enableEditButton) { icon.colorFilter = PorterDuffColorFilter(
icon.colorFilter = colorFilter ContextCompat.getColor(context!!, R.color.white_color),
} PorterDuff.Mode.SRC_IN
)
} }
activity?.title = getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size) activity?.title = getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size)
themeToolbar(toolbar, R.color.white_color, setToolbarColors(
DefaultThemeManager.resolveAttribute(R.attr.accentBright, context!!), colorFilter) R.color.white_color,
R.attr.accentBright.getColorIntFromAttr(context!!)
)
} }
} }
} }

Loading…
Cancel
Save