mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-19 09:25:34 +00:00
[fenix] No issue: refresh after undoing bookmark deletion (https://github.com/mozilla-mobile/fenix/pull/2198)
This commit is contained in:
parent
809cf9bb6c
commit
f5614eb93a
@ -6,13 +6,20 @@ package org.mozilla.fenix.ext
|
|||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers.IO
|
||||||
|
import kotlinx.coroutines.Dispatchers.Main
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.mozilla.fenix.components.FenixSnackbar
|
import org.mozilla.fenix.components.FenixSnackbar
|
||||||
|
|
||||||
fun CoroutineScope.allowUndo(view: View, message: String, undoActionTitle: String, operation: suspend () -> Unit) {
|
fun CoroutineScope.allowUndo(
|
||||||
val undoJob = launch(Dispatchers.IO) {
|
view: View,
|
||||||
|
message: String,
|
||||||
|
undoActionTitle: String,
|
||||||
|
onCancel: suspend () -> Unit = {},
|
||||||
|
operation: suspend () -> Unit
|
||||||
|
) {
|
||||||
|
val undoJob = launch(IO) {
|
||||||
delay(UNDO_DELAY)
|
delay(UNDO_DELAY)
|
||||||
operation.invoke()
|
operation.invoke()
|
||||||
}
|
}
|
||||||
@ -20,6 +27,9 @@ fun CoroutineScope.allowUndo(view: View, message: String, undoActionTitle: Strin
|
|||||||
.setText(message)
|
.setText(message)
|
||||||
.setAction(undoActionTitle) {
|
.setAction(undoActionTitle) {
|
||||||
undoJob.cancel()
|
undoJob.cancel()
|
||||||
|
launch(Main) {
|
||||||
|
onCancel.invoke()
|
||||||
|
}
|
||||||
}.show()
|
}.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
|
|||||||
|
|
||||||
CoroutineScope(Main).allowUndo(
|
CoroutineScope(Main).allowUndo(
|
||||||
view!!, getString(R.string.bookmark_deletion_snackbar_message, it.item.url.urlToHost()),
|
view!!, getString(R.string.bookmark_deletion_snackbar_message, it.item.url.urlToHost()),
|
||||||
getString(R.string.bookmark_undo_deletion)
|
getString(R.string.bookmark_undo_deletion), { refreshBookmarks(components) }
|
||||||
) {
|
) {
|
||||||
components.core.bookmarksStorage.deleteNode(it.item.guid)
|
components.core.bookmarksStorage.deleteNode(it.item.guid)
|
||||||
components.analytics.metrics.track(Event.RemoveBookmark)
|
components.analytics.metrics.track(Event.RemoveBookmark)
|
||||||
@ -292,7 +292,7 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
|
|||||||
|
|
||||||
CoroutineScope(Main).allowUndo(
|
CoroutineScope(Main).allowUndo(
|
||||||
view!!, getString(R.string.bookmark_deletion_multiple_snackbar_message),
|
view!!, getString(R.string.bookmark_deletion_multiple_snackbar_message),
|
||||||
getString(R.string.bookmark_undo_deletion)
|
getString(R.string.bookmark_undo_deletion), { refreshBookmarks(components) }
|
||||||
) {
|
) {
|
||||||
deleteSelectedBookmarks(selectedBookmarks, components)
|
deleteSelectedBookmarks(selectedBookmarks, components)
|
||||||
components.analytics.metrics.track(Event.RemoveBookmarks)
|
components.analytics.metrics.track(Event.RemoveBookmarks)
|
||||||
|
Loading…
Reference in New Issue
Block a user