Skip to content

Commit

Permalink
Add option to backup non-library read entries (#1324)
Browse files Browse the repository at this point in the history
Co-authored-by: jobobby04 <[email protected]>
Co-authored-by: AntsyLich <[email protected]>
  • Loading branch information
3 people authored Oct 14, 2024
1 parent eb6092b commit de36357
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down Expand Up @@ -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),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -22,6 +23,7 @@ data class BackupOptions(
chapters,
tracking,
history,
readEntries,
appSettings,
extensionRepoSettings,
sourceSettings,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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],
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ class MangaRepositoryImpl(
return handler.awaitList { mangasQueries.getFavorites(MangaMapper::mapManga) }
}

override suspend fun getReadMangaNotInLibrary(): List<Manga> {
return handler.awaitList { mangasQueries.getReadMangaNotInLibrary(MangaMapper::mapManga) }
}

override suspend fun getLibraryManga(): List<LibraryManga> {
return handler.awaitList { libraryViewQueries.library(MangaMapper::mapLibraryManga) }
}
Expand Down
9 changes: 9 additions & 0 deletions data/src/main/sqldelight/tachiyomi/data/mangas.sq
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface MangaRepository {

suspend fun getFavorites(): List<Manga>

suspend fun getReadMangaNotInLibrary(): List<Manga>

suspend fun getLibraryManga(): List<LibraryManga>

fun getLibraryMangaAsFlow(): Flow<List<LibraryManga>>
Expand Down
1 change: 1 addition & 0 deletions i18n/src/commonMain/moko-resources/base/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,7 @@
<string name="source_settings">Source settings</string>
<string name="extensionRepo_settings">Extension repos</string>
<string name="private_settings">Include sensitive settings (e.g., tracker login tokens)</string>
<string name="non_library_settings">All read entries</string>
<string name="creating_backup">Creating backup</string>
<string name="creating_backup_error">Backup failed</string>
<string name="missing_storage_permission">Storage permissions not granted</string>
Expand Down

0 comments on commit de36357

Please sign in to comment.