mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Add advanced setting to clear WebView data
This commit is contained in:
		| @@ -4,6 +4,8 @@ import android.annotation.SuppressLint | ||||
| import android.content.ActivityNotFoundException | ||||
| import android.content.Intent | ||||
| import android.provider.Settings | ||||
| import android.webkit.WebStorage | ||||
| import android.webkit.WebView | ||||
| import androidx.core.net.toUri | ||||
| import androidx.preference.PreferenceScreen | ||||
| import com.google.android.material.dialog.MaterialAlertDialogBuilder | ||||
| @@ -39,8 +41,11 @@ import eu.kanade.tachiyomi.util.preference.switchPreference | ||||
| import eu.kanade.tachiyomi.util.preference.titleRes | ||||
| import eu.kanade.tachiyomi.util.system.DeviceUtil | ||||
| import eu.kanade.tachiyomi.util.system.isPackageInstalled | ||||
| 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 logcat.LogPriority | ||||
| import rikka.sui.Sui | ||||
| import uy.kohesive.injekt.injectLazy | ||||
| import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys | ||||
| @@ -139,6 +144,12 @@ class SettingsAdvancedController : SettingsController() { | ||||
|                 titleRes = R.string.pref_auto_clear_chapter_cache | ||||
|                 defaultValue = false | ||||
|             } | ||||
|             preference { | ||||
|                 key = "pref_clear_webview_data" | ||||
|                 titleRes = R.string.pref_clear_webview_data | ||||
|  | ||||
|                 onClick { clearWebViewData() } | ||||
|             } | ||||
|             preference { | ||||
|                 key = "pref_clear_database" | ||||
|                 titleRes = R.string.pref_clear_database | ||||
| @@ -275,10 +286,28 @@ class SettingsAdvancedController : SettingsController() { | ||||
|                         resources?.getString(R.string.used_cache, chapterCache.readableSize) | ||||
|                 } | ||||
|             } catch (e: Throwable) { | ||||
|                 logcat(LogPriority.ERROR, e) | ||||
|                 withUIContext { activity?.toast(R.string.cache_delete_error) } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun clearWebViewData() { | ||||
|         if (activity == null) return | ||||
|         try { | ||||
|             val webview = WebView(activity!!) | ||||
|             webview.setDefaultSettings() | ||||
|             webview.clearCache(true) | ||||
|             webview.clearFormData() | ||||
|             webview.clearHistory() | ||||
|             webview.clearSslPreferences() | ||||
|             WebStorage.getInstance().deleteAllData() | ||||
|             activity?.toast(R.string.webview_data_deleted) | ||||
|         } catch (e: Throwable) { | ||||
|             logcat(LogPriority.ERROR, e) | ||||
|             activity?.toast(R.string.cache_delete_error) | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  | ||||
| private const val CLEAR_CACHE_KEY = "pref_clear_cache_key" | ||||
|   | ||||
		Reference in New Issue
	
	Block a user