Skip to content

Commit

Permalink
For mozilla-mobile#1601 - Bookmark icon should change visually if pag…
Browse files Browse the repository at this point in the history
…e is bookmarked
  • Loading branch information
ekager committed Apr 23, 2019
1 parent 911ef44 commit 8e6bad0
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 11 deletions.
22 changes: 22 additions & 0 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<QuickActionChange>()
.onNext(QuickActionChange.BookmarkedStateChange(true))
requireComponents.analytics.metrics.track(Event.AddBookmark)
view?.let {
FenixSnackbar.make(
Expand Down Expand Up @@ -543,13 +547,31 @@ 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)
}
}
requireComponents.core.sessionManager.selectedSession?.register(observer)
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<QuickActionChange>()
.onNext(QuickActionChange.BookmarkedStateChange(found))
}
}
}

private fun setToolbarBehavior(loading: Boolean) {
val toolbarView = toolbarComponent.uiView.view
(toolbarView.layoutParams as CoordinatorLayout.LayoutParams).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ 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<QuickActionState, QuickActionAction, QuickActionChange>(
bus.getManagedEmitter(QuickActionAction::class.java),
bus.getSafeManagedObservable(QuickActionChange::class.java)
) {

override val reducer: Reducer<QuickActionState, QuickActionChange> = { state, change ->
when (change) {
is QuickActionChange.BookmarkedStateChange -> {
state.copy(bookmarked = change.bookmarked)
}
is QuickActionChange.ReadableStateChange -> {
state.copy(readable = change.readable)
}
Expand All @@ -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()
Expand All @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,15 @@ class QuickActionUIView(

override fun updateView() = Consumer<QuickActionState> {
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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/library_bookmarks_icon"
android:fillType="evenOdd"
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"
android:strokeWidth="1"
android:strokeColor="#00000000" />
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" />
</vector>
</item>
</layer-list>
29 changes: 29 additions & 0 deletions app/src/main/res/drawable/bookmarks_circle_background_outline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:width="40dp"
android:height="40dp" />
<solid android:color="@color/library_bookmarks_icon_background" />
</shape>
</item>
<item
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp">
<vector
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/bookmarks_icon_outline"
android:pathData="M12,2a1,1 0,0 1,0.87 0.507l2.768,4.884 5.536,0.977a1,1 0,0 1,0.624 1.588l-3.744,4.955 0.934,5.934a1,1 0,0 1,-1.456 1.039L12,18.955l-5.532,2.929a1,1 0,0 1,-1.456 -1.04l0.934,-5.933 -3.744,-4.955a1,1 0,0 1,0.624 -1.588l5.536,-0.977 2.768,-4.884A1,1 0,0 1,12 2zM12,5.028l-2.13,3.76a1,1 0,0 1,-0.696 0.49l-4.391,0.776 3.015,3.99a1,1 0,0 1,0.19 0.759l-0.69,4.378 4.234,-2.241a1,1 0,0 1,0.936 0l4.232,2.24 -0.689,-4.378a1,1 0,0 1,0.19 -0.759l3.015,-3.99 -4.39,-0.775a1,1 0,0 1,-0.697 -0.492L12,5.028z" />
</vector>
</item>
</layer-list>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_library.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<org.mozilla.fenix.library.LibraryListItem
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/layout_quick_action_sheet.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?selectableItemBackgroundBorderless"
android:drawableTop="@drawable/library_icon_bookmarks_circle_background"
android:drawableTop="@drawable/bookmarks_circle_background_outline"
android:drawablePadding="5dp"
android:text="@string/quick_action_bookmark"
android:textAllCaps="false"
Expand Down Expand Up @@ -99,4 +99,4 @@
android:alpha="1.0"
android:background="?foundation" />
</FrameLayout>
</LinearLayout>
</LinearLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
<color name="library_downloads_icon">#2E2060</color>

<color name="library_bookmarks_icon_background">#F4B8D9</color>
<color name="library_bookmarks_icon">#491949</color>
<color name="bookmarks_icon_filled">#C60084</color>
<color name="bookmarks_icon_outline">#50134B</color>

<color name="library_history_icon_background">#F5C0C6</color>
<color name="library_history_icon">#3E0909</color>
Expand Down
Binary file added debug.keystore
Binary file not shown.

0 comments on commit 8e6bad0

Please sign in to comment.