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
import eu.kanade.tachiyomi.data.download.DownloadManager
import eu.kanade.tachiyomi.data.download.DownloadProvider
import eu.kanade.tachiyomi.source.model.SManga
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
import uy.kohesive.injekt.injectLazy
import kotlin.collections.MutableMap
import kotlin.collections.mutableMapOf
import kotlin.collections.set
open class MangaImpl : Manga {
@ -48,7 +51,9 @@ open class MangaImpl : Manga {
val trueTitle = other.title
"${customTitle}${SManga.splitter}${trueTitle}"
} 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)
}

View File

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

View File

@ -182,6 +182,10 @@ class DownloadManager(val context: Context) {
return cache.getDownloadCount(manga)
}
fun renameCache(from: String, to: String, source: Long) {
cache.renameFolder(from, to, source)
}
/**
* Calls delete chapter, which deletes temp downloads
* @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) {
@ -138,8 +136,8 @@ class DownloadProvider(private val context: Context) {
val sourceDir = findSourceDir(source)
val mangaDir = sourceDir?.findFile(DiskUtil.buildValidFilename(from))
mangaDir?.renameTo(to)
val cache = DownloadCache(context, this, sourceManager)
cache.renameFolder(from, to, sourceId)
val downloadManager:DownloadManager by injectLazy()
downloadManager.renameCache(from, to, sourceId)
}
/**