mirror of
https://github.com/null2264/yokai.git
synced 2025-06-21 10:44:42 +00:00
chore(settings): Move stuff around
This commit is contained in:
parent
ea5d29304d
commit
298e50627a
5 changed files with 91 additions and 85 deletions
|
@ -14,14 +14,11 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.google.firebase.crashlytics.ktx.crashlytics
|
||||
import com.hippo.unifile.UniFile
|
||||
import dev.yokai.domain.base.BasePreferences.ExtensionInstaller
|
||||
import dev.yokai.domain.extension.interactor.TrustExtension
|
||||
import eu.kanade.tachiyomi.BuildConfig
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
||||
import eu.kanade.tachiyomi.data.download.DownloadManager
|
||||
import eu.kanade.tachiyomi.data.download.DownloadProvider
|
||||
|
@ -66,7 +63,6 @@ import eu.kanade.tachiyomi.util.system.localeContext
|
|||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.system.withUIContext
|
||||
import eu.kanade.tachiyomi.util.view.openInBrowser
|
||||
import eu.kanade.tachiyomi.util.view.withFadeTransaction
|
||||
import kotlinx.coroutines.CoroutineStart
|
||||
|
@ -87,12 +83,8 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
|||
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
|
||||
private val chapterCache: ChapterCache by injectLazy()
|
||||
|
||||
private val db: DatabaseHelper by injectLazy()
|
||||
|
||||
private val coverCache: CoverCache by injectLazy()
|
||||
|
||||
private val downloadManager: DownloadManager by injectLazy()
|
||||
|
||||
private val trustExtension: TrustExtension by injectLazy()
|
||||
|
@ -190,13 +182,6 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
|||
|
||||
preferenceCategory {
|
||||
titleRes = R.string.data_management
|
||||
preference {
|
||||
key = CLEAR_CACHE_KEY
|
||||
titleRes = R.string.clear_chapter_cache
|
||||
summary = context.getString(R.string.used_, chapterCache.readableSize)
|
||||
|
||||
onClick { clearChapterCache() }
|
||||
}
|
||||
|
||||
preference {
|
||||
titleRes = R.string.force_download_cache_refresh
|
||||
|
@ -204,36 +189,6 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
|||
onClick { downloadManager.refreshCache() }
|
||||
}
|
||||
|
||||
preference {
|
||||
key = "clean_cached_covers"
|
||||
titleRes = R.string.clean_up_cached_covers
|
||||
summary = context.getString(
|
||||
R.string.delete_old_covers_in_library_used_,
|
||||
coverCache.getChapterCacheSize(),
|
||||
)
|
||||
|
||||
onClick {
|
||||
context.toast(R.string.starting_cleanup)
|
||||
(activity as? AppCompatActivity)?.lifecycleScope?.launchIO {
|
||||
coverCache.deleteOldCovers()
|
||||
}
|
||||
}
|
||||
}
|
||||
preference {
|
||||
key = "clear_cached_not_library"
|
||||
titleRes = R.string.clear_cached_covers_non_library
|
||||
summary = context.getString(
|
||||
R.string.delete_all_covers__not_in_library_used_,
|
||||
coverCache.getOnlineCoverCacheSize(),
|
||||
)
|
||||
|
||||
onClick {
|
||||
context.toast(R.string.starting_cleanup)
|
||||
(activity as? AppCompatActivity)?.lifecycleScope?.launchIO {
|
||||
coverCache.deleteAllCachedCovers()
|
||||
}
|
||||
}
|
||||
}
|
||||
preference {
|
||||
key = "clean_downloaded_chapters"
|
||||
titleRes = R.string.clean_up_downloaded_chapters
|
||||
|
@ -487,36 +442,6 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun clearChapterCache() {
|
||||
if (activity == null) return
|
||||
viewScope.launchIO {
|
||||
val files = chapterCache.cacheDir.listFiles() ?: return@launchIO
|
||||
var deletedFiles = 0
|
||||
try {
|
||||
files.forEach { file ->
|
||||
if (chapterCache.removeFileFromCache(file.name)) {
|
||||
deletedFiles++
|
||||
}
|
||||
}
|
||||
withUIContext {
|
||||
activity?.toast(
|
||||
resources?.getQuantityString(
|
||||
R.plurals.cache_cleared,
|
||||
deletedFiles,
|
||||
deletedFiles,
|
||||
),
|
||||
)
|
||||
findPreference(CLEAR_CACHE_KEY)?.summary =
|
||||
resources?.getString(R.string.used_, chapterCache.readableSize)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
withUIContext {
|
||||
activity?.toast(R.string.cache_delete_error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearWebViewData() {
|
||||
if (activity == null) return
|
||||
try {
|
||||
|
@ -536,8 +461,6 @@ class SettingsAdvancedController : SettingsLegacyController() {
|
|||
}
|
||||
|
||||
private companion object {
|
||||
const val CLEAR_CACHE_KEY = "pref_clear_cache_key"
|
||||
|
||||
private var job: Job? = null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,9 @@ import android.view.MenuInflater
|
|||
import android.view.MenuItem
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.net.toUri
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.preference.PreferenceScreen
|
||||
import com.hippo.unifile.UniFile
|
||||
import dev.yokai.domain.storage.StorageManager
|
||||
|
@ -20,6 +22,8 @@ import eu.kanade.tachiyomi.data.backup.BackupCreatorJob
|
|||
import eu.kanade.tachiyomi.data.backup.BackupFileValidator
|
||||
import eu.kanade.tachiyomi.data.backup.BackupRestoreJob
|
||||
import eu.kanade.tachiyomi.data.backup.models.Backup
|
||||
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
||||
import eu.kanade.tachiyomi.data.cache.CoverCache
|
||||
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||
import eu.kanade.tachiyomi.ui.setting.SettingsLegacyController
|
||||
import eu.kanade.tachiyomi.ui.setting.bindTo
|
||||
|
@ -33,9 +37,11 @@ import eu.kanade.tachiyomi.ui.setting.summaryRes
|
|||
import eu.kanade.tachiyomi.ui.setting.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.DeviceUtil
|
||||
import eu.kanade.tachiyomi.util.system.disableItems
|
||||
import eu.kanade.tachiyomi.util.system.launchIO
|
||||
import eu.kanade.tachiyomi.util.system.materialAlertDialog
|
||||
import eu.kanade.tachiyomi.util.system.openInBrowser
|
||||
import eu.kanade.tachiyomi.util.system.toast
|
||||
import eu.kanade.tachiyomi.util.system.withUIContext
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
@ -49,10 +55,14 @@ class SettingsDataController : SettingsLegacyController() {
|
|||
internal val storagePreferences: StoragePreferences by injectLazy()
|
||||
internal val storageManager: StorageManager by injectLazy()
|
||||
|
||||
private val coverCache: CoverCache by injectLazy()
|
||||
private val chapterCache: ChapterCache by injectLazy()
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||
titleRes = R.string.data_and_storage
|
||||
|
||||
preference {
|
||||
key = "pref_storage_location"
|
||||
bindTo(storagePreferences.baseStorageDirectory())
|
||||
titleRes = R.string.storage_location
|
||||
|
||||
|
@ -150,6 +160,50 @@ class SettingsDataController : SettingsLegacyController() {
|
|||
}
|
||||
|
||||
infoPreference(R.string.backup_info)
|
||||
|
||||
preferenceCategory {
|
||||
titleRes = R.string.storage_usage
|
||||
|
||||
preference {
|
||||
key = CLEAR_CACHE_KEY
|
||||
titleRes = R.string.clear_chapter_cache
|
||||
summary = context.getString(R.string.used_, chapterCache.readableSize)
|
||||
|
||||
onClick { clearChapterCache() }
|
||||
}
|
||||
|
||||
preference {
|
||||
key = "clear_cached_not_library"
|
||||
titleRes = R.string.clear_cached_covers_non_library
|
||||
summary = context.getString(
|
||||
R.string.delete_all_covers__not_in_library_used_,
|
||||
coverCache.getOnlineCoverCacheSize(),
|
||||
)
|
||||
|
||||
onClick {
|
||||
context.toast(R.string.starting_cleanup)
|
||||
(activity as? AppCompatActivity)?.lifecycleScope?.launchIO {
|
||||
coverCache.deleteAllCachedCovers()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preference {
|
||||
key = "clean_cached_covers"
|
||||
titleRes = R.string.clean_up_cached_covers
|
||||
summary = context.getString(
|
||||
R.string.delete_old_covers_in_library_used_,
|
||||
coverCache.getChapterCacheSize(),
|
||||
)
|
||||
|
||||
onClick {
|
||||
context.toast(R.string.starting_cleanup)
|
||||
(activity as? AppCompatActivity)?.lifecycleScope?.launchIO {
|
||||
coverCache.deleteOldCovers()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
|
@ -331,8 +385,40 @@ class SettingsDataController : SettingsLegacyController() {
|
|||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun clearChapterCache() {
|
||||
if (activity == null) return
|
||||
viewScope.launchIO {
|
||||
val files = chapterCache.cacheDir.listFiles() ?: return@launchIO
|
||||
var deletedFiles = 0
|
||||
try {
|
||||
files.forEach { file ->
|
||||
if (chapterCache.removeFileFromCache(file.name)) {
|
||||
deletedFiles++
|
||||
}
|
||||
}
|
||||
withUIContext {
|
||||
activity?.toast(
|
||||
resources?.getQuantityString(
|
||||
R.plurals.cache_cleared,
|
||||
deletedFiles,
|
||||
deletedFiles,
|
||||
),
|
||||
)
|
||||
findPreference(CLEAR_CACHE_KEY)?.summary =
|
||||
resources?.getString(R.string.used_, chapterCache.readableSize)
|
||||
}
|
||||
} catch (_: Exception) {
|
||||
withUIContext {
|
||||
activity?.toast(R.string.cache_delete_error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private const val CLEAR_CACHE_KEY = "pref_clear_cache_key"
|
||||
|
||||
private const val CODE_DATA_DIR = 104
|
||||
private const val CODE_BACKUP_CREATE = 504
|
||||
private const val CODE_BACKUP_RESTORE = 505
|
||||
|
|
|
@ -14,8 +14,6 @@ import eu.kanade.tachiyomi.ui.setting.defaultValue
|
|||
import eu.kanade.tachiyomi.ui.setting.infoPreference
|
||||
import eu.kanade.tachiyomi.ui.setting.intListPreference
|
||||
import eu.kanade.tachiyomi.ui.setting.multiSelectListPreferenceMat
|
||||
import eu.kanade.tachiyomi.ui.setting.onClick
|
||||
import eu.kanade.tachiyomi.ui.setting.preference
|
||||
import eu.kanade.tachiyomi.ui.setting.preferenceCategory
|
||||
import eu.kanade.tachiyomi.ui.setting.summaryRes
|
||||
import eu.kanade.tachiyomi.ui.setting.switchPreference
|
||||
|
@ -34,12 +32,6 @@ class SettingsDownloadController : SettingsLegacyController() {
|
|||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||
titleRes = R.string.downloads
|
||||
|
||||
preference {
|
||||
titleRes = R.string.download_location
|
||||
onClick { navigateTo(SettingsDataController()) }
|
||||
|
||||
summary = "Moved to Data and Storage!"
|
||||
}
|
||||
switchPreference {
|
||||
key = Keys.downloadOnlyOverWifi
|
||||
titleRes = R.string.only_download_over_wifi
|
||||
|
|
|
@ -799,6 +799,7 @@
|
|||
<!-- Storage -->
|
||||
<string name="data_and_storage">Data and storage</string>
|
||||
<string name="storage_location">Storage location</string>
|
||||
<string name="storage_usage">Storage usage</string>
|
||||
|
||||
<!-- Backup -->
|
||||
<string name="backup">Backup</string>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue