Fixes for local manga and others for custom manga info

This commit is contained in:
Jay 2020-01-20 12:34:20 -08:00
parent c92b2bb203
commit bf919e7949
5 changed files with 35 additions and 48 deletions

View file

@ -32,44 +32,26 @@ interface SManga : Serializable {
return splitTitle.last() return splitTitle.last()
} }
fun currentGenres(): String? { fun currentGenres() = split(genre, true)
val splitGenre = genre?.split(splitter) ?: return null
return splitGenre.first()
}
fun originalGenres(): String? { fun originalGenres() = split(genre, false)
val splitGenre = genre?.split(splitter) ?: return null
return splitGenre.last()
}
fun currentDesc(): String? { fun currentDesc() = split(description, true)
val splitDesc = description?.split(splitter) ?: return null
return splitDesc.first()
}
fun originalDesc(): String? { fun originalDesc() = split(description, false)
val splitDesc = description?.split(splitter) ?: return null
return splitDesc.last()
}
fun currentAuthor(): String? { fun currentAuthor() = split(author, true)
val splitAuth = author?.split(splitter) ?: return null
return splitAuth.first()
}
fun originalAuthor(): String? { fun originalAuthor() = split(author, false)
val splitAuth = author?.split(splitter) ?: return null
return splitAuth.last()
}
fun currentArtist(): String? { fun currentArtist() = split(artist, true)
val splitArtist = artist?.split(splitter) ?: return null
return splitArtist.first()
}
fun originalArtist(): String? { fun originalArtist() = split(artist, false)
val splitArtist = artist?.split(splitter) ?: return null
return splitArtist.last() 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) { fun copyFrom(other: SManga) {

View file

@ -102,7 +102,7 @@ class EditMangaDialog : DialogController {
changeCover() changeCover()
} }
if (manga.currentArtist() != manga.originalArtist()) if (manga.currentDesc() != manga.originalDesc())
view.manga_description.append(manga.currentDesc()) view.manga_description.append(manga.currentDesc())
if (!manga.originalDesc().isNullOrBlank()) if (!manga.originalDesc().isNullOrBlank())
view.manga_description.hint = "${resources?.getString(R.string.description)}: ${manga view.manga_description.hint = "${resources?.getString(R.string.description)}: ${manga
@ -114,7 +114,7 @@ class EditMangaDialog : DialogController {
} }
private fun resetTags() { private fun resetTags() {
if (manga.originalGenres().isNullOrBlank() || manga.originalGenres() == "null") if (manga.originalGenres().isNullOrBlank())
dialogView?.manga_genres_tags?.setTags(emptyList()) dialogView?.manga_genres_tags?.setTags(emptyList())
else else
dialogView?.manga_genres_tags?.setTags(manga.originalGenres()?.split(", ")) dialogView?.manga_genres_tags?.setTags(manga.originalGenres()?.split(", "))

View file

@ -293,6 +293,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
if (manga.currentGenres().isNullOrBlank().not()) { if (manga.currentGenres().isNullOrBlank().not()) {
manga_genres_tags.setTags(manga.currentGenres()?.split(", ")) manga_genres_tags.setTags(manga.currentGenres()?.split(", "))
} }
else manga_genres_tags.setTags(emptyList())
// Update description TextView. // Update description TextView.
manga_summary.text = if (manga.currentDesc().isNullOrBlank()) { manga_summary.text = if (manga.currentDesc().isNullOrBlank()) {

View file

@ -204,6 +204,7 @@ class MangaInfoPresenter(
fun updateManga(title:String?, author:String?, artist: String?, uri: Uri?, fun updateManga(title:String?, author:String?, artist: String?, uri: Uri?,
description: String?, tags: Array<String>?) { description: String?, tags: Array<String>?) {
var changed = false var changed = false
val title = title?.trim()
if (title.isNullOrBlank() && manga.currentTitle() != manga.originalTitle()) { if (title.isNullOrBlank() && manga.currentTitle() != manga.originalTitle()) {
manga.title = manga.originalTitle() manga.title = manga.originalTitle()
changed = true changed = true
@ -212,27 +213,30 @@ class MangaInfoPresenter(
changed = true changed = true
} }
val author = author?.trim()
if (author.isNullOrBlank() && manga.currentAuthor() != manga.originalAuthor()) { if (author.isNullOrBlank() && manga.currentAuthor() != manga.originalAuthor()) {
manga.author = manga.originalAuthor() manga.author = manga.originalAuthor()
changed = true changed = true
} else if (!author.isNullOrBlank() && author != manga.currentAuthor()) { } else if (!author.isNullOrBlank() && author != manga.currentAuthor()) {
manga.author = "${author}${SManga.splitter}${manga.originalAuthor()}" manga.author = "${author}${SManga.splitter}${manga.originalAuthor() ?: ""}"
changed = true changed = true
} }
val artist = artist?.trim()
if (artist.isNullOrBlank() && manga.currentArtist() != manga.currentArtist()) { if (artist.isNullOrBlank() && manga.currentArtist() != manga.currentArtist()) {
manga.artist = manga.originalArtist() manga.artist = manga.originalArtist()
changed = true changed = true
} else if (!artist.isNullOrBlank() && artist != manga.currentArtist()) { } else if (!artist.isNullOrBlank() && artist != manga.currentArtist()) {
manga.artist = "${artist}${SManga.splitter}${manga.originalArtist()}" manga.artist = "${artist}${SManga.splitter}${manga.originalArtist() ?: ""}"
changed = true changed = true
} }
val description = description?.trim()
if (description.isNullOrBlank() && manga.currentDesc() != manga.originalDesc()) { if (description.isNullOrBlank() && manga.currentDesc() != manga.originalDesc()) {
manga.description = manga.originalDesc() manga.description = manga.originalDesc()
changed = true changed = true
} else if (!description.isNullOrBlank() && description != manga.currentDesc()) { } else if (!description.isNullOrBlank() && description != manga.currentDesc()) {
manga.description = "${description}${SManga.splitter}${manga.originalDesc()}" manga.description = "${description}${SManga.splitter}${manga.originalDesc() ?: ""}"
changed = true changed = true
} }
@ -242,13 +246,12 @@ class MangaInfoPresenter(
changed = true changed = true
} else if (!tagsString.isNullOrBlank() && tagsString != manga.currentGenres()) { } else if (!tagsString.isNullOrBlank() && tagsString != manga.currentGenres()) {
tagsString = tags?.joinToString(", ") { it.capitalize() } tagsString = tags?.joinToString(", ") { it.capitalize() }
manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres()}" manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres() ?: ""}"
changed = true changed = true
} }
if (uri != null) editCoverWithStream(uri) if (uri != null) editCoverWithStream(uri)
if (changed) db.updateMangaInfo(manga).executeAsBlocking() if (changed) db.updateMangaInfo(manga).executeAsBlocking()
} }

View file

@ -19,6 +19,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:adjustViewBounds="true" android:adjustViewBounds="true"
android:layout_height="150dp" android:layout_height="150dp"
android:contentDescription="@string/description_cover"
android:background="@drawable/image_border_background" android:background="@drawable/image_border_background"
android:src="@mipmap/ic_launcher"/> android:src="@mipmap/ic_launcher"/>
@ -66,6 +67,16 @@
android:inputType="text" android:inputType="text"
android:maxLines="1"/> android:maxLines="1"/>
<EditText
android:id="@+id/manga_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:hint="@string/description"
android:inputType="text|textMultiLine"
android:scrollHorizontally="false" />
<Button <Button
android:id="@+id/reset_tags" android:id="@+id/reset_tags"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -94,16 +105,6 @@
app:atg_borderColor="@color/md_blue_A400" app:atg_borderColor="@color/md_blue_A400"
app:atg_textColor="@color/md_blue_A400" /> app:atg_textColor="@color/md_blue_A400" />
<EditText
android:id="@+id/manga_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/description"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:inputType="text|textMultiLine"
android:scrollHorizontally="false"/>
<View <View
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="1dp" android:layout_height="1dp"