mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-27 03:18:25 +01:00
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:
parent
441e7bf8b1
commit
1474c8ffb3
@ -24,6 +24,11 @@ import androidx.compose.material3.TopAppBarScrollBehavior
|
|||||||
import androidx.compose.material3.rememberTopAppBarState
|
import androidx.compose.material3.rememberTopAppBarState
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
import androidx.compose.ui.input.nestedscroll.nestedScroll
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@ -49,7 +54,9 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter
|
|||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Dialog
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Dialog
|
||||||
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Event
|
import eu.kanade.tachiyomi.ui.recent.updates.UpdatesPresenter.Event
|
||||||
import eu.kanade.tachiyomi.util.system.toast
|
import eu.kanade.tachiyomi.util.system.toast
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.collectLatest
|
import kotlinx.coroutines.flow.collectLatest
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -115,9 +122,20 @@ fun UpdateScreen(
|
|||||||
val contentPaddingWithNavBar = (if (presenter.selectionMode) PaddingValues() else bottomNavPaddingValues) +
|
val contentPaddingWithNavBar = (if (presenter.selectionMode) PaddingValues() else bottomNavPaddingValues) +
|
||||||
contentPadding + WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues()
|
contentPadding + WindowInsets.navigationBars.only(WindowInsetsSides.Bottom).asPaddingValues()
|
||||||
|
|
||||||
|
val scope = rememberCoroutineScope()
|
||||||
|
var isRefreshing by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
SwipeRefresh(
|
SwipeRefresh(
|
||||||
state = rememberSwipeRefreshState(isRefreshing = false),
|
state = rememberSwipeRefreshState(isRefreshing = isRefreshing),
|
||||||
onRefresh = onUpdateLibrary,
|
onRefresh = {
|
||||||
|
onUpdateLibrary()
|
||||||
|
scope.launch {
|
||||||
|
// Fake refresh status but hide it after a second as it's a long running task
|
||||||
|
isRefreshing = true
|
||||||
|
delay(1000)
|
||||||
|
isRefreshing = false
|
||||||
|
}
|
||||||
|
},
|
||||||
swipeEnabled = presenter.selectionMode.not(),
|
swipeEnabled = presenter.selectionMode.not(),
|
||||||
indicatorPadding = contentPaddingWithNavBar,
|
indicatorPadding = contentPaddingWithNavBar,
|
||||||
indicator = { s, trigger ->
|
indicator = { s, trigger ->
|
||||||
|
@ -54,8 +54,13 @@ class UpdatesController :
|
|||||||
|
|
||||||
// Let compose view handle this
|
// Let compose view handle this
|
||||||
override fun handleBack(): Boolean {
|
override fun handleBack(): Boolean {
|
||||||
(activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher?.onBackPressed()
|
val dispatcher = (activity as? OnBackPressedDispatcherOwner)?.onBackPressedDispatcher ?: return false
|
||||||
return true
|
return if (dispatcher.hasEnabledCallbacks()) {
|
||||||
|
dispatcher.onBackPressed()
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onBackClicked() {
|
private fun onBackClicked() {
|
||||||
|
@ -157,13 +157,12 @@ class UpdatesPresenter(
|
|||||||
* @param download download object containing progress.
|
* @param download download object containing progress.
|
||||||
*/
|
*/
|
||||||
private fun updateDownloadState(download: Download) {
|
private fun updateDownloadState(download: Download) {
|
||||||
val uiModels = state.uiModels
|
state.uiModels = uiModels.toMutableList().apply {
|
||||||
val modifiedIndex = uiModels.indexOfFirst {
|
val modifiedIndex = uiModels.indexOfFirst {
|
||||||
it is UpdatesUiModel.Item && it.item.update.chapterId == download.chapter.id
|
it is UpdatesUiModel.Item && it.item.update.chapterId == download.chapter.id
|
||||||
}
|
}
|
||||||
if (modifiedIndex < 0) return
|
if (modifiedIndex < 0) return@apply
|
||||||
|
|
||||||
state.uiModels = uiModels.toMutableList().apply {
|
|
||||||
var uiModel = removeAt(modifiedIndex)
|
var uiModel = removeAt(modifiedIndex)
|
||||||
if (uiModel is UpdatesUiModel.Item) {
|
if (uiModel is UpdatesUiModel.Item) {
|
||||||
val item = uiModel.item.copy(
|
val item = uiModel.item.copy(
|
||||||
@ -249,7 +248,6 @@ class UpdatesPresenter(
|
|||||||
downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id }
|
downloadManager.deleteChapters(chapters, manga, source).mapNotNull { it.id }
|
||||||
}
|
}
|
||||||
|
|
||||||
val uiModels = state.uiModels
|
|
||||||
val deletedUpdates = uiModels.filter {
|
val deletedUpdates = uiModels.filter {
|
||||||
it is UpdatesUiModel.Item && deletedIds.contains(it.item.update.chapterId)
|
it is UpdatesUiModel.Item && deletedIds.contains(it.item.update.chapterId)
|
||||||
}
|
}
|
||||||
@ -279,16 +277,15 @@ class UpdatesPresenter(
|
|||||||
userSelected: Boolean = false,
|
userSelected: Boolean = false,
|
||||||
fromLongPress: 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 {
|
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 }
|
val firstSelection = none { it is UpdatesUiModel.Item && it.item.selected }
|
||||||
var newItem = (removeAt(modifiedIndex) as? UpdatesUiModel.Item)?.item?.copy(selected = selected) ?: return@apply
|
var newItem = (removeAt(modifiedIndex) as? UpdatesUiModel.Item)?.item?.copy(selected = selected) ?: return@apply
|
||||||
add(modifiedIndex, UpdatesUiModel.Item(newItem))
|
add(modifiedIndex, UpdatesUiModel.Item(newItem))
|
||||||
|
Loading…
Reference in New Issue
Block a user