Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.aatricks.novelscraper.data.local

import androidx.room.*
import io.aatricks.novelscraper.data.model.LibraryItem
import io.aatricks.novelscraper.data.model.ReadingMode
import kotlinx.coroutines.flow.Flow

@Dao
Expand Down Expand Up @@ -42,6 +43,9 @@ interface LibraryDao {
@Query("UPDATE library_items SET hasUpdates = 0 WHERE id = :id")
suspend fun clearUpdatesForId(id: String)

@Query("UPDATE library_items SET readingMode = :readingMode WHERE baseTitle = :baseTitle")
suspend fun updateReadingModeByBaseTitle(baseTitle: String, readingMode: ReadingMode)

@Transaction
suspend fun setCurrentReading(id: String, timestamp: Long = System.currentTimeMillis()) {
clearCurrentlyReading()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ class LibraryRepository @Inject constructor(
suspend fun updateReadingMode(itemId: String, readingMode: ReadingMode): Boolean =
runCatching("Failed to update reading mode", false) {
libraryDao.getItemById(itemId)?.let { item ->
val allItems = libraryDao.getAllItems().firstOrNull() ?: emptyList()
val updatedItems = allItems
.filter { it.baseTitle == item.baseTitle }
.map { it.copy(readingMode = readingMode) }
libraryDao.insertItems(updatedItems)
libraryDao.updateReadingModeByBaseTitle(item.baseTitle, readingMode)
true
} ?: false
} ?: false
Expand Down