From de36357da834bff4110dbb56dd7ce7aad04d3c7d Mon Sep 17 00:00:00 2001 From: Roshan Varughese <40583749+Animeboynz@users.noreply.github.com> Date: Tue, 15 Oct 2024 05:30:23 +1300 Subject: [PATCH] Add option to backup non-library read entries (#1324) Co-authored-by: jobobby04 Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --- .../data/backup/create/BackupCreator.kt | 6 +++++- .../data/backup/create/BackupOptions.kt | 17 +++++++++++++---- .../tachiyomi/data/manga/MangaRepositoryImpl.kt | 4 ++++ .../main/sqldelight/tachiyomi/data/mangas.sq | 9 +++++++++ .../domain/manga/repository/MangaRepository.kt | 2 ++ .../commonMain/moko-resources/base/strings.xml | 1 + 6 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt index fa06f55bb9..d6851a7586 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupCreator.kt @@ -27,6 +27,7 @@ import tachiyomi.core.common.util.system.logcat import tachiyomi.domain.backup.service.BackupPreferences import tachiyomi.domain.manga.interactor.GetFavorites import tachiyomi.domain.manga.model.Manga +import tachiyomi.domain.manga.repository.MangaRepository import tachiyomi.i18n.MR import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -43,6 +44,7 @@ class BackupCreator( private val parser: ProtoBuf = Injekt.get(), private val getFavorites: GetFavorites = Injekt.get(), private val backupPreferences: BackupPreferences = Injekt.get(), + private val mangaRepository: MangaRepository = Injekt.get(), private val categoriesBackupCreator: CategoriesBackupCreator = CategoriesBackupCreator(), private val mangaBackupCreator: MangaBackupCreator = MangaBackupCreator(), @@ -75,7 +77,9 @@ class BackupCreator( throw IllegalStateException(context.stringResource(MR.strings.create_backup_file_error)) } - val backupManga = backupMangas(getFavorites.await(), options) + val nonFavoriteManga = if (options.readEntries) mangaRepository.getReadMangaNotInLibrary() else emptyList() + val backupManga = backupMangas(getFavorites.await() + nonFavoriteManga, options) + val backup = Backup( backupManga = backupManga, backupCategories = backupCategories(options), diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt index daaecff8ec..efb20f6bff 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/create/BackupOptions.kt @@ -10,6 +10,7 @@ data class BackupOptions( val chapters: Boolean = true, val tracking: Boolean = true, val history: Boolean = true, + val readEntries: Boolean = true, val appSettings: Boolean = true, val extensionRepoSettings: Boolean = true, val sourceSettings: Boolean = true, @@ -22,6 +23,7 @@ data class BackupOptions( chapters, tracking, history, + readEntries, appSettings, extensionRepoSettings, sourceSettings, @@ -60,6 +62,12 @@ data class BackupOptions( getter = BackupOptions::categories, setter = { options, enabled -> options.copy(categories = enabled) }, ), + Entry( + label = MR.strings.non_library_settings, + getter = BackupOptions::readEntries, + setter = { options, enabled -> options.copy(readEntries = enabled) }, + enabled = { it.libraryEntries }, + ), ) val settingsOptions = persistentListOf( @@ -92,10 +100,11 @@ data class BackupOptions( chapters = array[2], tracking = array[3], history = array[4], - appSettings = array[5], - extensionRepoSettings = array[6], - sourceSettings = array[7], - privateSettings = array[8], + readEntries = array[5], + appSettings = array[6], + extensionRepoSettings = array[7], + sourceSettings = array[8], + privateSettings = array[9], ) } diff --git a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt index f7aaf4c997..ae6c8d3409 100644 --- a/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt +++ b/data/src/main/java/tachiyomi/data/manga/MangaRepositoryImpl.kt @@ -49,6 +49,10 @@ class MangaRepositoryImpl( return handler.awaitList { mangasQueries.getFavorites(MangaMapper::mapManga) } } + override suspend fun getReadMangaNotInLibrary(): List { + return handler.awaitList { mangasQueries.getReadMangaNotInLibrary(MangaMapper::mapManga) } + } + override suspend fun getLibraryManga(): List { return handler.awaitList { libraryViewQueries.library(MangaMapper::mapLibraryManga) } } diff --git a/data/src/main/sqldelight/tachiyomi/data/mangas.sq b/data/src/main/sqldelight/tachiyomi/data/mangas.sq index 3e21e5bc00..e3cb8076a1 100644 --- a/data/src/main/sqldelight/tachiyomi/data/mangas.sq +++ b/data/src/main/sqldelight/tachiyomi/data/mangas.sq @@ -78,6 +78,15 @@ SELECT * FROM mangas WHERE favorite = 1; +getReadMangaNotInLibrary: +SELECT * +FROM mangas +WHERE favorite = 0 AND _id IN ( + SELECT DISTINCT chapters.manga_id + FROM chapters + WHERE read = 1 OR last_page_read != 0 +); + getAllManga: SELECT * FROM mangas; diff --git a/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt b/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt index 8c74851f3e..f81650102c 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/repository/MangaRepository.kt @@ -17,6 +17,8 @@ interface MangaRepository { suspend fun getFavorites(): List + suspend fun getReadMangaNotInLibrary(): List + suspend fun getLibraryManga(): List fun getLibraryMangaAsFlow(): Flow> diff --git a/i18n/src/commonMain/moko-resources/base/strings.xml b/i18n/src/commonMain/moko-resources/base/strings.xml index f9e4d1ed69..f61df609c0 100644 --- a/i18n/src/commonMain/moko-resources/base/strings.xml +++ b/i18n/src/commonMain/moko-resources/base/strings.xml @@ -546,6 +546,7 @@ Source settings Extension repos Include sensitive settings (e.g., tracker login tokens) + All read entries Creating backup Backup failed Storage permissions not granted