Updates to the last commit

This commit is contained in:
Jay 2020-02-03 01:24:20 -08:00
parent 86992a02d8
commit 301bafe460
4 changed files with 20 additions and 13 deletions

View File

@ -1,9 +1,12 @@
package eu.kanade.tachiyomi.data.database.models package eu.kanade.tachiyomi.data.database.models
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.model.SManga import eu.kanade.tachiyomi.source.model.SManga
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.injectLazy
import uy.kohesive.injekt.api.get import kotlin.collections.MutableMap
import kotlin.collections.mutableMapOf
import kotlin.collections.set
open class MangaImpl : Manga { open class MangaImpl : Manga {
@ -48,7 +51,9 @@ open class MangaImpl : Manga {
val trueTitle = other.title val trueTitle = other.title
"${customTitle}${SManga.splitter}${trueTitle}" "${customTitle}${SManga.splitter}${trueTitle}"
} else other.title } else other.title
Injekt.get<DownloadProvider>().renameMangaFolder(oldTitle, title, source) val db:DownloadManager by injectLazy()
val provider = DownloadProvider(db.context)
provider.renameMangaFolder(oldTitle, title, source)
} }
super.copyFrom(other) super.copyFrom(other)
} }

View File

@ -12,6 +12,7 @@ import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.util.DiskUtil import eu.kanade.tachiyomi.util.DiskUtil
import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get import uy.kohesive.injekt.api.get
import java.io.File
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
/** /**
@ -124,7 +125,7 @@ class DownloadCache(
/** /**
* Renews the downloads cache. * Renews the downloads cache.
*/ */
fun renew() { private fun renew() {
val onlineSources = sourceManager.getOnlineSources() val onlineSources = sourceManager.getOnlineSources()
val sourceDirs = rootDir.dir.listFiles() val sourceDirs = rootDir.dir.listFiles()
@ -234,14 +235,13 @@ class DownloadCache(
val sourceDir = rootDir.files[source] ?: return val sourceDir = rootDir.files[source] ?: return
val list = sourceDir.files.toMutableMap() val list = sourceDir.files.toMutableMap()
val mangaFiles = sourceDir.files[DiskUtil.buildValidFilename(from)] ?: return val mangaFiles = sourceDir.files[DiskUtil.buildValidFilename(from)] ?: return
val newDir = MangaDirectory( val newFile = UniFile.fromFile(File(sourceDir.dir.filePath + "/" + DiskUtil
UniFile.fromUri( .buildValidFilename(to))) ?: return
context, Uri.parse(sourceDir.dir.filePath + "/" + DiskUtil.buildValidFilename(to)) val newDir = MangaDirectory(newFile)
)
)
newDir.files = mangaFiles.files newDir.files = mangaFiles.files
list.remove(DiskUtil.buildValidFilename(from)) list.remove(DiskUtil.buildValidFilename(from))
list[to] = newDir list[to] = newDir
sourceDir.files = list
} }

View File

@ -182,6 +182,10 @@ class DownloadManager(val context: Context) {
return cache.getDownloadCount(manga) return cache.getDownloadCount(manga)
} }
fun renameCache(from: String, to: String, source: Long) {
cache.renameFolder(from, to, source)
}
/** /**
* Calls delete chapter, which deletes temp downloads * Calls delete chapter, which deletes temp downloads
* @param downloads list of downloads to cancel * @param downloads list of downloads to cancel

View File

@ -128,8 +128,6 @@ class DownloadProvider(private val context: Context) {
} }
} }
} }
val cache = DownloadCache(context, this, sourceManager)
cache.renew()
} }
fun renameMangaFolder(from: String, to: String, sourceId: Long) { fun renameMangaFolder(from: String, to: String, sourceId: Long) {
@ -138,8 +136,8 @@ class DownloadProvider(private val context: Context) {
val sourceDir = findSourceDir(source) val sourceDir = findSourceDir(source)
val mangaDir = sourceDir?.findFile(DiskUtil.buildValidFilename(from)) val mangaDir = sourceDir?.findFile(DiskUtil.buildValidFilename(from))
mangaDir?.renameTo(to) mangaDir?.renameTo(to)
val cache = DownloadCache(context, this, sourceManager) val downloadManager:DownloadManager by injectLazy()
cache.renameFolder(from, to, sourceId) downloadManager.renameCache(from, to, sourceId)
} }
/** /**