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 8bb1d4b965..bc2dd24d76 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 @@ -148,7 +150,9 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } private fun getAppropriateLayoutGravity(): Int { - if (getSessionById()?.isCustomTabSession() == true) { return Gravity.TOP } + if (getSessionById()?.isCustomTabSession() == true) { + return Gravity.TOP + } return Gravity.BOTTOM } @@ -264,7 +268,11 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, ) thumbnailsFeature.set( - feature = ThumbnailsFeature(requireContext(), view.engineView, requireComponents.core.sessionManager), + feature = ThumbnailsFeature( + requireContext(), + view.engineView, + requireComponents.core.sessionManager + ), owner = this, view = view ) @@ -362,8 +370,15 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, getSessionById()?.let { session -> CoroutineScope(IO).launch { val guid = requireComponents.core.bookmarksStorage - .addItem(BookmarkRoot.Mobile.id, session.url, session.title, null) + .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( @@ -371,7 +386,10 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, Snackbar.LENGTH_LONG ) .setAction(getString(R.string.edit_bookmark_snackbar_action)) { - Navigation.findNavController(requireActivity(), R.id.container) + Navigation.findNavController( + requireActivity(), + R.id.container + ) .navigate( BrowserFragmentDirections .actionBrowserFragmentToBookmarkEditFragment( @@ -411,7 +429,11 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } } - override fun onRequestPermissionsResult(requestCode: Int, permissions: Array, grantResults: IntArray) { + override fun onRequestPermissionsResult( + requestCode: Int, + permissions: Array, + grantResults: IntArray + ) { when (requestCode) { REQUEST_CODE_DOWNLOAD_PERMISSIONS -> downloadsFeature.withFeature { it.onPermissionsResult(permissions, grantResults) @@ -473,14 +495,16 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, .navigate(BrowserFragmentDirections.actionBrowserFragmentToLibraryFragment()) is ToolbarMenu.Item.RequestDesktop -> sessionUseCases.requestDesktopSite.invoke(action.item.isChecked) ToolbarMenu.Item.Share -> getSessionById()?.let { session -> - session.url.apply { requireContext().share(this) + session.url.apply { + requireContext().share(this) } } ToolbarMenu.Item.NewPrivateTab -> { val directions = BrowserFragmentDirections .actionBrowserFragmentToSearchFragment(null) Navigation.findNavController(view!!).navigate(directions) - (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Private + (activity as HomeActivity).browsingModeManager.mode = + BrowsingModeManager.Mode.Private } ToolbarMenu.Item.FindInPage -> { FindInPageIntegration.launch?.invoke() @@ -500,7 +524,8 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, val directions = BrowserFragmentDirections .actionBrowserFragmentToSearchFragment(null) Navigation.findNavController(view!!).navigate(directions) - (activity as HomeActivity).browsingModeManager.mode = BrowsingModeManager.Mode.Normal + (activity as HomeActivity).browsingModeManager.mode = + BrowsingModeManager.Mode.Normal } ToolbarMenu.Item.OpenInFenix -> { val intent = Intent(context, IntentReceiverActivity::class.java) @@ -547,7 +572,11 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, private fun getSessionById(): Session? { return if (externalSessionId != null) { - requireNotNull(requireContext().components.core.sessionManager.findSessionById(externalSessionId!!)) + requireNotNull( + requireContext().components.core.sessionManager.findSessionById( + externalSessionId!! + ) + ) } else { requireComponents.core.sessionManager.selectedSession } @@ -562,6 +591,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) } } @@ -579,8 +611,21 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, } } + private fun searchBookmarks(session: Session) { + launch { + val list = requireComponents.core.bookmarksStorage.getBookmarksWithUrl(session.url) + val found = list.isNotEmpty() && list[0].url == session.url + launch(Main) { + getManagedEmitter() + .onNext(QuickActionChange.BookmarkedStateChange(found)) + } + } + } + private fun setToolbarBehavior(loading: Boolean) { - if (getSessionById()?.isCustomTabSession() == true) { return } + if (getSessionById()?.isCustomTabSession() == true) { + return + } val toolbarView = toolbarComponent.uiView.view (toolbarView.layoutParams as CoordinatorLayout.LayoutParams).apply { @@ -592,7 +637,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, behavior = BrowserToolbarBottomBehavior(context, null) } else { (behavior as? BrowserToolbarBottomBehavior)?.forceExpand(toolbarView) - null + behavior = null } } } @@ -603,6 +648,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope, private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2 private const val REQUEST_CODE_APP_PERMISSIONS = 3 private const val TOOLBAR_HEIGHT = 56f - const val REPORT_SITE_ISSUE_URL = "https://webcompat.com/issues/new?url=%s&label=browser-fenix" + const val REPORT_SITE_ISSUE_URL = + "https://webcompat.com/issues/new?url=%s&label=browser-fenix" } } 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 bb354a9da6..6dbff25438 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 88e8084a9f..e42fa13331 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,6 @@ class QuickActionUIView( override fun updateView() = Consumer { view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE + view.quick_action_bookmark.isSelected = it.bookmarked } } diff --git a/app/src/main/res/drawable/bookmark_two_state.xml b/app/src/main/res/drawable/bookmark_two_state.xml new file mode 100644 index 0000000000..3b704a91ea --- /dev/null +++ b/app/src/main/res/drawable/bookmark_two_state.xml @@ -0,0 +1,11 @@ + + + + + + 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 6527a3a8e3..a847916a2d 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 0000000000..dbbbf8c300 --- /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 84961be340..c72a3a228c 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 bdec44b119..796746bc73 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -91,8 +91,10 @@ #D4C1FA #2E2060 - #F4B8D9 - #491949 + #C60084 + #FFB4DB + #FFB4DB + #50134B #F5C0C6 #3E0909 diff --git a/debug.keystore b/debug.keystore new file mode 100644 index 0000000000..a04026c33c Binary files /dev/null and b/debug.keystore differ