2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00
This commit is contained in:
Colin Lee 2019-05-01 12:21:28 -05:00 committed by GitHub
parent 4a58a8ece1
commit 93aed2ebe0

View File

@ -370,42 +370,7 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
} }
is QuickActionAction.BookmarkPressed -> { is QuickActionAction.BookmarkPressed -> {
requireComponents.analytics.metrics.track(Event.QuickActionSheetBookmarkTapped) requireComponents.analytics.metrics.track(Event.QuickActionSheetBookmarkTapped)
getSessionById()?.let { session -> bookmarkTapped()
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()
}
}
}
}
} }
is QuickActionAction.ReadPressed -> { is QuickActionAction.ReadPressed -> {
requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped) requireComponents.analytics.metrics.track(Event.QuickActionSheetReadTapped)
@ -416,6 +381,58 @@ class BrowserFragment : Fragment(), BackHandler, CoroutineScope,
assignSitePermissionsRules() 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() { override fun onStop() {
super.onStop() super.onStop()
sessionObserver?.let { sessionObserver?.let {