|
|
|
|
@ -1,7 +1,6 @@
|
|
|
|
|
package org.koitharu.kotatsu.ui.settings
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
|
import androidx.preference.Preference
|
|
|
|
|
import com.google.android.material.snackbar.Snackbar
|
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
|
@ -16,6 +15,7 @@ import org.koitharu.kotatsu.ui.search.MangaSuggestionsProvider
|
|
|
|
|
import org.koitharu.kotatsu.utils.CacheUtils
|
|
|
|
|
import org.koitharu.kotatsu.utils.FileSizeUtils
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
|
|
|
import org.koitharu.kotatsu.utils.ext.viewLifecycleScope
|
|
|
|
|
|
|
|
|
|
class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cache) {
|
|
|
|
|
|
|
|
|
|
@ -24,7 +24,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
|
addPreferencesFromResource(R.xml.pref_history)
|
|
|
|
|
findPreference<Preference>(R.string.key_pages_cache_clear)?.let { pref ->
|
|
|
|
|
lifecycleScope.launchWhenResumed {
|
|
|
|
|
viewLifecycleScope.launchWhenResumed {
|
|
|
|
|
val size = withContext(Dispatchers.IO) {
|
|
|
|
|
CacheUtils.computeCacheSize(pref.context, Cache.PAGES.dir)
|
|
|
|
|
}
|
|
|
|
|
@ -32,7 +32,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
findPreference<Preference>(R.string.key_thumbs_cache_clear)?.let { pref ->
|
|
|
|
|
lifecycleScope.launchWhenResumed {
|
|
|
|
|
viewLifecycleScope.launchWhenResumed {
|
|
|
|
|
val size = withContext(Dispatchers.IO) {
|
|
|
|
|
CacheUtils.computeCacheSize(pref.context, Cache.THUMBS.dir)
|
|
|
|
|
}
|
|
|
|
|
@ -44,7 +44,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|
|
|
|
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
|
|
|
|
|
}
|
|
|
|
|
findPreference<Preference>(R.string.key_updates_feed_clear)?.let { p ->
|
|
|
|
|
lifecycleScope.launchWhenResumed {
|
|
|
|
|
viewLifecycleScope.launchWhenResumed {
|
|
|
|
|
val items = trackerRepo.count()
|
|
|
|
|
p.summary = p.context.resources.getQuantityString(R.plurals.items, items, items)
|
|
|
|
|
}
|
|
|
|
|
@ -73,7 +73,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
getString(R.string.key_updates_feed_clear) -> {
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
|
viewLifecycleScope.launch {
|
|
|
|
|
trackerRepo.clearLogs()
|
|
|
|
|
preference.summary = preference.context.resources
|
|
|
|
|
.getQuantityString(R.plurals.items, 0, 0)
|
|
|
|
|
@ -91,7 +91,7 @@ class HistorySettingsFragment : BasePreferenceFragment(R.string.history_and_cach
|
|
|
|
|
|
|
|
|
|
private fun clearCache(preference: Preference, cache: Cache) {
|
|
|
|
|
val ctx = preference.context.applicationContext
|
|
|
|
|
lifecycleScope.launch {
|
|
|
|
|
viewLifecycleScope.launch {
|
|
|
|
|
try {
|
|
|
|
|
preference.isEnabled = false
|
|
|
|
|
val size = withContext(Dispatchers.IO) {
|
|
|
|
|
|