2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-03 23:15:31 +00:00

For #1586: Behavior when adding a duplicate bookmark (#2195)

This commit is contained in:
Colin Lee 2019-05-01 12:21:28 -05:00 committed by GitHub
parent a4c201f2ee
commit b931957426
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -370,42 +370,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
}
is QuickActionAction.BookmarkPressed -> {
requireComponents.analytics.metrics.track(Event.QuickActionSheetBookmarkTapped)
getSessionById()?.let { session ->
CoroutineScope(IO).launch {
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(
it,
Snackbar.LENGTH_LONG
)
.setAction(getString(R.string.edit_bookmark_snackbar_action)) {
Navigation.findNavController(
requireActivity(),
R.id.container
)
.navigate(
BrowserFragmentDirections
.actionBrowserFragmentToBookmarkEditFragment(
guid
)
)
}
.setText(getString(R.string.bookmark_saved_snackbar))
.show()
}
}
}
}
bookmarkTapped()
}
is QuickActionAction.ReadPressed -> {
requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped)
@ -416,6 +381,58 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
assignSitePermissionsRules()
}
private fun bookmarkTapped() {
getSessionById()?.let { session ->
CoroutineScope(IO).launch {
val components = requireComponents
val existing = components.core.bookmarksStorage.getBookmarksWithUrl(session.url)
val found = existing.isNotEmpty() && existing[0].url == session.url
if (found) {
launch(Main) {
Navigation.findNavController(requireActivity(), R.id.container)
.navigate(
BrowserFragmentDirections
.actionBrowserFragmentToBookmarkEditFragment(existing[0].guid)
)
}
} else {
val guid = components.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(
it,
Snackbar.LENGTH_LONG
)
.setAction(getString(R.string.edit_bookmark_snackbar_action)) {
Navigation.findNavController(
requireActivity(),
R.id.container
)
.navigate(
BrowserFragmentDirections
.actionBrowserFragmentToBookmarkEditFragment(
guid
)
)
}
.setText(getString(R.string.bookmark_saved_snackbar))
.show()
}
}
}
}
}
}
override fun onStop() {
super.onStop()
sessionObserver?.let {