diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/ReversibleActionObserver.kt b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/ReversibleActionObserver.kt index b66e64cbb..8d94173d9 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/ReversibleActionObserver.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/core/ui/util/ReversibleActionObserver.kt @@ -7,12 +7,16 @@ import org.koitharu.kotatsu.R class ReversibleActionObserver( private val snackbarHost: View, + private val snackbarAnchor: View? = null, ) : FlowCollector { override suspend fun emit(value: ReversibleAction) { val handle = value.handle val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG val snackbar = Snackbar.make(snackbarHost, value.stringResId, length) + if (snackbarAnchor?.isShown == true) { + snackbar.anchorView = snackbarAnchor + } if (handle != null) { snackbar.setAction(R.string.undo) { handle.reverseAsync() } } diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt index af2ff95ee..54851696e 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsActivity.kt @@ -138,7 +138,7 @@ class DetailsActivity : }, ), ) - viewModel.onActionDone.observeEvent(this, ReversibleActionObserver(viewBinding.containerDetails)) + viewModel.onActionDone.observeEvent(this, ReversibleActionObserver(viewBinding.containerDetails, viewBinding.layoutBottom)) viewModel.onShowTip.observeEvent(this) { showTip() } viewModel.historyInfo.observe(this, ::onHistoryChanged) viewModel.selectedBranch.observe(this) { @@ -187,6 +187,9 @@ class DetailsActivity : buttonTip = null val menu = PopupMenu(v.context, v) menu.inflate(R.menu.popup_read) + menu.menu.findItem(R.id.action_forget)?.isVisible = viewModel.historyInfo.value.run { + !isIncognitoMode && history != null + } menu.setOnMenuItemClickListener(this) menu.setForceShowIcon(true) menu.show() @@ -203,6 +206,11 @@ class DetailsActivity : true } + R.id.action_forget -> { + viewModel.removeFromHistory() + true + } + R.id.action_pages_thumbs -> { val history = viewModel.historyInfo.value.history PagesThumbnailsSheet.show( diff --git a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt index b40073093..e9f6d59a2 100644 --- a/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt +++ b/app/src/main/kotlin/org/koitharu/kotatsu/details/ui/DetailsViewModel.kt @@ -346,6 +346,13 @@ class DetailsViewModel @Inject constructor( settings.closeTip(DetailsActivity.TIP_BUTTON) } + fun removeFromHistory() { + launchJob(Dispatchers.Default) { + val handle = historyRepository.delete(setOf(mangaId)) + onActionDone.call(ReversibleAction(R.string.removed_from_history, handle)) + } + } + private fun doLoad() = launchLoadingJob(Dispatchers.Default) { detailsLoadUseCase.invoke(intent) .onEachWhile { diff --git a/app/src/main/res/menu/popup_read.xml b/app/src/main/res/menu/popup_read.xml index 256f2ef54..d7f442667 100644 --- a/app/src/main/res/menu/popup_read.xml +++ b/app/src/main/res/menu/popup_read.xml @@ -12,4 +12,9 @@ android:icon="@drawable/ic_grid" android:title="@string/pages" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 74a7f514e..639bfbc4e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -597,4 +597,5 @@ Saving pages Ask for the destination dir every time Default page save directory + Remove from history