[fenix] No issue: refresh after undoing bookmark deletion (https://github.com/mozilla-mobile/fenix/pull/2198)

pull/600/head
Colin Lee 6 years ago committed by GitHub
parent 809cf9bb6c
commit f5614eb93a

@ -6,13 +6,20 @@ package org.mozilla.fenix.ext
import android.view.View
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.launch
import org.mozilla.fenix.components.FenixSnackbar
fun CoroutineScope.allowUndo(view: View, message: String, undoActionTitle: String, operation: suspend () -> Unit) {
val undoJob = launch(Dispatchers.IO) {
fun CoroutineScope.allowUndo(
view: View,
message: String,
undoActionTitle: String,
onCancel: suspend () -> Unit = {},
operation: suspend () -> Unit
) {
val undoJob = launch(IO) {
delay(UNDO_DELAY)
operation.invoke()
}
@ -20,6 +27,9 @@ fun CoroutineScope.allowUndo(view: View, message: String, undoActionTitle: Strin
.setText(message)
.setAction(undoActionTitle) {
undoJob.cancel()
launch(Main) {
onCancel.invoke()
}
}.show()
}

@ -219,7 +219,7 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
CoroutineScope(Main).allowUndo(
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.analytics.metrics.track(Event.RemoveBookmark)
@ -292,7 +292,7 @@ class BookmarkFragment : Fragment(), CoroutineScope, BackHandler, AccountObserve
CoroutineScope(Main).allowUndo(
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)
components.analytics.metrics.track(Event.RemoveBookmarks)

Loading…
Cancel
Save