1
0
Fork 0

Fixes #1646: Changes bookmarks toolbar color (#1651)

master
Sawyer Blatz 2019-04-16 08:03:22 -07:00 committed by GitHub
parent 23edd2559d
commit 3b3d4c3de5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 16 deletions

View File

@ -22,6 +22,7 @@ import mozilla.components.browser.icons.IconRequest
import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.increaseTapArea
@ -182,8 +183,13 @@ class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkA
private fun setColorsAndIcons(selected: Boolean, item: BookmarkNode) {
val backgroundTint =
if (selected) R.color.bookmark_selection_appbar_background else R.color.bookmark_favicon_background
val backgroundTintList = ContextCompat.getColorStateList(containerView!!.context, backgroundTint)
if (selected) {
DefaultThemeManager.resolveAttribute(R.attr.accent, containerView!!.context)
} else {
DefaultThemeManager.resolveAttribute(R.attr.neutral, containerView!!.context)
}
val backgroundTintList = ContextCompat.getColorStateList(containerView.context, backgroundTint)
bookmark_favicon.backgroundTintList = backgroundTintList
if (selected) bookmark_favicon.setImageResource(R.drawable.mozac_ic_check)
@ -249,8 +255,12 @@ class BookmarkAdapter(val emptyView: View, val actionEmitter: Observer<BookmarkA
setMenu(item, containerView!!)
val backgroundTint =
if (selected) R.color.bookmark_selection_appbar_background else R.color.bookmark_favicon_background
val backgroundTint = if (selected) {
DefaultThemeManager.resolveAttribute(R.attr.accent, containerView.context)
} else {
DefaultThemeManager.resolveAttribute(R.attr.neutral, containerView.context)
}
val backgroundTintList = ContextCompat.getColorStateList(containerView.context, backgroundTint)
bookmark_favicon.backgroundTintList = backgroundTintList
val res = if (selected) R.drawable.mozac_ic_check else R.drawable.ic_folder_icon

View File

@ -39,10 +39,11 @@ import mozilla.components.concept.sync.AccountObserver
import mozilla.components.concept.sync.OAuthAccount
import mozilla.components.concept.sync.Profile
import mozilla.components.support.base.feature.BackHandler
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.BrowsingModeManager
import org.mozilla.fenix.DefaultThemeManager
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.BrowserDirection
import org.mozilla.fenix.components.FenixSnackbar
import org.mozilla.fenix.ext.allowUndo
import org.mozilla.fenix.ext.getColorFromAttr
@ -95,6 +96,14 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
override fun onDestroy() {
super.onDestroy()
job.cancel()
// Reset the toolbar color
val toolbar = (activity as AppCompatActivity).findViewById<Toolbar>(R.id.navigationToolbar)
val colorFilter = PorterDuffColorFilter(
R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN)
themeToolbar(toolbar, DefaultThemeManager.resolveAttribute(R.attr.primaryText, context!!),
DefaultThemeManager.resolveAttribute(R.attr.foundation, context!!), colorFilter)
}
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
@ -113,8 +122,8 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
}
is BookmarkState.Mode.Selecting -> {
inflater.inflate(R.menu.bookmarks_select_multi, menu)
val colorFilter =
PorterDuffColorFilter(R.attr.primaryText.getColorFromAttr(context!!), PorterDuff.Mode.SRC_IN)
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 {
@ -125,17 +134,25 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
}
activity?.title = getString(R.string.bookmarks_multi_select_title, mode.selectedItems.size)
themeToolbar(toolbar, colorFilter)
themeToolbar(toolbar, R.color.white_color,
DefaultThemeManager.resolveAttribute(R.attr.accentBright, context!!), colorFilter)
}
}
}
private fun themeToolbar(
toolbar: Toolbar,
colorFilter: PorterDuffColorFilter
textColor: Int,
backgroundColor: Int,
colorFilter: PorterDuffColorFilter? = null
) {
toolbar.setBackgroundColor(ContextCompat.getColor(context!!, R.color.bookmark_multi_select_actionbar))
toolbar.setTitleTextColor(R.attr.primaryText.getColorFromAttr(context!!))
toolbar.setTitleTextColor(ContextCompat.getColor(context!!, textColor))
toolbar.setBackgroundColor(ContextCompat.getColor(context!!, backgroundColor))
if (colorFilter == null) {
return
}
toolbar.overflowIcon?.colorFilter = colorFilter
(0 until toolbar.childCount).forEach {
when (val item = toolbar.getChildAt(it)) {

View File

@ -15,6 +15,7 @@ import mozilla.components.concept.storage.BookmarkNode
import mozilla.components.concept.storage.BookmarkNodeType
import mozilla.components.support.ktx.android.content.res.pxToDp
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getColorFromAttr
import org.mozilla.fenix.library.bookmarks.BookmarksSharedViewModel
class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedViewModel) :
@ -84,8 +85,13 @@ class SelectBookmarkFolderAdapter(private val sharedViewModel: BookmarksSharedVi
fun bind(folder: BookmarkNodeWithDepth, selected: Boolean, selectionInterface: SelectionInterface) {
val backgroundTint =
if (selected) R.color.bookmark_selection_appbar_background else R.color.bookmark_favicon_background
val backgroundTintList = ContextCompat.getColorStateList(containerView!!.context, backgroundTint)
if (selected) {
R.attr.accent.getColorFromAttr(containerView!!.context)
} else {
R.attr.neutral.getColorFromAttr(containerView!!.context)
}
val backgroundTintList = ContextCompat.getColorStateList(containerView.context, backgroundTint)
bookmark_favicon.backgroundTintList = backgroundTintList
val res = if (selected) R.drawable.mozac_ic_check else R.drawable.ic_folder_icon
bookmark_favicon.setImageResource(res)

View File

@ -45,9 +45,6 @@
<!-- Bookmark buttons -->
<color name="bookmark_favicon_background">#DFDFE3</color>
<color name="bookmark_multi_select_actionbar">#592ACB</color>
<color name="bookmark_snackbar_background">#2E0EC1</color>
<color name="bookmark_selection_appbar_background">#2E0EC1</color>
<!-- Session placeholder icons-->
<color name="session_placeholder_blue">#00B3F4</color>
@ -85,4 +82,5 @@
<!-- Misc colors applied universally-->
<color name="suggestion_highlight_color">#5C592ACB</color>
<color name="delete_color">@color/photonRed60</color>
<color name="white_color">#FBFBFE</color>
</resources>