Implement manga dir rename

This commit is contained in:
Jobobby04 2021-07-21 13:56:11 -04:00
parent e4debc89f0
commit fda6458821
2 changed files with 17 additions and 1 deletions

View File

@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.model.Page
import eu.kanade.tachiyomi.util.lang.launchIO
import eu.kanade.tachiyomi.util.storage.DiskUtil
import rx.Observable
import timber.log.Timber
import uy.kohesive.injekt.injectLazy
@ -382,6 +383,12 @@ class DownloadManager(private val context: Context) {
}
}
fun renameMangaDir(oldTitle: String, newTitle: String, source: Long) {
val sourceDir = provider.findSourceDir(sourceManager.getOrStub(source)) ?: return
val mangaDir = sourceDir.findFile(DiskUtil.buildValidFilename(oldTitle), true) ?: return
mangaDir.renameTo(DiskUtil.buildValidFilename(newTitle))
}
private fun getChaptersToDelete(chapters: List<Chapter>): List<Chapter> {
return if (!preferences.removeBookmarkedChapters()) {
chapters.filterNot { it.bookmark }

View File

@ -1,7 +1,11 @@
package eu.kanade.tachiyomi.source.model
import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.database.models.MangaImpl
import eu.kanade.tachiyomi.data.download.DownloadManager
import tachiyomi.source.model.MangaInfo
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import java.io.Serializable
interface SManga : Serializable {
@ -41,8 +45,13 @@ interface SManga : Serializable {
fun copyFrom(other: SManga) {
// EXH -->
if (other.title.isNotBlank()) {
if (other.title.isNotBlank() && originalTitle != other.title) {
val oldTitle = originalTitle
title = other.originalTitle
val source = (this as? Manga)?.source
if (source != null) {
Injekt.get<DownloadManager>().renameMangaDir(oldTitle, other.originalTitle, source)
}
}
// EXH <--