|
@@ -9,9 +9,9 @@ import android.webkit.WebView
|
|
|
import androidx.core.net.toUri
|
|
|
import androidx.preference.PreferenceScreen
|
|
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
|
+import eu.kanade.domain.manga.repository.MangaRepository
|
|
|
import eu.kanade.tachiyomi.R
|
|
|
import eu.kanade.tachiyomi.data.cache.ChapterCache
|
|
|
-import eu.kanade.tachiyomi.data.database.DatabaseHelper
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
|
@@ -25,6 +25,7 @@ import eu.kanade.tachiyomi.ui.base.controller.pushController
|
|
|
import eu.kanade.tachiyomi.ui.setting.database.ClearDatabaseController
|
|
|
import eu.kanade.tachiyomi.util.CrashLogUtil
|
|
|
import eu.kanade.tachiyomi.util.lang.launchIO
|
|
|
+import eu.kanade.tachiyomi.util.lang.withIOContext
|
|
|
import eu.kanade.tachiyomi.util.lang.withUIContext
|
|
|
import eu.kanade.tachiyomi.util.preference.bindTo
|
|
|
import eu.kanade.tachiyomi.util.preference.defaultValue
|
|
@@ -45,17 +46,21 @@ import eu.kanade.tachiyomi.util.system.logcat
|
|
|
import eu.kanade.tachiyomi.util.system.powerManager
|
|
|
import eu.kanade.tachiyomi.util.system.setDefaultSettings
|
|
|
import eu.kanade.tachiyomi.util.system.toast
|
|
|
+import kotlinx.coroutines.runBlocking
|
|
|
import logcat.LogPriority
|
|
|
import rikka.sui.Sui
|
|
|
+import uy.kohesive.injekt.Injekt
|
|
|
+import uy.kohesive.injekt.api.get
|
|
|
import uy.kohesive.injekt.injectLazy
|
|
|
import java.io.File
|
|
|
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
|
|
|
|
|
-class SettingsAdvancedController : SettingsController() {
|
|
|
+class SettingsAdvancedController(
|
|
|
+ private val mangaRepository: MangaRepository = Injekt.get()
|
|
|
+) : SettingsController() {
|
|
|
|
|
|
private val network: NetworkHelper by injectLazy()
|
|
|
private val chapterCache: ChapterCache by injectLazy()
|
|
|
- private val db: DatabaseHelper by injectLazy()
|
|
|
|
|
|
@SuppressLint("BatteryLife")
|
|
|
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
|
@@ -216,6 +221,13 @@ class SettingsAdvancedController : SettingsController() {
|
|
|
|
|
|
onClick { LibraryUpdateService.start(context, target = Target.TRACKING) }
|
|
|
}
|
|
|
+ preference {
|
|
|
+ key = "pref_reset_viewer_flags"
|
|
|
+ titleRes = R.string.pref_reset_viewer_flags
|
|
|
+ summaryRes = R.string.pref_reset_viewer_flags_summary
|
|
|
+
|
|
|
+ onClick { resetViewerFlags() }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
preferenceCategory {
|
|
@@ -276,37 +288,52 @@ class SettingsAdvancedController : SettingsController() {
|
|
|
}
|
|
|
|
|
|
private fun clearChapterCache() {
|
|
|
- if (activity == null) return
|
|
|
+ val activity = activity ?: return
|
|
|
launchIO {
|
|
|
try {
|
|
|
val deletedFiles = chapterCache.clear()
|
|
|
withUIContext {
|
|
|
- activity?.toast(resources?.getString(R.string.cache_deleted, deletedFiles))
|
|
|
+ activity.toast(resources?.getString(R.string.cache_deleted, deletedFiles))
|
|
|
findPreference(CLEAR_CACHE_KEY)?.summary =
|
|
|
resources?.getString(R.string.used_cache, chapterCache.readableSize)
|
|
|
}
|
|
|
} catch (e: Throwable) {
|
|
|
logcat(LogPriority.ERROR, e)
|
|
|
- withUIContext { activity?.toast(R.string.cache_delete_error) }
|
|
|
+ withUIContext { activity.toast(R.string.cache_delete_error) }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private fun clearWebViewData() {
|
|
|
- if (activity == null) return
|
|
|
+ val activity = activity ?: return
|
|
|
try {
|
|
|
- val webview = WebView(activity!!)
|
|
|
+ val webview = WebView(activity)
|
|
|
webview.setDefaultSettings()
|
|
|
webview.clearCache(true)
|
|
|
webview.clearFormData()
|
|
|
webview.clearHistory()
|
|
|
webview.clearSslPreferences()
|
|
|
WebStorage.getInstance().deleteAllData()
|
|
|
- activity?.applicationInfo?.dataDir?.let { File("$it/app_webview/").deleteRecursively() }
|
|
|
- activity?.toast(R.string.webview_data_deleted)
|
|
|
+ activity.applicationInfo?.dataDir?.let { File("$it/app_webview/").deleteRecursively() }
|
|
|
+ activity.toast(R.string.webview_data_deleted)
|
|
|
} catch (e: Throwable) {
|
|
|
logcat(LogPriority.ERROR, e)
|
|
|
- activity?.toast(R.string.cache_delete_error)
|
|
|
+ activity.toast(R.string.cache_delete_error)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun resetViewerFlags() {
|
|
|
+ val activity = activity ?: return
|
|
|
+ launchIO {
|
|
|
+ val isSuccesful = mangaRepository.resetViewerFlags()
|
|
|
+ withUIContext {
|
|
|
+ val resouurceString = if (isSuccesful) {
|
|
|
+ R.string.pref_reset_viewer_flags_succesful
|
|
|
+ } else {
|
|
|
+ R.string.pref_reset_viewer_flags_unsuccesful
|
|
|
+ }
|
|
|
+ activity.toast(resouurceString)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|