Some tweaks on Updates screen (#7729)

Based on #7708, #7709 and #7717

Co-Authored-By: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com>
Co-Authored-By: Andreas <6576096+ghostbear@users.noreply.github.com>

Co-authored-by: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com>
Co-authored-by: Andreas <6576096+ghostbear@users.noreply.github.com>
This commit is contained in:
AntsyLich
2022-08-12 22:21:05 +06:00
committed by GitHub
parent 441e7bf8b1
commit 1474c8ffb3
3 changed files with 40 additions and 20 deletions

View File

@@ -54,8 +54,13 @@ class UpdatesController :
// Let compose view handle this
override fun handleBack(): Boolean {
(activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher?.onBackPressed()
return true
val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false
return if (dispatcher.hasEnabledCallbacks()) {
dispatcher.onBackPressed()
true
} else {
false
}
}
private fun onBackClicked() {

View File

@@ -157,13 +157,12 @@ class UpdatesPresenter(
* @param download download object containing progress.
*/
private fun updateDownloadState(download: Download) {
val uiModels = state.uiModels
val modifiedIndex = uiModels.indexOfFirst {
it is UpdatesUiModel.Item && it.item.update.chapterId == download.chapter.id
}
if (modifiedIndex < 0) return
state.uiModels = uiModels.toMutableList().apply {
val modifiedIndex = uiModels.indexOfFirst {
it is UpdatesUiModel.Item && it.item.update.chapterId == download.chapter.id
}
if (modifiedIndex < 0) return@apply
var uiModel = removeAt(modifiedIndex)
if (uiModel is UpdatesUiModel.Item) {
val item = uiModel.item.copy(
@@ -249,7 +248,6 @@ class UpdatesPresenter(
downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id }
}
val uiModels = state.uiModels
val deletedUpdates = uiModels.filter {
it is UpdatesUiModel.Item && deletedIds.contains(it.item.update.chapterId)
}
@@ -279,16 +277,15 @@ class UpdatesPresenter(
userSelected: Boolean = false,
fromLongPress: Boolean = false,
) {
val uiModels = state.uiModels
val modifiedIndex = uiModels.indexOfFirst {
it is UpdatesUiModel.Item && it.item.update.chapterId == item.update.chapterId
}
if (modifiedIndex < 0) return
val oldItem = (uiModels[modifiedIndex] as? UpdatesUiModel.Item)?.item ?: return
if ((oldItem.selected && selected) || (!oldItem.selected && !selected)) return
state.uiModels = uiModels.toMutableList().apply {
val modifiedIndex = indexOfFirst {
it is UpdatesUiModel.Item && it.item == item
}
if (modifiedIndex < 0) return@apply
val oldItem = (get(modifiedIndex) as? UpdatesUiModel.Item)?.item ?: return@apply
if ((oldItem.selected && selected) || (!oldItem.selected && !selected)) return@apply
val firstSelection = none { it is UpdatesUiModel.Item && it.item.selected }
var newItem = (removeAt(modifiedIndex) as? UpdatesUiModel.Item)?.item?.copy(selected = selected) ?: return@apply
add(modifiedIndex, UpdatesUiModel.Item(newItem))