Update Voyager

This commit is contained in:
arkon
2023-10-22 15:54:31 -04:00
parent 6d1e520c6c
commit 012854dd1e
25 changed files with 136 additions and 137 deletions
@@ -7,7 +7,7 @@ import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import cafe.adriel.voyager.core.model.StateScreenModel
import cafe.adriel.voyager.core.model.coroutineScope
import cafe.adriel.voyager.core.model.screenModelScope
import eu.kanade.core.preference.asState
import eu.kanade.core.util.addOrRemove
import eu.kanade.core.util.insertSeparators
@@ -65,15 +65,15 @@ class UpdatesScreenModel(
private val _events: Channel<Event> = Channel(Int.MAX_VALUE)
val events: Flow<Event> = _events.receiveAsFlow()
val lastUpdated by libraryPreferences.lastUpdatedTimestamp().asState(coroutineScope)
val relativeTime by uiPreferences.relativeTime().asState(coroutineScope)
val lastUpdated by libraryPreferences.lastUpdatedTimestamp().asState(screenModelScope)
val relativeTime by uiPreferences.relativeTime().asState(screenModelScope)
// First and last selected index in list
private val selectedPositions: Array<Int> = arrayOf(-1, -1)
private val selectedChapterIds: HashSet<Long> = HashSet()
init {
coroutineScope.launchIO {
screenModelScope.launchIO {
// Set date limit for recent chapters
val calendar = Calendar.getInstance().apply {
time = Date()
@@ -99,7 +99,7 @@ class UpdatesScreenModel(
}
}
coroutineScope.launchIO {
screenModelScope.launchIO {
merge(downloadManager.statusFlow(), downloadManager.progressFlow())
.catch { logcat(LogPriority.ERROR, it) }
.collect(this@UpdatesScreenModel::updateDownloadState)
@@ -131,7 +131,7 @@ class UpdatesScreenModel(
fun updateLibrary(): Boolean {
val started = LibraryUpdateJob.startNow(Injekt.get<Application>())
coroutineScope.launch {
screenModelScope.launch {
_events.send(Event.LibraryUpdateTriggered(started))
}
return started
@@ -163,7 +163,7 @@ class UpdatesScreenModel(
fun downloadChapters(items: List<UpdatesItem>, action: ChapterDownloadAction) {
if (items.isEmpty()) return
coroutineScope.launch {
screenModelScope.launch {
when (action) {
ChapterDownloadAction.START -> {
downloadChapters(items)
@@ -203,7 +203,7 @@ class UpdatesScreenModel(
* @param read whether to mark chapters as read or unread.
*/
fun markUpdatesRead(updates: List<UpdatesItem>, read: Boolean) {
coroutineScope.launchIO {
screenModelScope.launchIO {
setReadStatus.await(
read = read,
chapters = updates
@@ -219,7 +219,7 @@ class UpdatesScreenModel(
* @param updates the list of chapters to bookmark.
*/
fun bookmarkUpdates(updates: List<UpdatesItem>, bookmark: Boolean) {
coroutineScope.launchIO {
screenModelScope.launchIO {
updates
.filterNot { it.update.bookmark == bookmark }
.map { ChapterUpdate(id = it.update.chapterId, bookmark = bookmark) }
@@ -233,7 +233,7 @@ class UpdatesScreenModel(
* @param updatesItem the list of chapters to download.
*/
private fun downloadChapters(updatesItem: List<UpdatesItem>) {
coroutineScope.launchNonCancellable {
screenModelScope.launchNonCancellable {
val groupedUpdates = updatesItem.groupBy { it.update.mangaId }.values
for (updates in groupedUpdates) {
val mangaId = updates.first().update.mangaId
@@ -252,7 +252,7 @@ class UpdatesScreenModel(
* @param updatesItem list of chapters
*/
fun deleteChapters(updatesItem: List<UpdatesItem>) {
coroutineScope.launchNonCancellable {
screenModelScope.launchNonCancellable {
updatesItem
.groupBy { it.update.mangaId }
.entries