Threw local manga editing into a json
This commit is contained in:
parent
a253c255e8
commit
db11ac8cf6
3 changed files with 130 additions and 66 deletions
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.source
|
|||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.GsonBuilder
|
||||
import com.google.gson.JsonObject
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.source.model.Filter
|
||||
|
@ -21,6 +22,7 @@ import rx.Observable
|
|||
import timber.log.Timber
|
||||
import java.io.File
|
||||
import java.io.FileInputStream
|
||||
import java.io.FileWriter
|
||||
import java.io.InputStream
|
||||
import java.util.Locale
|
||||
import java.util.Scanner
|
||||
|
@ -148,6 +150,42 @@ class LocalSource(private val context: Context) : CatalogueSource {
|
|||
return Observable.just(manga)
|
||||
}
|
||||
|
||||
fun updateMangaInfo(manga: SManga) {
|
||||
val directory = getBaseDirectories(context).mapNotNull { File(it, manga.url) }.find { it
|
||||
.exists() } ?: return
|
||||
val gson = GsonBuilder().setPrettyPrinting().create()
|
||||
val file = File(directory, "info.json")
|
||||
file.writeText(gson.toJson(manga.toJson()))
|
||||
}
|
||||
|
||||
fun SManga.toJson():MangaJson {
|
||||
return MangaJson(title, author, artist, description, genre?.split(", ")?.toTypedArray())
|
||||
}
|
||||
|
||||
data class MangaJson(
|
||||
val title:String,
|
||||
val author:String?,
|
||||
val artist:String?,
|
||||
val description:String?,
|
||||
val genre:Array<String>?
|
||||
) {
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MangaJson
|
||||
|
||||
if (title != other.title) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
return title.hashCode()
|
||||
}
|
||||
}
|
||||
|
||||
override fun fetchChapterList(manga: SManga): Observable<List<SChapter>> {
|
||||
val chapters = getBaseDirectories(context)
|
||||
.mapNotNull { File(it, manga.url).listFiles()?.toList() }
|
||||
|
|
|
@ -20,6 +20,7 @@ import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|||
import eu.kanade.tachiyomi.data.database.models.Manga
|
||||
import eu.kanade.tachiyomi.data.database.models.MangaImpl
|
||||
import eu.kanade.tachiyomi.data.glide.GlideApp
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
import eu.kanade.tachiyomi.ui.base.controller.DialogController
|
||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||
import eu.kanade.tachiyomi.util.chop
|
||||
|
@ -83,38 +84,52 @@ class EditMangaDialog : DialogController {
|
|||
.signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString()))
|
||||
.dontAnimate()
|
||||
.into(view.manga_cover)
|
||||
val isLocal = manga.source == LocalSource.ID
|
||||
|
||||
if (manga.currentTitle() != manga.originalTitle())
|
||||
view.manga_title.append(manga.currentTitle())
|
||||
view.manga_title.hint = "${resources?.getString(R.string.title)}: ${manga.originalTitle()}"
|
||||
if (isLocal) {
|
||||
if (manga.title != manga.url)
|
||||
view.manga_title.append(manga.title)
|
||||
view.manga_title.hint = "${resources?.getString(R.string.title)}: ${manga.url}"
|
||||
view.manga_author.append(manga.author ?: "")
|
||||
view.manga_artist.append(manga.artist ?: "")
|
||||
view.manga_description.append(manga.description ?: "")
|
||||
view.manga_genres_tags.setTags(manga.genre?.split(", ") ?: emptyList())
|
||||
}
|
||||
else {
|
||||
if (manga.currentTitle() != manga.originalTitle())
|
||||
view.manga_title.append(manga.currentTitle())
|
||||
view.manga_title.hint = "${resources?.getString(R.string.title)}: ${manga
|
||||
.originalTitle()}"
|
||||
|
||||
if (manga.currentAuthor() != manga.originalAuthor())
|
||||
view.manga_author.append(manga.currentAuthor())
|
||||
if (!manga.originalAuthor().isNullOrBlank())
|
||||
view.manga_author.hint = "${resources?.getString(R.string.manga_info_author_label)}: ${manga.originalAuthor()}"
|
||||
if (manga.currentAuthor() != manga.originalAuthor())
|
||||
view.manga_author.append(manga.currentAuthor())
|
||||
if (!manga.originalAuthor().isNullOrBlank())
|
||||
view.manga_author.hint = "${resources?.getString(R.string
|
||||
.manga_info_author_label)}: ${manga.originalAuthor()}"
|
||||
|
||||
if (manga.currentArtist() != manga.originalArtist())
|
||||
view.manga_artist.append(manga.currentArtist())
|
||||
if (!manga.originalArtist().isNullOrBlank())
|
||||
view.manga_artist.hint = "${resources?.getString(R.string.manga_info_artist_label)}: ${manga.originalArtist()}"
|
||||
if (manga.currentArtist() != manga.originalArtist())
|
||||
view.manga_artist.append(manga.currentArtist())
|
||||
if (!manga.originalArtist().isNullOrBlank())
|
||||
view.manga_artist.hint = "${resources?.getString(R.string
|
||||
.manga_info_artist_label)}: ${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
|
||||
.originalDesc()?.chop(15)}"
|
||||
if (manga.currentGenres().isNullOrBlank().not()) {
|
||||
view.manga_genres_tags.setTags(manga.currentGenres()?.split(", "))
|
||||
}
|
||||
}
|
||||
view.cover_layout.setOnClickListener {
|
||||
changeCover()
|
||||
}
|
||||
|
||||
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
|
||||
.originalDesc()?.chop(15)}"
|
||||
if (manga.currentGenres().isNullOrBlank().not()) {
|
||||
view.manga_genres_tags.setTags(manga.currentGenres()?.split(", "))
|
||||
}
|
||||
view.reset_tags.setOnClickListener { resetTags() }
|
||||
}
|
||||
|
||||
private fun resetTags() {
|
||||
if (manga.originalGenres().isNullOrBlank())
|
||||
if (manga.originalGenres().isNullOrBlank() || manga.source == LocalSource.ID)
|
||||
dialogView?.manga_genres_tags?.setTags(emptyList())
|
||||
else
|
||||
dialogView?.manga_genres_tags?.setTags(manga.originalGenres()?.split(", "))
|
||||
|
|
|
@ -203,56 +203,67 @@ class MangaInfoPresenter(
|
|||
|
||||
fun updateManga(title:String?, author:String?, artist: String?, uri: Uri?,
|
||||
description: String?, tags: Array<String>?) {
|
||||
var changed = false
|
||||
val title = title?.trim()
|
||||
if (title.isNullOrBlank() && manga.currentTitle() != manga.originalTitle()) {
|
||||
manga.title = manga.originalTitle()
|
||||
changed = true
|
||||
} else if (!title.isNullOrBlank() && title != manga.currentTitle()) {
|
||||
manga.title = "${title}${SManga.splitter}${manga.originalTitle()}"
|
||||
changed = true
|
||||
if (manga.source == LocalSource.ID) {
|
||||
manga.title = if (title.isNullOrBlank()) manga.url else title.trim()
|
||||
manga.author = author?.trim()
|
||||
manga.artist = artist?.trim()
|
||||
manga.description = description?.trim()
|
||||
val tagsString = tags?.joinToString(", ") { it.capitalize() }
|
||||
manga.genre = if (tags.isNullOrEmpty()) null else tagsString?.trim()
|
||||
LocalSource(downloadManager.context).updateMangaInfo(manga)
|
||||
db.updateMangaInfo(manga).executeAsBlocking()
|
||||
}
|
||||
else {
|
||||
var changed = false
|
||||
val title = title?.trim()
|
||||
if (title.isNullOrBlank() && manga.currentTitle() != manga.originalTitle()) {
|
||||
manga.title = manga.originalTitle()
|
||||
changed = true
|
||||
} else if (!title.isNullOrBlank() && title != manga.currentTitle()) {
|
||||
manga.title = "${title}${SManga.splitter}${manga.originalTitle()}"
|
||||
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() ?: ""}"
|
||||
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() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
|
||||
val artist = artist?.trim()
|
||||
if (artist.isNullOrBlank() && manga.currentArtist() != manga.originalArtist()) {
|
||||
manga.artist = manga.originalArtist()
|
||||
changed = true
|
||||
} else if (!artist.isNullOrBlank() && artist != manga.currentArtist()) {
|
||||
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() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
|
||||
var tagsString = tags?.joinToString(", ")
|
||||
if (tagsString.isNullOrBlank() && manga.currentGenres() != manga.originalGenres()) {
|
||||
manga.genre = manga.originalGenres()
|
||||
changed = true
|
||||
} else if (!tagsString.isNullOrBlank() && tagsString != manga.currentGenres()) {
|
||||
tagsString = tags?.joinToString(", ") { it.capitalize() }
|
||||
manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
if (changed) db.updateMangaInfo(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
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() ?: ""}"
|
||||
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() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
|
||||
var tagsString = tags?.joinToString(", ")
|
||||
if (tagsString.isNullOrBlank() && manga.currentGenres() != manga.originalGenres()) {
|
||||
manga.genre = manga.originalGenres()
|
||||
changed = true
|
||||
} else if (!tagsString.isNullOrBlank() && tagsString != manga.currentGenres()) {
|
||||
tagsString = tags?.joinToString(", ") { it.capitalize() }
|
||||
manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
|
||||
if (uri != null) editCoverWithStream(uri)
|
||||
|
||||
if (changed) db.updateMangaInfo(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
private fun editCoverWithStream(uri: Uri): Boolean {
|
||||
|
|
Reference in a new issue