Add Remove from history action on details activity
This commit is contained in:
@@ -7,12 +7,16 @@ import org.koitharu.kotatsu.R
|
|||||||
|
|
||||||
class ReversibleActionObserver(
|
class ReversibleActionObserver(
|
||||||
private val snackbarHost: View,
|
private val snackbarHost: View,
|
||||||
|
private val snackbarAnchor: View? = null,
|
||||||
) : FlowCollector<ReversibleAction> {
|
) : FlowCollector<ReversibleAction> {
|
||||||
|
|
||||||
override suspend fun emit(value: ReversibleAction) {
|
override suspend fun emit(value: ReversibleAction) {
|
||||||
val handle = value.handle
|
val handle = value.handle
|
||||||
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
val length = if (handle == null) Snackbar.LENGTH_SHORT else Snackbar.LENGTH_LONG
|
||||||
val snackbar = Snackbar.make(snackbarHost, value.stringResId, length)
|
val snackbar = Snackbar.make(snackbarHost, value.stringResId, length)
|
||||||
|
if (snackbarAnchor?.isShown == true) {
|
||||||
|
snackbar.anchorView = snackbarAnchor
|
||||||
|
}
|
||||||
if (handle != null) {
|
if (handle != null) {
|
||||||
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
snackbar.setAction(R.string.undo) { handle.reverseAsync() }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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.onShowTip.observeEvent(this) { showTip() }
|
||||||
viewModel.historyInfo.observe(this, ::onHistoryChanged)
|
viewModel.historyInfo.observe(this, ::onHistoryChanged)
|
||||||
viewModel.selectedBranch.observe(this) {
|
viewModel.selectedBranch.observe(this) {
|
||||||
@@ -187,6 +187,9 @@ class DetailsActivity :
|
|||||||
buttonTip = null
|
buttonTip = null
|
||||||
val menu = PopupMenu(v.context, v)
|
val menu = PopupMenu(v.context, v)
|
||||||
menu.inflate(R.menu.popup_read)
|
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.setOnMenuItemClickListener(this)
|
||||||
menu.setForceShowIcon(true)
|
menu.setForceShowIcon(true)
|
||||||
menu.show()
|
menu.show()
|
||||||
@@ -203,6 +206,11 @@ class DetailsActivity :
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
R.id.action_forget -> {
|
||||||
|
viewModel.removeFromHistory()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
R.id.action_pages_thumbs -> {
|
R.id.action_pages_thumbs -> {
|
||||||
val history = viewModel.historyInfo.value.history
|
val history = viewModel.historyInfo.value.history
|
||||||
PagesThumbnailsSheet.show(
|
PagesThumbnailsSheet.show(
|
||||||
|
|||||||
@@ -346,6 +346,13 @@ class DetailsViewModel @Inject constructor(
|
|||||||
settings.closeTip(DetailsActivity.TIP_BUTTON)
|
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) {
|
private fun doLoad() = launchLoadingJob(Dispatchers.Default) {
|
||||||
detailsLoadUseCase.invoke(intent)
|
detailsLoadUseCase.invoke(intent)
|
||||||
.onEachWhile {
|
.onEachWhile {
|
||||||
|
|||||||
@@ -12,4 +12,9 @@
|
|||||||
android:icon="@drawable/ic_grid"
|
android:icon="@drawable/ic_grid"
|
||||||
android:title="@string/pages" />
|
android:title="@string/pages" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_forget"
|
||||||
|
android:icon="@drawable/ic_delete"
|
||||||
|
android:title="@string/remove_from_history" />
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
|||||||
@@ -597,4 +597,5 @@
|
|||||||
<string name="pages_saving">Saving pages</string>
|
<string name="pages_saving">Saving pages</string>
|
||||||
<string name="ask_for_dest_dir_every_time">Ask for the destination dir every time</string>
|
<string name="ask_for_dest_dir_every_time">Ask for the destination dir every time</string>
|
||||||
<string name="default_page_save_dir">Default page save directory</string>
|
<string name="default_page_save_dir">Default page save directory</string>
|
||||||
|
<string name="remove_from_history">Remove from history</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user