mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-09-10 21:03:13 +02:00
Threw local manga editing into a json
This commit is contained in:
parent
a253c255e8
commit
db11ac8cf6
@ -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,24 +84,34 @@ class EditMangaDialog : DialogController {
|
||||
.signature(ObjectKey(MangaImpl.getLastCoverFetch(manga.id!!).toString()))
|
||||
.dontAnimate()
|
||||
.into(view.manga_cover)
|
||||
val isLocal = manga.source == LocalSource.ID
|
||||
|
||||
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()}"
|
||||
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()}"
|
||||
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()}"
|
||||
|
||||
view.cover_layout.setOnClickListener {
|
||||
changeCover()
|
||||
}
|
||||
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())
|
||||
@ -110,11 +121,15 @@ class EditMangaDialog : DialogController {
|
||||
if (manga.currentGenres().isNullOrBlank().not()) {
|
||||
view.manga_genres_tags.setTags(manga.currentGenres()?.split(", "))
|
||||
}
|
||||
}
|
||||
view.cover_layout.setOnClickListener {
|
||||
changeCover()
|
||||
}
|
||||
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,6 +203,17 @@ class MangaInfoPresenter(
|
||||
|
||||
fun updateManga(title:String?, author:String?, artist: String?, uri: Uri?,
|
||||
description: String?, tags: Array<String>?) {
|
||||
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()) {
|
||||
@ -223,7 +234,7 @@ class MangaInfoPresenter(
|
||||
}
|
||||
|
||||
val artist = artist?.trim()
|
||||
if (artist.isNullOrBlank() && manga.currentArtist() != manga.currentArtist()) {
|
||||
if (artist.isNullOrBlank() && manga.currentArtist() != manga.originalArtist()) {
|
||||
manga.artist = manga.originalArtist()
|
||||
changed = true
|
||||
} else if (!artist.isNullOrBlank() && artist != manga.currentArtist()) {
|
||||
@ -249,10 +260,10 @@ class MangaInfoPresenter(
|
||||
manga.genre = "${tagsString}${SManga.splitter}${manga.originalGenres() ?: ""}"
|
||||
changed = true
|
||||
}
|
||||
|
||||
if (changed) db.updateMangaInfo(manga).executeAsBlocking()
|
||||
}
|
||||
if (uri != null) editCoverWithStream(uri)
|
||||
|
||||
if (changed) db.updateMangaInfo(manga).executeAsBlocking()
|
||||
}
|
||||
|
||||
private fun editCoverWithStream(uri: Uri): Boolean {
|
||||
|
Loading…
Reference in New Issue
Block a user