mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-12 20:19:05 +01:00
Add unified storage location setting
Currently only using it as a replacement for the downloads location.
This commit is contained in:
@@ -92,8 +92,8 @@ class BackupCreator(
|
||||
file = (
|
||||
if (isAutoBackup) {
|
||||
// Get dir of file and create
|
||||
var dir = UniFile.fromUri(context, uri)
|
||||
dir = dir.createDirectory("automatic")
|
||||
val dir = UniFile.fromUri(context, uri)
|
||||
.createDirectory("automatic")
|
||||
|
||||
// Delete older backups
|
||||
dir.listFiles { _, filename -> Backup.filenameRegex.matches(filename) }
|
||||
|
||||
@@ -44,9 +44,9 @@ import tachiyomi.core.util.lang.launchIO
|
||||
import tachiyomi.core.util.lang.launchNonCancellable
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import tachiyomi.domain.storage.service.StoragePreferences
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import java.io.File
|
||||
@@ -64,7 +64,7 @@ class DownloadCache(
|
||||
private val provider: DownloadProvider = Injekt.get(),
|
||||
private val sourceManager: SourceManager = Injekt.get(),
|
||||
private val extensionManager: ExtensionManager = Injekt.get(),
|
||||
private val downloadPreferences: DownloadPreferences = Injekt.get(),
|
||||
private val storagePreferences: StoragePreferences = Injekt.get(),
|
||||
) {
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
@@ -98,7 +98,7 @@ class DownloadCache(
|
||||
private var rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
|
||||
|
||||
init {
|
||||
downloadPreferences.downloadsDirectory().changes()
|
||||
storagePreferences.baseStorageDirectory().changes()
|
||||
.onEach {
|
||||
rootDownloadsDir = RootDirectory(getDirectoryFromPreference())
|
||||
invalidateCache()
|
||||
@@ -297,8 +297,8 @@ class DownloadCache(
|
||||
* Returns the downloads directory from the user's preferences.
|
||||
*/
|
||||
private fun getDirectoryFromPreference(): UniFile {
|
||||
val dir = downloadPreferences.downloadsDirectory().get()
|
||||
return UniFile.fromUri(context, dir.toUri())
|
||||
return UniFile.fromUri(context, storagePreferences.baseStorageDirectory().get().toUri())
|
||||
.createDirectory(StoragePreferences.DOWNLOADS_DIR)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,8 +12,8 @@ import logcat.LogPriority
|
||||
import tachiyomi.core.i18n.stringResource
|
||||
import tachiyomi.core.util.system.logcat
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.storage.service.StoragePreferences
|
||||
import tachiyomi.i18n.MR
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
@@ -26,7 +26,7 @@ import uy.kohesive.injekt.api.get
|
||||
*/
|
||||
class DownloadProvider(
|
||||
private val context: Context,
|
||||
downloadPreferences: DownloadPreferences = Injekt.get(),
|
||||
private val storagePreferences: StoragePreferences = Injekt.get(),
|
||||
) {
|
||||
|
||||
private val scope = MainScope()
|
||||
@@ -34,18 +34,24 @@ class DownloadProvider(
|
||||
/**
|
||||
* The root directory for downloads.
|
||||
*/
|
||||
private var downloadsDir = downloadPreferences.downloadsDirectory().get().let {
|
||||
val dir = UniFile.fromUri(context, it.toUri())
|
||||
DiskUtil.createNoMediaFile(dir, context)
|
||||
dir
|
||||
}
|
||||
private var downloadsDir = setDownloadsLocation()
|
||||
|
||||
init {
|
||||
downloadPreferences.downloadsDirectory().changes()
|
||||
.onEach { downloadsDir = UniFile.fromUri(context, it.toUri()) }
|
||||
storagePreferences.baseStorageDirectory().changes()
|
||||
.onEach { downloadsDir = setDownloadsLocation() }
|
||||
.launchIn(scope)
|
||||
}
|
||||
|
||||
private fun setDownloadsLocation(): UniFile {
|
||||
return storagePreferences.baseStorageDirectory().get().let {
|
||||
val dir = UniFile.fromUri(context, it.toUri())
|
||||
.createDirectory(StoragePreferences.DOWNLOADS_DIR)
|
||||
DiskUtil.createNoMediaFile(dir, context)
|
||||
logcat { "downloadsDir: ${dir.filePath}" }
|
||||
dir
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the download directory for a manga. For internal use only.
|
||||
*
|
||||
|
||||
@@ -12,10 +12,11 @@ import eu.kanade.tachiyomi.util.system.isDevFlavor
|
||||
import tachiyomi.core.preference.AndroidPreferenceStore
|
||||
import tachiyomi.core.preference.PreferenceStore
|
||||
import tachiyomi.core.provider.AndroidBackupFolderProvider
|
||||
import tachiyomi.core.provider.AndroidDownloadFolderProvider
|
||||
import tachiyomi.core.provider.AndroidStorageFolderProvider
|
||||
import tachiyomi.domain.backup.service.BackupPreferences
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.library.service.LibraryPreferences
|
||||
import tachiyomi.domain.storage.service.StoragePreferences
|
||||
import uy.kohesive.injekt.api.InjektModule
|
||||
import uy.kohesive.injekt.api.InjektRegistrar
|
||||
import uy.kohesive.injekt.api.addSingletonFactory
|
||||
@@ -49,13 +50,7 @@ class PreferenceModule(val app: Application) : InjektModule {
|
||||
TrackPreferences(get())
|
||||
}
|
||||
addSingletonFactory {
|
||||
AndroidDownloadFolderProvider(app)
|
||||
}
|
||||
addSingletonFactory {
|
||||
DownloadPreferences(
|
||||
folderProvider = get<AndroidDownloadFolderProvider>(),
|
||||
preferenceStore = get(),
|
||||
)
|
||||
DownloadPreferences(get())
|
||||
}
|
||||
addSingletonFactory {
|
||||
AndroidBackupFolderProvider(app)
|
||||
@@ -66,6 +61,15 @@ class PreferenceModule(val app: Application) : InjektModule {
|
||||
preferenceStore = get(),
|
||||
)
|
||||
}
|
||||
addSingletonFactory {
|
||||
AndroidStorageFolderProvider(app)
|
||||
}
|
||||
addSingletonFactory {
|
||||
StoragePreferences(
|
||||
folderProvider = get<AndroidStorageFolderProvider>(),
|
||||
preferenceStore = get(),
|
||||
)
|
||||
}
|
||||
addSingletonFactory {
|
||||
UiPreferences(get())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user