Replace custom download amount with next 25

Simplifies things and maybe discourages whacky downloading behavior?
Users can still range select in the chapters list to download custom amounts.
This commit is contained in:
arkon
2023-02-12 15:25:09 -05:00
parent 5ce64ac7ff
commit f6e6a7ddf1
8 changed files with 29 additions and 202 deletions
@@ -32,7 +32,6 @@ import eu.kanade.presentation.manga.ChapterSettingsDialog
import eu.kanade.presentation.manga.EditCoverAction
import eu.kanade.presentation.manga.MangaScreen
import eu.kanade.presentation.manga.components.DeleteChaptersDialog
import eu.kanade.presentation.manga.components.DownloadCustomAmountDialog
import eu.kanade.presentation.manga.components.MangaCoverDialog
import eu.kanade.presentation.util.AssistContentScreen
import eu.kanade.presentation.util.isTabletUi
@@ -156,18 +155,6 @@ class MangaScreen(
},
)
}
is MangaInfoScreenModel.Dialog.DownloadCustomAmount -> {
DownloadCustomAmountDialog(
maxAmount = dialog.max,
onDismissRequest = onDismissRequest,
onConfirm = { amount ->
val chaptersToDownload = screenModel.getUnreadChaptersSorted().take(amount)
if (chaptersToDownload.isNotEmpty()) {
screenModel.startDownload(chapters = chaptersToDownload, startNow = false)
}
},
)
}
is MangaInfoScreenModel.Dialog.DuplicateManga -> DuplicateMangaDialog(
onDismissRequest = onDismissRequest,
onConfirm = { screenModel.toggleFavorite(onRemoved = {}, checkDuplicate = false) },
@@ -83,8 +83,8 @@ class MangaInfoScreenModel(
private val isFromSource: Boolean,
private val downloadPreferences: DownloadPreferences = Injekt.get(),
private val libraryPreferences: LibraryPreferences = Injekt.get(),
private val readerPreferences: ReaderPreferences = Injekt.get(),
private val uiPreferences: UiPreferences = Injekt.get(),
readerPreferences: ReaderPreferences = Injekt.get(),
uiPreferences: UiPreferences = Injekt.get(),
private val trackManager: TrackManager = Injekt.get(),
private val downloadManager: DownloadManager = Injekt.get(),
private val downloadCache: DownloadCache = Injekt.get(),
@@ -123,8 +123,8 @@ class MangaInfoScreenModel(
get() = successState?.processedChapters
val relativeTime by uiPreferences.relativeTime().asState(coroutineScope)
val skipFiltered by readerPreferences.skipFiltered().asState(coroutineScope)
val dateFormat by mutableStateOf(UiPreferences.dateFormat(uiPreferences.dateFormat().get()))
private val skipFiltered by readerPreferences.skipFiltered().asState(coroutineScope)
private val selectedPositions: Array<Int> = arrayOf(-1, -1) // first and last selected index in list
private val selectedChapterIds: HashSet<Long> = HashSet()
@@ -354,7 +354,7 @@ class MangaInfoScreenModel(
/**
* Returns true if the manga has any downloads.
*/
fun hasDownloads(): Boolean {
private fun hasDownloads(): Boolean {
val manga = successState?.manga ?: return false
return downloadManager.getDownloadCount(manga) > 0
}
@@ -527,7 +527,7 @@ class MangaInfoScreenModel(
/**
* Returns the list of filtered or all chapter items if [skipFiltered] is false.
*/
fun getChapterItems(): List<ChapterItem> {
private fun getChapterItems(): List<ChapterItem> {
return if (skipFiltered) filteredChapters.orEmpty().toList() else allChapters.orEmpty()
}
@@ -539,19 +539,19 @@ class MangaInfoScreenModel(
return successState.chapters.getNextUnread(successState.manga)
}
fun getUnreadChapters(): List<Chapter> {
private fun getUnreadChapters(): List<Chapter> {
return getChapterItems()
.filter { (chapter, dlStatus) -> !chapter.read && dlStatus == Download.State.NOT_DOWNLOADED }
.map { it.chapter }
}
fun getUnreadChaptersSorted(): List<Chapter> {
private fun getUnreadChaptersSorted(): List<Chapter> {
val manga = successState?.manga ?: return emptyList()
val chaptersSorted = getUnreadChapters().sortedWith(getChapterSort(manga))
return if (manga.sortDescending()) chaptersSorted.reversed() else chaptersSorted
}
fun startDownload(
private fun startDownload(
chapters: List<Chapter>,
startNow: Boolean,
) {
@@ -611,19 +611,16 @@ class MangaInfoScreenModel(
DownloadAction.NEXT_1_CHAPTER -> getUnreadChaptersSorted().take(1)
DownloadAction.NEXT_5_CHAPTERS -> getUnreadChaptersSorted().take(5)
DownloadAction.NEXT_10_CHAPTERS -> getUnreadChaptersSorted().take(10)
DownloadAction.CUSTOM -> {
showDownloadCustomDialog()
return
}
DownloadAction.NEXT_25_CHAPTERS -> getUnreadChaptersSorted().take(25)
DownloadAction.UNREAD_CHAPTERS -> getUnreadChapters()
DownloadAction.ALL_CHAPTERS -> getChapterItems().map { it.chapter }
}
if (!chaptersToDownload.isNullOrEmpty()) {
if (chaptersToDownload.isNotEmpty()) {
startDownload(chaptersToDownload, false)
}
}
fun cancelDownload(chapterId: Long) {
private fun cancelDownload(chapterId: Long) {
val activeDownload = downloadManager.getQueuedDownloadOrNull(chapterId) ?: return
downloadManager.cancelQueuedDownloads(listOf(activeDownload))
updateDownloadState(activeDownload.apply { status = Download.State.NOT_DOWNLOADED })
@@ -913,7 +910,6 @@ class MangaInfoScreenModel(
data class ChangeCategory(val manga: Manga, val initialSelection: List<CheckboxState<Category>>) : Dialog()
data class DeleteChapters(val chapters: List<Chapter>) : Dialog()
data class DuplicateManga(val manga: Manga, val duplicate: Manga) : Dialog()
data class DownloadCustomAmount(val max: Int) : Dialog()
object SettingsSheet : Dialog()
object TrackSheet : Dialog()
object FullCover : Dialog()
@@ -928,16 +924,6 @@ class MangaInfoScreenModel(
}
}
private fun showDownloadCustomDialog() {
val max = getChapterItems().count()
mutableState.update { state ->
when (state) {
MangaScreenState.Loading -> state
is MangaScreenState.Success -> state.copy(dialog = Dialog.DownloadCustomAmount(max))
}
}
}
fun showDeleteChapterDialog(chapters: List<Chapter>) {
mutableState.update { state ->
when (state) {