mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-09 19:10:42 +00:00
For #1601 - Bookmark icon should change visually if page is bookmarked
This commit is contained in:
parent
bc10c65c52
commit
99f979e86b
@ -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<QuickActionChange>()
|
||||
.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<String>, grantResults: IntArray) {
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<String>,
|
||||
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<QuickActionChange>()
|
||||
.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"
|
||||
}
|
||||
}
|
||||
|
@ -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<QuickActionState, QuickActionAction, QuickActionChange>(
|
||||
bus.getManagedEmitter(QuickActionAction::class.java),
|
||||
bus.getSafeManagedObservable(QuickActionChange::class.java)
|
||||
@ -24,6 +27,9 @@ class QuickActionComponent(
|
||||
|
||||
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)
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
|
@ -97,5 +97,6 @@ class QuickActionUIView(
|
||||
|
||||
override fun updateView() = Consumer<QuickActionState> {
|
||||
view.quick_action_read.visibility = if (it.readable) View.VISIBLE else View.GONE
|
||||
view.quick_action_bookmark.isSelected = it.bookmarked
|
||||
}
|
||||
}
|
||||
|
11
app/src/main/res/drawable/bookmark_two_state.xml
Normal file
11
app/src/main/res/drawable/bookmark_two_state.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?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/. -->
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:enterFadeDuration="150" android:exitFadeDuration="150">
|
||||
<item android:state_selected="false"
|
||||
android:drawable="@drawable/bookmarks_circle_background_outline" />
|
||||
<item android:state_selected="true"
|
||||
android:drawable="@drawable/bookmarks_circle_background_filled" />
|
||||
</selector>
|
@ -8,7 +8,7 @@
|
||||
<size
|
||||
android:width="40dp"
|
||||
android:height="40dp" />
|
||||
<solid android:color="@color/library_bookmarks_icon_background" />
|
||||
<solid android:color="@color/bookmarks_icon_background_filled" />
|
||||
</shape>
|
||||
</item>
|
||||
<item
|
||||
@ -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>
|
@ -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/bookmarks_icon_background_outline" />
|
||||
</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>
|
@ -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
|
||||
|
@ -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/bookmark_two_state"
|
||||
android:drawablePadding="5dp"
|
||||
android:text="@string/quick_action_bookmark"
|
||||
android:textAllCaps="false"
|
||||
|
@ -91,8 +91,10 @@
|
||||
<color name="library_downloads_icon_background">#D4C1FA</color>
|
||||
<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_background_filled">#C60084</color>
|
||||
<color name="bookmarks_icon_filled">#FFB4DB</color>
|
||||
<color name="bookmarks_icon_background_outline">#FFB4DB</color>
|
||||
<color name="bookmarks_icon_outline">#50134B</color>
|
||||
|
||||
<color name="library_history_icon_background">#F5C0C6</color>
|
||||
<color name="library_history_icon">#3E0909</color>
|
||||
|
BIN
debug.keystore
Normal file
BIN
debug.keystore
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user