Fix applying global color filter (close #1088)

This commit is contained in:
Koitharu
2024-09-06 12:19:59 +03:00
parent b601b07586
commit f09e28e782
3 changed files with 11 additions and 4 deletions

View File

@@ -1,6 +1,8 @@
package org.koitharu.kotatsu.core.db.dao
import androidx.room.*
import androidx.room.Dao
import androidx.room.Query
import androidx.room.Upsert
import kotlinx.coroutines.flow.Flow
import org.koitharu.kotatsu.core.db.entity.MangaPrefsEntity
@@ -13,6 +15,9 @@ abstract class PreferencesDao {
@Query("SELECT * FROM preferences WHERE manga_id = :mangaId")
abstract fun observe(mangaId: Long): Flow<MangaPrefsEntity?>
@Query("UPDATE preferences SET cf_brightness = 0, cf_contrast = 0, cf_invert = 0, cf_grayscale = 0")
abstract suspend fun resetColorFilters()
@Upsert
abstract suspend fun upsert(pref: MangaPrefsEntity)
}

View File

@@ -52,6 +52,10 @@ class MangaDataRepository @Inject constructor(
}
}
suspend fun resetColorFilters() {
db.getPreferencesDao().resetColorFilters()
}
suspend fun getReaderMode(mangaId: Long): ReaderMode? {
return db.getPreferencesDao().find(mangaId)?.let { ReaderMode.valueOf(it.mode) }
}

View File

@@ -73,9 +73,7 @@ class ColorFilterConfigViewModel @Inject constructor(
fun saveGlobally() {
launchLoadingJob(Dispatchers.Default) {
settings.readerColorFilter = colorFilter.value
if (mangaDataRepository.getColorFilter(manga.id) != null) {
mangaDataRepository.saveColorFilter(manga, colorFilter.value)
}
mangaDataRepository.resetColorFilters()
onDismiss.call(Unit)
}
}