From 9e3aaab95fa9d85e656c19a123d2fece3127de3d Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Wed, 14 Apr 2021 16:18:58 -0400 Subject: [PATCH] Edit Manga Status (for Local and online Mostly the same, except custom status can be null so it's not automatically added to the edits.json Since SY implemented first I'm using the same key for backups, I would've liked if customStatus was nullable but it is what it is Closes #704 Co-Authored-By: jobobby04 <17078382+jobobby04@users.noreply.github.com> --- .../data/backup/full/FullBackupRestore.kt | 2 +- .../data/backup/full/models/BackupManga.kt | 14 ++++++++++---- .../data/database/mappers/MangaTypeMapping.kt | 2 +- .../tachiyomi/data/database/models/MangaImpl.kt | 6 +++++- .../database/resolvers/MangaInfoPutResolver.kt | 1 + .../tachiyomi/data/library/CustomMangaManager.kt | 11 ++++++++--- .../java/eu/kanade/tachiyomi/source/LocalSource.kt | 5 +++-- .../eu/kanade/tachiyomi/source/model/SManga.kt | 4 +++- .../kanade/tachiyomi/ui/manga/EditMangaDialog.kt | 8 ++++++-- .../tachiyomi/ui/manga/MangaDetailsPresenter.kt | 7 +++++-- app/src/main/res/layout/edit_manga_dialog.xml | 12 +++++++++++- app/src/main/res/values/arrays.xml | 7 +++++++ 12 files changed, 61 insertions(+), 18 deletions(-) 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 98bf2f6a69..8528f5f6af 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 @@ -66,7 +66,7 @@ class FullBackupRestore(context: Context, notifier: BackupNotifier) : AbstractBa val categories = backupManga.categories val history = backupManga.history val tracks = backupManga.getTrackingImpl() - val customManga = backupManga.getCustomMangaInfo() + val customManga = backupManga.getCustomMangaInfo(manga) try { restoreMangaData(manga, chapters, categories, history, tracks, backupCategories, customManga) 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 16b58dc798..3005868022 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 @@ -36,6 +36,9 @@ data class BackupManga( @ProtoNumber(101) var chapterFlags: Int = 0, @ProtoNumber(102) var history: List = emptyList(), + // SY specific values + @ProtoNumber(602) var customStatus: Int = 0, + // J2K specific values @ProtoNumber(800) var customTitle: String? = null, @ProtoNumber(801) var customArtist: String? = null, @@ -67,12 +70,13 @@ data class BackupManga( } } - fun getCustomMangaInfo(): CustomMangaManager.MangaJson? { + fun getCustomMangaInfo(manga: Manga): CustomMangaManager.MangaJson? { if (customTitle != null || customArtist != null || customAuthor != null || customDescription != null || - customGenre != null + customGenre != null || + manga.status != customStatus ) { return CustomMangaManager.MangaJson( id = 0L, @@ -80,7 +84,8 @@ data class BackupManga( author = customAuthor, artist = customArtist, description = customDescription, - genre = customGenre?.toTypedArray() + genre = customGenre?.toTypedArray(), + status = if (manga.status != customStatus) customStatus else null ) } return null @@ -101,7 +106,7 @@ data class BackupManga( author = manga.originalAuthor, description = manga.originalDescription, genre = manga.getOriginalGenres() ?: emptyList(), - status = manga.status, + status = manga.originalStatus, thumbnailUrl = manga.thumbnail_url, favorite = manga.favorite, source = manga.source, @@ -115,6 +120,7 @@ data class BackupManga( backupManga.customAuthor = it.author backupManga.customDescription = it.description backupManga.customGenre = it.getGenres() + backupManga.customStatus = it.status } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt index 90b78c9014..189dab7676 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/mappers/MangaTypeMapping.kt @@ -57,7 +57,7 @@ class MangaPutResolver : DefaultPutResolver() { put(COL_DESCRIPTION, obj.originalDescription) put(COL_GENRE, obj.originalGenre) put(COL_TITLE, obj.originalTitle) - put(COL_STATUS, obj.status) + put(COL_STATUS, obj.originalStatus) put(COL_THUMBNAIL_URL, obj.thumbnail_url) put(COL_FAVORITE, obj.favorite) put(COL_LAST_UPDATE, obj.last_update) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index 4372faa32e..42ddc257e8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -43,7 +43,9 @@ open class MangaImpl : Manga { get() = if (favorite) customMangaManager.getManga(this)?.genre ?: ogGenre else ogGenre set(value) { ogGenre = value } - override var status: Int = 0 + override var status: Int + get() = if (favorite) customMangaManager.getManga(this)?.status ?: ogStatus else ogStatus + set(value) { ogStatus = value } override var thumbnail_url: String? = null @@ -71,6 +73,8 @@ open class MangaImpl : Manga { private set var ogGenre: String? = null private set + var ogStatus: Int = 0 + private set override fun copyFrom(other: SManga) { if (other is MangaImpl && other::ogTitle.isInitialized && diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaInfoPutResolver.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaInfoPutResolver.kt index 140069fb05..82719f95fb 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaInfoPutResolver.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/resolvers/MangaInfoPutResolver.kt @@ -31,5 +31,6 @@ class MangaInfoPutResolver() : PutResolver() { put(MangaTable.COL_AUTHOR, manga.originalAuthor) put(MangaTable.COL_ARTIST, manga.originalArtist) put(MangaTable.COL_DESCRIPTION, manga.originalDescription) + put(MangaTable.COL_STATUS, manga.originalStatus) } } 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 5cc2dcfef3..53824c4d1c 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 @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.data.library import android.content.Context +import com.github.salomonbrys.kotson.nullInt import com.github.salomonbrys.kotson.nullLong import com.github.salomonbrys.kotson.nullString import com.github.salomonbrys.kotson.set @@ -48,13 +49,14 @@ class CustomMangaManager(val context: Context) { description = mangaObject["description"]?.nullString genre = mangaObject["genre"]?.asJsonArray?.mapNotNull { it.nullString } ?.joinToString(", ") + status = mangaObject["status"]?.nullInt ?: 0 } id to manga }.toMap().toMutableMap() } fun saveMangaInfo(manga: MangaJson) { - if (manga.title == null && manga.author == null && manga.artist == null && manga.description == null && manga.genre == null) { + if (manga.title == null && manga.author == null && manga.artist == null && manga.description == null && manga.genre == null && manga.status == null) { customMangaMap.remove(manga.id) } else { customMangaMap[manga.id] = MangaImpl().apply { @@ -64,6 +66,7 @@ class CustomMangaManager(val context: Context) { artist = manga.artist description = manga.description genre = manga.genre?.joinToString(", ") + status = manga.status ?: -1 } } saveCustomInfo() @@ -89,7 +92,8 @@ class CustomMangaManager(val context: Context) { author, artist, description, - genre?.split(", ")?.toTypedArray() + genre?.split(", ")?.toTypedArray(), + status.takeUnless { it == -1 } ) } @@ -99,7 +103,8 @@ class CustomMangaManager(val context: Context) { val author: String? = null, val artist: String? = null, val description: String? = null, - val genre: Array? = null + val genre: Array? = null, + val status: Int? = null ) { override fun equals(other: Any?): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt index 2b2bc29890..21f9f9d369 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/LocalSource.kt @@ -200,7 +200,7 @@ class LocalSource(private val context: Context) : CatalogueSource { } fun SManga.toJson(): MangaJson { - return MangaJson(title, author, artist, description, genre?.split(", ")?.toTypedArray()) + return MangaJson(title, author, artist, description, genre?.split(", ")?.toTypedArray(), status) } data class MangaJson( @@ -208,7 +208,8 @@ class LocalSource(private val context: Context) : CatalogueSource { val author: String?, val artist: String?, val description: String?, - val genre: Array? + val genre: Array?, + val status: Int?, ) { override fun equals(other: Any?): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt index 9805b13771..d8e747c37d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/source/model/SManga.kt @@ -34,6 +34,8 @@ interface SManga : Serializable { get() = (this as? MangaImpl)?.ogDesc ?: description val originalGenre: String? get() = (this as? MangaImpl)?.ogGenre ?: genre + val originalStatus: Int + get() = (this as? MangaImpl)?.ogStatus ?: status fun copyFrom(other: SManga) { if (other.author != null) { @@ -56,7 +58,7 @@ interface SManga : Serializable { thumbnail_url = other.thumbnail_url } - status = other.status + status = other.originalStatus if (!initialized) { initialized = other.initialized diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt index 9ec8a51cd3..f06e94698a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/EditMangaDialog.kt @@ -14,7 +14,9 @@ import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.image.coil.MangaFetcher import eu.kanade.tachiyomi.databinding.EditMangaDialogBinding import eu.kanade.tachiyomi.source.LocalSource +import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.ui.base.controller.DialogController +import eu.kanade.tachiyomi.util.isLocal import eu.kanade.tachiyomi.util.lang.chop import eu.kanade.tachiyomi.util.view.visibleIf import uy.kohesive.injekt.Injekt @@ -66,7 +68,7 @@ class EditMangaDialog : DialogController { fun onViewCreated() { binding.mangaCover.loadAny(manga) - val isLocal = manga.source == LocalSource.ID + val isLocal = manga.isLocal() if (isLocal) { if (manga.title != manga.url) { @@ -107,13 +109,14 @@ class EditMangaDialog : DialogController { )?.chop(20)}" } } + binding.mangaStatus.setSelection(manga.status.coerceIn(SManga.UNKNOWN, SManga.LICENSED)) binding.mangaGenresTags.clearFocus() binding.coverLayout.setOnClickListener { infoController.changeCover() } binding.resetTags.setOnClickListener { resetTags() } binding.resetTags.text = resources?.getString( - if (manga.genre.isNullOrBlank() || manga.source == LocalSource.ID) { + if (manga.originalGenre.isNullOrBlank() || isLocal) { R.string.clear_tags } else { R.string.reset_tags @@ -152,6 +155,7 @@ class EditMangaDialog : DialogController { customCoverUri, binding.mangaDescription.text.toString(), binding.mangaGenresTags.tags, + binding.mangaStatus.selectedPosition, willResetCover ) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt index 10d7562ab7..d66d0b14dc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaDetailsPresenter.kt @@ -30,6 +30,7 @@ import eu.kanade.tachiyomi.data.track.TrackManager import eu.kanade.tachiyomi.data.track.TrackService import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.toSChapter import eu.kanade.tachiyomi.source.model.toSManga import eu.kanade.tachiyomi.ui.manga.chapter.ChapterItem @@ -573,7 +574,6 @@ class MangaDetailsPresenter( fun confirmDeletion() { coverCache.deleteFromCache(manga) - db.resetMangaInfo(manga).executeAsBlocking() downloadManager.deleteManga(manga, source) customMangaManager.saveMangaInfo(CustomMangaManager.MangaJson(manga.id!!)) asyncUpdateMangaAndChapters(true) @@ -629,6 +629,7 @@ class MangaDetailsPresenter( uri: Uri?, description: String?, tags: Array?, + status: Int?, resetCover: Boolean = false ) { if (manga.source == LocalSource.ID) { @@ -638,6 +639,7 @@ class MangaDetailsPresenter( manga.description = description?.trimOrNull() val tagsString = tags?.joinToString(", ") { it.capitalize() } manga.genre = if (tags.isNullOrEmpty()) null else tagsString?.trim() + manga.status = status ?: SManga.UNKNOWN LocalSource(downloadManager.context).updateMangaInfo(manga) db.updateMangaInfo(manga).executeAsBlocking() } else { @@ -652,7 +654,8 @@ class MangaDetailsPresenter( author?.trimOrNull(), artist?.trimOrNull(), description?.trimOrNull(), - genre + genre, + if (status != this.manga.originalStatus) status else null ) customMangaManager.saveMangaInfo(manga) } diff --git a/app/src/main/res/layout/edit_manga_dialog.xml b/app/src/main/res/layout/edit_manga_dialog.xml index bedcac0ed0..7b721b98a5 100644 --- a/app/src/main/res/layout/edit_manga_dialog.xml +++ b/app/src/main/res/layout/edit_manga_dialog.xml @@ -35,6 +35,16 @@ android:layout_marginStart="16dp" android:text="@string/reset_cover" /> + + @string/smart_fit + + @string/unknown_status + @string/ongoing + @string/completed + @string/licensed + + @string/webtoon_side_padding_0 @string/webtoon_side_padding_10