diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt index 723fb259be..5ee002a949 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupManager.kt @@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.toMangaInfo +import eu.kanade.tachiyomi.data.library.CustomMangaManager import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.Source @@ -20,6 +21,7 @@ abstract class AbstractBackupManager(protected val context: Context) { internal val sourceManager: SourceManager by injectLazy() internal val trackManager: TrackManager by injectLazy() protected val preferences: PreferencesHelper by injectLazy() + protected val customMangaManager: CustomMangaManager by injectLazy() abstract fun createBackup(uri: Uri, flags: Int, isJob: Boolean): String? diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt index 0706cc3f16..094de8e231 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/AbstractBackupRestore.kt @@ -7,6 +7,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Track +import eu.kanade.tachiyomi.data.library.CustomMangaManager import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.util.chapter.NoChaptersException @@ -22,6 +23,7 @@ abstract class AbstractBackupRestore(protected val co protected val db: DatabaseHelper by injectLazy() protected val trackManager: TrackManager by injectLazy() + protected val customMangaManager: CustomMangaManager by injectLazy() var job: Job? = null diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt index 8d87f40b3c..6b887a04b6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/BackupCreateService.kt @@ -30,7 +30,9 @@ class BackupCreateService : Service() { internal const val BACKUP_HISTORY_MASK = 0x4 internal const val BACKUP_TRACK = 0x8 internal const val BACKUP_TRACK_MASK = 0x8 - internal const val BACKUP_ALL = 0xF + internal const val BACKUP_CUSTOM_INFO = 0x10 + internal const val BACKUP_CUSTOM_INFO_MASK = 0x10 + internal const val BACKUP_ALL = 0x1F /** * Returns the status of the service. diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt index 61a2448579..9d8b897932 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupManager.kt @@ -8,6 +8,8 @@ import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CATE import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CATEGORY_MASK import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CHAPTER import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CHAPTER_MASK +import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CUSTOM_INFO +import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_CUSTOM_INFO_MASK import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_HISTORY import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_HISTORY_MASK import eu.kanade.tachiyomi.data.backup.BackupCreateService.Companion.BACKUP_TRACK @@ -126,7 +128,7 @@ class FullBackupManager(context: Context) : AbstractBackupManager(context) { */ private fun backupMangaObject(manga: Manga, options: Int): BackupManga { // Entry for this manga - val mangaObject = BackupManga.copyFrom(manga) + val mangaObject = BackupManga.copyFrom(manga, if (options and BACKUP_CUSTOM_INFO_MASK == BACKUP_CUSTOM_INFO) customMangaManager else null) // Check if user wants chapter information in backup if (options and BACKUP_CHAPTER_MASK == BACKUP_CHAPTER) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt index 8e0dd54085..b9244e975e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/FullBackupRestore.kt @@ -12,6 +12,8 @@ import eu.kanade.tachiyomi.data.backup.full.models.BackupSerializer import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Track +import eu.kanade.tachiyomi.data.library.CustomMangaManager +import eu.kanade.tachiyomi.data.library.LibraryUpdateService import okio.buffer import okio.gzip import okio.source @@ -64,9 +66,10 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa val categories = backupManga.categories val history = backupManga.history val tracks = backupManga.getTrackingImpl() + val customManga = backupManga.getCustomMangaInfo() try { - restoreMangaData(manga, chapters, categories, history, tracks, backupCategories) + restoreMangaData(manga, chapters, categories, history, tracks, backupCategories, customManga) } catch (e: Exception) { val sourceName = sourceMapping[manga.source] ?: manga.source.toString() errors.add(Date() to "${manga.title} [$sourceName]: ${e.message}") @@ -91,19 +94,20 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa categories: List, history: List, tracks: List, - backupCategories: List + backupCategories: List, + customManga: CustomMangaManager.MangaJson? ) { db.inTransaction { val dbManga = backupManager.getMangaFromDatabase(manga) if (dbManga == null) { // Manga not in database - restoreMangaFetch(manga, chapters, categories, history, tracks, backupCategories) + restoreMangaFetch(manga, chapters, categories, history, tracks, backupCategories, customManga) } else { // Manga in database // Copy information from manga already in database backupManager.restoreMangaNoFetch(manga, dbManga) // Fetch rest of manga information - restoreMangaNoFetch(manga, chapters, categories, history, tracks, backupCategories) + restoreMangaNoFetch(manga, chapters, categories, history, tracks, backupCategories, customManga) } } } @@ -121,15 +125,15 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa categories: List, history: List, tracks: List, - backupCategories: List + backupCategories: List, + customManga: CustomMangaManager.MangaJson? ) { try { val fetchedManga = backupManager.restoreManga(manga) fetchedManga.id ?: return - backupManager.restoreChaptersForManga(fetchedManga, chapters) - restoreExtraForManga(fetchedManga, categories, history, tracks, backupCategories) + restoreExtraForManga(fetchedManga, categories, history, tracks, backupCategories, customManga) } catch (e: Exception) { errors.add(Date() to "${manga.title} - ${e.message}") } @@ -141,14 +145,22 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa categories: List, history: List, tracks: List, - backupCategories: List + backupCategories: List, + customManga: CustomMangaManager.MangaJson? ) { backupManager.restoreChaptersForManga(backupManga, chapters) - restoreExtraForManga(backupManga, categories, history, tracks, backupCategories) + restoreExtraForManga(backupManga, categories, history, tracks, backupCategories, customManga) } - private fun restoreExtraForManga(manga: Manga, categories: List, history: List, tracks: List, backupCategories: List) { + private fun restoreExtraForManga( + manga: Manga, + categories: List, + history: List, + tracks: List, + backupCategories: List, + customManga: CustomMangaManager.MangaJson? + ) { // Restore categories backupManager.restoreCategoriesForManga(manga, categories, backupCategories) @@ -157,5 +169,9 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa // Restore tracking backupManager.restoreTrackForManga(manga, tracks) + + // Restore Custom Info + customManga?.id = manga.id!! + customManga?.let { customMangaManager.saveMangaInfo(it) } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt index 5d433ea783..16b58dc798 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/backup/full/models/BackupManga.kt @@ -4,6 +4,7 @@ import eu.kanade.tachiyomi.data.database.models.ChapterImpl import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaImpl import eu.kanade.tachiyomi.data.database.models.TrackImpl +import eu.kanade.tachiyomi.data.library.CustomMangaManager import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoNumber @@ -34,6 +35,13 @@ data class BackupManga( @ProtoNumber(100) var favorite: Boolean = true, @ProtoNumber(101) var chapterFlags: Int = 0, @ProtoNumber(102) var history: List = emptyList(), + + // J2K specific values + @ProtoNumber(800) var customTitle: String? = null, + @ProtoNumber(801) var customArtist: String? = null, + @ProtoNumber(802) var customAuthor: String? = null, + @ProtoNumber(803) var customDescription: String? = null, + @ProtoNumber(803) var customGenre: List? = null ) { fun getMangaImpl(): MangaImpl { return MangaImpl().apply { @@ -59,6 +67,25 @@ data class BackupManga( } } + fun getCustomMangaInfo(): CustomMangaManager.MangaJson? { + if (customTitle != null || + customArtist != null || + customAuthor != null || + customDescription != null || + customGenre != null + ) { + return CustomMangaManager.MangaJson( + id = 0L, + title = customTitle, + author = customAuthor, + artist = customArtist, + description = customDescription, + genre = customGenre?.toTypedArray() + ) + } + return null + } + fun getTrackingImpl(): List { return tracking.map { it.getTrackingImpl() @@ -66,7 +93,7 @@ data class BackupManga( } companion object { - fun copyFrom(manga: Manga): BackupManga { + fun copyFrom(manga: Manga, customMangaManager: CustomMangaManager?): BackupManga { return BackupManga( url = manga.url, title = manga.originalTitle, @@ -81,7 +108,15 @@ data class BackupManga( dateAdded = manga.date_added, viewer = manga.viewer, chapterFlags = manga.chapter_flags - ) + ).also { backupManga -> + customMangaManager?.getManga(manga)?.let { + backupManga.customTitle = it.title + backupManga.customArtist = it.artist + backupManga.customAuthor = it.author + backupManga.customDescription = it.description + backupManga.customGenre = it.getGenres() + } + } } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/library/CustomMangaManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/library/CustomMangaManager.kt index 743bada22c..5cc2dcfef3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/library/CustomMangaManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/library/CustomMangaManager.kt @@ -94,7 +94,7 @@ class CustomMangaManager(val context: Context) { } data class MangaJson( - val id: Long, + var id: Long, val title: String? = null, val author: String? = null, val artist: String? = null, diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt index 780a69c52a..0723c50ae5 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsBackupController.kt @@ -271,7 +271,8 @@ class SettingsBackupController : SettingsController() { R.string.categories, R.string.chapters, R.string.tracking, - R.string.history + R.string.history, + R.string.custom_manga_info ) .map { activity.getString(it) } @@ -281,7 +282,7 @@ class SettingsBackupController : SettingsController() { .listItemsMultiChoice( items = options, disabledIndices = intArrayOf(0), - initialSelection = intArrayOf(0, 1, 2, 3, 4) + initialSelection = intArrayOf(0, 1, 2, 3, 4, 5) ) { _, positions, _ -> var flags = 0 for (i in 1 until positions.size) { @@ -290,6 +291,7 @@ class SettingsBackupController : SettingsController() { 2 -> flags = flags or BackupCreateService.BACKUP_CHAPTER 3 -> flags = flags or BackupCreateService.BACKUP_TRACK 4 -> flags = flags or BackupCreateService.BACKUP_HISTORY + 5 -> flags = flags or BackupCreateService.BACKUP_CUSTOM_INFO } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9e529f3b9d..65ae385240 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -426,6 +426,7 @@ Cover saved Error saving cover Error sharing cover + Custom manga info A chapter has been removed from the source:\n%2$s\nDelete its download?