Remove tmp chapter files after exiting reader
(cherry picked from commit 4e221397ceaec334307546920b3e1168e56f5433) # Conflicts: # app/src/main/java/eu/kanade/tachiyomi/di/AppModule.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderViewModel.kt # app/src/main/java/eu/kanade/tachiyomi/ui/reader/loader/ChapterLoader.kt # source-local/src/androidMain/kotlin/tachiyomi/source/local/LocalSource.kt
This commit is contained in:
@@ -32,6 +32,7 @@ import nl.adaptivity.xmlutil.XmlDeclMode
|
||||
import nl.adaptivity.xmlutil.core.XmlVersion
|
||||
import nl.adaptivity.xmlutil.serialization.XML
|
||||
import tachiyomi.core.storage.AndroidStorageFolderProvider
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.data.AndroidDatabaseHandler
|
||||
import tachiyomi.data.Database
|
||||
import tachiyomi.data.DatabaseHandler
|
||||
@@ -139,6 +140,8 @@ class AppModule(val app: Application) : InjektModule {
|
||||
ProtoBuf
|
||||
}
|
||||
|
||||
addSingletonFactory { UniFileTempFileManager(app) }
|
||||
|
||||
addSingletonFactory { ChapterCache(app, get(), get()) }
|
||||
addSingletonFactory { CoverCache(app) }
|
||||
|
||||
|
||||
@@ -71,6 +71,7 @@ import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import logcat.LogPriority
|
||||
import tachiyomi.core.preference.toggle
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.core.util.lang.launchIO
|
||||
import tachiyomi.core.util.lang.launchNonCancellable
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
@@ -108,6 +109,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val downloadManager: DownloadManager = Injekt.get(),
|
||||
private val downloadProvider: DownloadProvider = Injekt.get(),
|
||||
private val tempFileManager: UniFileTempFileManager = Injekt.get(),
|
||||
private val imageSaver: ImageSaver = Injekt.get(),
|
||||
preferences: BasePreferences = Injekt.get(),
|
||||
val readerPreferences: ReaderPreferences = Injekt.get(),
|
||||
@@ -380,6 +382,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
context = context,
|
||||
downloadManager = downloadManager,
|
||||
downloadProvider = downloadProvider,
|
||||
tempFileManager = tempFileManager,
|
||||
manga = manga,
|
||||
source = source, /* SY --> */
|
||||
sourceManager = sourceManager,
|
||||
@@ -1274,6 +1277,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
private fun deletePendingChapters() {
|
||||
viewModelScope.launchNonCancellable {
|
||||
downloadManager.deletePendingChapters()
|
||||
tempFileManager.deleteTempFiles()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.source.online.all.MergedSource
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.setting.ReaderPreferences
|
||||
import tachiyomi.core.i18n.stringResource
|
||||
import tachiyomi.core.storage.toTempFile
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.core.util.lang.withIOContext
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
@@ -28,6 +28,7 @@ class ChapterLoader(
|
||||
private val context: Context,
|
||||
private val downloadManager: DownloadManager,
|
||||
private val downloadProvider: DownloadProvider,
|
||||
private val tempFileManager: UniFileTempFileManager,
|
||||
private val manga: Manga,
|
||||
private val source: Source,
|
||||
// SY -->
|
||||
@@ -125,13 +126,13 @@ class ChapterLoader(
|
||||
source is LocalSource -> source.getFormat(chapter.chapter).let { format ->
|
||||
when (format) {
|
||||
is Format.Directory -> DirectoryPageLoader(format.file)
|
||||
is Format.Zip -> ZipPageLoader(format.file.toTempFile(context))
|
||||
is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file))
|
||||
is Format.Rar -> try {
|
||||
RarPageLoader(format.file.toTempFile(context))
|
||||
RarPageLoader(tempFileManager.createTempFile(format.file))
|
||||
} catch (e: UnsupportedRarV5Exception) {
|
||||
error(context.stringResource(MR.strings.loader_rar5_error))
|
||||
}
|
||||
is Format.Epub -> EpubPageLoader(format.file.toTempFile(context))
|
||||
is Format.Epub -> EpubPageLoader(tempFileManager.createTempFile(format.file))
|
||||
}
|
||||
}
|
||||
else -> error(context.stringResource(MR.strings.loader_not_implemented_error))
|
||||
@@ -142,13 +143,13 @@ class ChapterLoader(
|
||||
source is LocalSource -> source.getFormat(chapter.chapter).let { format ->
|
||||
when (format) {
|
||||
is Format.Directory -> DirectoryPageLoader(format.file)
|
||||
is Format.Zip -> ZipPageLoader(format.file.toTempFile(context))
|
||||
is Format.Zip -> ZipPageLoader(tempFileManager.createTempFile(format.file))
|
||||
is Format.Rar -> try {
|
||||
RarPageLoader(format.file.toTempFile(context))
|
||||
RarPageLoader(tempFileManager.createTempFile(format.file))
|
||||
} catch (e: UnsupportedRarV5Exception) {
|
||||
error(context.stringResource(MR.strings.loader_rar5_error))
|
||||
}
|
||||
is Format.Epub -> EpubPageLoader(format.file.toTempFile(context))
|
||||
is Format.Epub -> EpubPageLoader(tempFileManager.createTempFile(format.file))
|
||||
}
|
||||
}
|
||||
source is HttpSource -> HttpPageLoader(chapter, source)
|
||||
|
||||
@@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderChapter
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import tachiyomi.core.storage.toTempFile
|
||||
import tachiyomi.core.storage.UniFileTempFileManager
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
@@ -23,6 +23,7 @@ internal class DownloadPageLoader(
|
||||
private val source: Source,
|
||||
private val downloadManager: DownloadManager,
|
||||
private val downloadProvider: DownloadProvider,
|
||||
private val tempFileManager: UniFileTempFileManager,
|
||||
) : PageLoader() {
|
||||
|
||||
private val context: Application by injectLazy()
|
||||
@@ -46,8 +47,8 @@ internal class DownloadPageLoader(
|
||||
zipPageLoader?.recycle()
|
||||
}
|
||||
|
||||
private suspend fun getPagesFromArchive(chapterPath: UniFile): List<ReaderPage> {
|
||||
val loader = ZipPageLoader(chapterPath.toTempFile(context)).also { zipPageLoader = it }
|
||||
private suspend fun getPagesFromArchive(file: UniFile): List<ReaderPage> {
|
||||
val loader = ZipPageLoader(tempFileManager.createTempFile(file)).also { zipPageLoader = it }
|
||||
return loader.getPages()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user