From eea19362d0c83eb30949c149883c8065f8094685 Mon Sep 17 00:00:00 2001 From: Emily Kager Date: Tue, 23 Apr 2019 11:32:48 -0700 Subject: [PATCH] For #1601 - Bookmark icon should change visually if page is bookmarked --- .../mozilla/fenix/browser/BrowserFragment.kt | 22 +++++++++++++ .../quickactionsheet/QuickActionComponent.kt | 11 +++++-- .../quickactionsheet/QuickActionUIView.kt | 10 ++++++ ...=> bookmarks_circle_background_filled.xml} | 9 ++---- .../bookmarks_circle_background_outline.xml | 29 ++++++++++++++++++ app/src/main/res/layout/fragment_library.xml | 2 +- .../res/layout/layout_quick_action_sheet.xml | 4 +-- app/src/main/res/values/colors.xml | 6 ++-- debug.keystore | Bin 0 -> 2625 bytes 9 files changed, 80 insertions(+), 13 deletions(-) rename app/src/main/res/drawable/{library_icon_bookmarks_circle_background.xml => bookmarks_circle_background_filled.xml} (80%) create mode 100644 app/src/main/res/drawable/bookmarks_circle_background_outline.xml create mode 100644 debug.keystore diff --git a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt index b6fc1cfb1ba2..b401c0a83343 100644 --- a/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt +++ b/app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt @@ -70,7 +70,9 @@ import org.mozilla.fenix.ext.share import org.mozilla.fenix.lib.Do import org.mozilla.fenix.mvi.ActionBusFactory import org.mozilla.fenix.mvi.getAutoDisposeObservable +import org.mozilla.fenix.mvi.getManagedEmitter import org.mozilla.fenix.quickactionsheet.QuickActionAction +import org.mozilla.fenix.quickactionsheet.QuickActionChange import org.mozilla.fenix.quickactionsheet.QuickActionComponent import org.mozilla.fenix.settings.quicksettings.QuickSettingsSheetDialogFragment import org.mozilla.fenix.utils.ItsNotBrokenSnack @@ -351,6 +353,8 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { val guid = requireComponents.core.bookmarksStorage .addItem(BookmarkRoot.Mobile.id, session.url, session.title, null) launch(Main) { + getManagedEmitter() + .onNext(QuickActionChange.BookmarkedStateChange(true)) requireComponents.analytics.metrics.track(Event.AddBookmark) view?.let { FenixSnackbar.make( @@ -543,6 +547,9 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { val observer = object : Session.Observer { override fun onLoadingStateChanged(session: Session, loading: Boolean) { super.onLoadingStateChanged(session, loading) + if (!loading) { + searchBookmarks(session) + } setToolbarBehavior(loading) } } @@ -550,6 +557,21 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope { return observer } + private fun searchBookmarks(session: Session) { + launch { + val list = + requireComponents.core.bookmarksStorage.searchBookmarks( + session.title, + 1 + ) + val found = list.isNotEmpty() && list[0].url == session.url + launch(Main) { + getManagedEmitter() + .onNext(QuickActionChange.BookmarkedStateChange(found)) + } + } + } + private fun setToolbarBehavior(loading: Boolean) { val toolbarView = toolbarComponent.uiView.view (toolbarView.layoutParams as CoordinatorLayout.LayoutParams).apply { diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt index bb354a9da6e4..6dbff2543883 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionComponent.kt @@ -16,7 +16,10 @@ import org.mozilla.fenix.mvi.ViewState class QuickActionComponent( private val container: ViewGroup, bus: ActionBusFactory, - override var initialState: QuickActionState = QuickActionState(false) + override var initialState: QuickActionState = QuickActionState( + readable = false, + bookmarked = false + ) ) : UIComponent( bus.getManagedEmitter(QuickActionAction::class.java), bus.getSafeManagedObservable(QuickActionChange::class.java) @@ -24,6 +27,9 @@ class QuickActionComponent( override val reducer: Reducer = { state, change -> when (change) { + is QuickActionChange.BookmarkedStateChange -> { + state.copy(bookmarked = change.bookmarked) + } is QuickActionChange.ReadableStateChange -> { state.copy(readable = change.readable) } @@ -38,7 +44,7 @@ class QuickActionComponent( } } -data class QuickActionState(val readable: Boolean) : ViewState +data class QuickActionState(val readable: Boolean, val bookmarked: Boolean) : ViewState sealed class QuickActionAction : Action { object Opened : QuickActionAction() @@ -50,5 +56,6 @@ sealed class QuickActionAction : Action { } sealed class QuickActionChange : Change { + data class BookmarkedStateChange(val bookmarked: Boolean) : QuickActionChange() data class ReadableStateChange(val readable: Boolean) : QuickActionChange() } diff --git a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt index 88e8084a9fc7..74ff10d1f696 100644 --- a/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt +++ b/app/src/main/java/org/mozilla/fenix/quickactionsheet/QuickActionUIView.kt @@ -97,5 +97,15 @@ class QuickActionUIView( override fun updateView() = Consumer { view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE + val bookmarkDrawable = + if (it.bookmarked) + R.drawable.bookmarks_circle_background_filled else + R.drawable.bookmarks_circle_background_outline + view.quick_action_bookmark.setCompoundDrawablesWithIntrinsicBounds( + 0, + bookmarkDrawable, + 0, + 0 + ) } } diff --git a/app/src/main/res/drawable/library_icon_bookmarks_circle_background.xml b/app/src/main/res/drawable/bookmarks_circle_background_filled.xml similarity index 80% rename from app/src/main/res/drawable/library_icon_bookmarks_circle_background.xml rename to app/src/main/res/drawable/bookmarks_circle_background_filled.xml index 6527a3a8e342..a847916a2d3a 100644 --- a/app/src/main/res/drawable/library_icon_bookmarks_circle_background.xml +++ b/app/src/main/res/drawable/bookmarks_circle_background_filled.xml @@ -8,7 +8,7 @@ - + + android:fillColor="@color/bookmarks_icon_filled" + android:pathData="M6.749,21.248C6.4234,21.2471 6.1142,21.1054 5.9008,20.8595C5.6875,20.6136 5.5909,20.2874 5.636,19.965L6.414,14.4L2.674,10.38C2.3928,10.0785 2.2991,9.6474 2.4296,9.2564C2.5601,8.8654 2.8941,8.5771 3.3,8.505L8.529,7.57L10.993,2.624C11.1833,2.242 11.5733,2.0006 12,2.0006C12.4267,2.0006 12.8167,2.242 13.007,2.624L15.471,7.57L20.7,8.5C21.1057,8.5724 21.4394,8.8608 21.5697,9.2518C21.7,9.6427 21.6062,10.0737 21.325,10.375L17.586,14.4L18.364,19.968C18.4229,20.3853 18.2434,20.8005 17.8991,21.0434C17.5547,21.2864 17.1034,21.3164 16.73,21.121L12,18.654L7.269,21.119C7.1087,21.2035 6.9302,21.2478 6.749,21.248Z" /> diff --git a/app/src/main/res/drawable/bookmarks_circle_background_outline.xml b/app/src/main/res/drawable/bookmarks_circle_background_outline.xml new file mode 100644 index 000000000000..dbbbf8c3003e --- /dev/null +++ b/app/src/main/res/drawable/bookmarks_circle_background_outline.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_library.xml b/app/src/main/res/layout/fragment_library.xml index 84961be34047..c72a3a228c6b 100644 --- a/app/src/main/res/layout/fragment_library.xml +++ b/app/src/main/res/layout/fragment_library.xml @@ -21,7 +21,7 @@ android:clickable="true" android:contentDescription="@string/library_bookmarks" android:focusable="true" - app:listItemIcon="@drawable/library_icon_bookmarks_circle_background" + app:listItemIcon="@drawable/bookmarks_circle_background_filled" app:listItemTitle="@string/library_bookmarks" /> - \ No newline at end of file + diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 2b4d33d5f006..ab872a99c205 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -83,8 +83,10 @@ #D4C1FA #2E2060 - #F4B8D9 - #491949 + #C60084 + #FFB4DB + #FFB4DB + #50134B #F5C0C6 #3E0909 diff --git a/debug.keystore b/debug.keystore new file mode 100644 index 0000000000000000000000000000000000000000..a04026c33c4efda3e7ef8a99d6ee5a94bf61201e GIT binary patch literal 2625 zcmY+Ec{tRI8pnULVeFS-hDkUS$!P3rjIj-}l;xBqnMTdn$CfqOCQBsyo;^|7Bb2M>gqbuCQ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