mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-14 13:08:56 +01:00
More refactoring of expected next update logic
This commit is contained in:
@@ -83,13 +83,6 @@ class MangaScreen(
|
||||
|
||||
val successState = state as MangaScreenModel.State.Success
|
||||
val isHttpSource = remember { successState.source is HttpSource }
|
||||
val fetchInterval = remember(successState.manga.fetchInterval) {
|
||||
FetchInterval(
|
||||
interval = successState.manga.fetchInterval,
|
||||
leadDays = screenModel.leadDay,
|
||||
followDays = screenModel.followDay,
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(successState.manga, screenModel.source) {
|
||||
if (isHttpSource) {
|
||||
@@ -107,7 +100,7 @@ class MangaScreen(
|
||||
state = successState,
|
||||
snackbarHostState = screenModel.snackbarHostState,
|
||||
dateFormat = screenModel.dateFormat,
|
||||
fetchInterval = fetchInterval,
|
||||
fetchInterval = successState.manga.fetchInterval,
|
||||
isTabletUi = isTabletUi(),
|
||||
chapterSwipeStartAction = screenModel.chapterSwipeStartAction,
|
||||
chapterSwipeEndAction = screenModel.chapterSwipeEndAction,
|
||||
@@ -218,7 +211,7 @@ class MangaScreen(
|
||||
}
|
||||
is MangaScreenModel.Dialog.SetFetchInterval -> {
|
||||
SetIntervalDialog(
|
||||
interval = if (dialog.manga.fetchInterval < 0) -dialog.manga.fetchInterval else 0,
|
||||
interval = dialog.manga.fetchInterval,
|
||||
onDismissRequest = onDismissRequest,
|
||||
onValueChanged = { screenModel.setFetchInterval(dialog.manga, it) },
|
||||
)
|
||||
|
||||
@@ -129,8 +129,6 @@ class MangaScreenModel(
|
||||
private val skipFiltered by readerPreferences.skipFiltered().asState(coroutineScope)
|
||||
|
||||
val isUpdateIntervalEnabled = LibraryPreferences.MANGA_OUTSIDE_RELEASE_PERIOD in libraryPreferences.libraryUpdateMangaRestriction().get()
|
||||
val leadDay = libraryPreferences.leadingExpectedDays().get()
|
||||
val followDay = libraryPreferences.followingExpectedDays().get()
|
||||
|
||||
private val selectedPositions: Array<Int> = arrayOf(-1, -1) // first and last selected index in list
|
||||
private val selectedChapterIds: HashSet<Long> = HashSet()
|
||||
@@ -361,20 +359,14 @@ class MangaScreenModel(
|
||||
}
|
||||
}
|
||||
|
||||
fun setFetchInterval(manga: Manga, newInterval: Int) {
|
||||
val interval = when (newInterval) {
|
||||
// reset interval 0 default to trigger recalculation
|
||||
// only reset if interval is custom, which is negative
|
||||
0 -> if (manga.fetchInterval < 0) 0 else manga.fetchInterval
|
||||
else -> -newInterval
|
||||
}
|
||||
fun setFetchInterval(manga: Manga, interval: Int) {
|
||||
coroutineScope.launchIO {
|
||||
updateManga.awaitUpdateFetchInterval(
|
||||
manga.copy(fetchInterval = interval),
|
||||
successState?.chapters?.map { it.chapter }.orEmpty(),
|
||||
// Custom intervals are negative
|
||||
manga.copy(fetchInterval = -interval),
|
||||
)
|
||||
val newManga = mangaRepository.getMangaById(mangaId)
|
||||
updateSuccessState { it.copy(manga = newManga) }
|
||||
val updatedManga = mangaRepository.getMangaById(manga.id)
|
||||
updateSuccessState { it.copy(manga = updatedManga) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1055,10 +1047,3 @@ data class ChapterItem(
|
||||
) {
|
||||
val isDownloaded = downloadState == Download.State.DOWNLOADED
|
||||
}
|
||||
|
||||
@Immutable
|
||||
data class FetchInterval(
|
||||
val interval: Int,
|
||||
val leadDays: Int,
|
||||
val followDays: Int,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user