From 301bafe460544fa011af65816936adedd201f02c Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 3 Feb 2020 01:24:20 -0800 Subject: [PATCH] Updates to the last commit --- .../tachiyomi/data/database/models/MangaImpl.kt | 11 ++++++++--- .../kanade/tachiyomi/data/download/DownloadCache.kt | 12 ++++++------ .../tachiyomi/data/download/DownloadManager.kt | 4 ++++ .../tachiyomi/data/download/DownloadProvider.kt | 6 ++---- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt index d9a925ff2e..906ad8f460 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/database/models/MangaImpl.kt @@ -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().renameMangaFolder(oldTitle, title, source) + val db:DownloadManager by injectLazy() + val provider = DownloadProvider(db.context) + provider.renameMangaFolder(oldTitle, title, source) } super.copyFrom(other) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index 38407d1a7e..d129132d67 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -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 } diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt index 413a9c5830..2e5b405ae4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadManager.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt index 9163ed2fdc..f68aa54cf9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadProvider.kt @@ -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) } /**