From bf919e7949fc28557e38b582073dd39db7ea42cb Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 20 Jan 2020 12:34:20 -0800 Subject: [PATCH] Fixes for local manga and others for custom manga info --- .../kanade/tachiyomi/source/model/SManga.kt | 44 ++++++------------- .../ui/manga/info/EditMangaDialog.kt | 4 +- .../ui/manga/info/MangaInfoController.kt | 1 + .../ui/manga/info/MangaInfoPresenter.kt | 13 +++--- app/src/main/res/layout/edit_manga_dialog.xml | 21 ++++----- 5 files changed, 35 insertions(+), 48 deletions(-) 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 7630040de9..568619511d 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 @@ -32,44 +32,26 @@ interface SManga : Serializable { return splitTitle.last() } - fun currentGenres(): String? { - val splitGenre = genre?.split(splitter) ?: return null - return splitGenre.first() - } + fun currentGenres() = split(genre, true) - fun originalGenres(): String? { - val splitGenre = genre?.split(splitter) ?: return null - return splitGenre.last() - } + fun originalGenres() = split(genre, false) - fun currentDesc(): String? { - val splitDesc = description?.split(splitter) ?: return null - return splitDesc.first() - } + fun currentDesc() = split(description, true) - fun originalDesc(): String? { - val splitDesc = description?.split(splitter) ?: return null - return splitDesc.last() - } + fun originalDesc() = split(description, false) - fun currentAuthor(): String? { - val splitAuth = author?.split(splitter) ?: return null - return splitAuth.first() - } + fun currentAuthor() = split(author, true) - fun originalAuthor(): String? { - val splitAuth = author?.split(splitter) ?: return null - return splitAuth.last() - } + fun originalAuthor() = split(author, false) - fun currentArtist(): String? { - val splitArtist = artist?.split(splitter) ?: return null - return splitArtist.first() - } + fun currentArtist() = split(artist, true) - fun originalArtist(): String? { - val splitArtist = artist?.split(splitter) ?: return null - return splitArtist.last() + fun originalArtist() = split(artist, false) + + private fun split(string: String?, first: Boolean):String? { + val split = string?.split(splitter) ?: return null + val s = if (first) split.first() else split.last() + return if (s.isBlank()) null else s } fun copyFrom(other: SManga) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/EditMangaDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/EditMangaDialog.kt index bb58f6375f..264f7d0226 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/EditMangaDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/EditMangaDialog.kt @@ -102,7 +102,7 @@ class EditMangaDialog : DialogController { changeCover() } - if (manga.currentArtist() != manga.originalArtist()) + if (manga.currentDesc() != manga.originalDesc()) view.manga_description.append(manga.currentDesc()) if (!manga.originalDesc().isNullOrBlank()) view.manga_description.hint = "${resources?.getString(R.string.description)}: ${manga @@ -114,7 +114,7 @@ class EditMangaDialog : DialogController { } private fun resetTags() { - if (manga.originalGenres().isNullOrBlank() || manga.originalGenres() == "null") + if (manga.originalGenres().isNullOrBlank()) dialogView?.manga_genres_tags?.setTags(emptyList()) else dialogView?.manga_genres_tags?.setTags(manga.originalGenres()?.split(", ")) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index d0b78060e2..4a73909e7b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -293,6 +293,7 @@ class MangaInfoController : NucleusController(), if (manga.currentGenres().isNullOrBlank().not()) { manga_genres_tags.setTags(manga.currentGenres()?.split(", ")) } + else manga_genres_tags.setTags(emptyList()) // Update description TextView. manga_summary.text = if (manga.currentDesc().isNullOrBlank()) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt index 1a79d6b85d..b878175600 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoPresenter.kt @@ -204,6 +204,7 @@ class MangaInfoPresenter( fun updateManga(title:String?, author:String?, artist: String?, uri: Uri?, description: String?, tags: Array?) { var changed = false + val title = title?.trim() if (title.isNullOrBlank() && manga.currentTitle() != manga.originalTitle()) { manga.title = manga.originalTitle() changed = true @@ -212,27 +213,30 @@ class MangaInfoPresenter( changed = true } + val author = author?.trim() if (author.isNullOrBlank() && manga.currentAuthor() != manga.originalAuthor()) { manga.author = manga.originalAuthor() changed = true } else if (!author.isNullOrBlank() && author != manga.currentAuthor()) { - manga.author = "${author}${SManga.splitter}${manga.originalAuthor()}" + manga.author = "${author}${SManga.splitter}${manga.originalAuthor() ?: ""}" changed = true } + val artist = artist?.trim() if (artist.isNullOrBlank() && manga.currentArtist() != manga.currentArtist()) { manga.artist = manga.originalArtist() changed = true } else if (!artist.isNullOrBlank() && artist != manga.currentArtist()) { - manga.artist = "${artist}${SManga.splitter}${manga.originalArtist()}" + manga.artist = "${artist}${SManga.splitter}${manga.originalArtist() ?: ""}" changed = true } + val description = description?.trim() if (description.isNullOrBlank() && manga.currentDesc() != manga.originalDesc()) { manga.description = manga.originalDesc() changed = true } else if (!description.isNullOrBlank() && description != manga.currentDesc()) { - manga.description = "${description}${SManga.splitter}${manga.originalDesc()}" + manga.description = "${description}${SManga.splitter}${manga.originalDesc() ?: ""}" changed = true } @@ -242,13 +246,12 @@ class MangaInfoPresenter( changed = true } else if (!tagsString.isNullOrBlank() && tagsString != manga.currentGenres()) { tagsString = tags?.joinToString(", ") { it.capitalize() } - manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres()}" + manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres() ?: ""}" changed = true } if (uri != null) editCoverWithStream(uri) - if (changed) db.updateMangaInfo(manga).executeAsBlocking() } diff --git a/app/src/main/res/layout/edit_manga_dialog.xml b/app/src/main/res/layout/edit_manga_dialog.xml index e1cfd70a36..8ef622edcd 100644 --- a/app/src/main/res/layout/edit_manga_dialog.xml +++ b/app/src/main/res/layout/edit_manga_dialog.xml @@ -19,6 +19,7 @@ android:layout_width="wrap_content" android:adjustViewBounds="true" android:layout_height="150dp" + android:contentDescription="@string/description_cover" android:background="@drawable/image_border_background" android:src="@mipmap/ic_launcher"/> @@ -66,6 +67,16 @@ android:inputType="text" android:maxLines="1"/> + +