Skip to content

Commit

Permalink
Clear WebView cache (#3605)
Browse files Browse the repository at this point in the history
Use the existing 'Clear image cache' setting, rename it and move it to the trouble shooting section.

It might help in some situations, like #3601

Signed-off-by: mueller-ma <[email protected]>
  • Loading branch information
mueller-ma authored Mar 2, 2024
1 parent 954d70a commit 9bc6f26
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.os.Build
import android.os.Bundle
import android.provider.Settings
import android.util.Log
import android.webkit.WebView
import androidx.activity.result.contract.ActivityResultContracts
import androidx.annotation.RequiresApi
import androidx.annotation.StringRes
Expand Down Expand Up @@ -112,7 +113,6 @@ class MainSettingsFragment : AbstractSettingsFragment(), ConnectionFactory.Updat
val drawerEntriesPrefs = getPreference(PrefKeys.DRAWER_ENTRIES)
val themePref = getPreference(PrefKeys.THEME)
val colorSchemePref = getPreference(PrefKeys.COLOR_SCHEME) as ListPreference
val clearCachePref = getPreference(PrefKeys.CLEAR_CACHE)
val fullscreenPref = getPreference(PrefKeys.FULLSCREEN)
val launcherPref = getPreference(PrefKeys.LAUNCHER)
val iconFormatPref = getPreference(PrefKeys.ICON_FORMAT)
Expand Down Expand Up @@ -194,8 +194,8 @@ class MainSettingsFragment : AbstractSettingsFragment(), ConnectionFactory.Updat
true
}

clearCachePref.setOnPreferenceClickListener { pref ->
clearImageCache(pref.context)
getPreference(PrefKeys.CLEAR_CACHE).setOnPreferenceClickListener { pref ->
clearCaches(pref.context)
true
}

Expand Down Expand Up @@ -308,7 +308,7 @@ class MainSettingsFragment : AbstractSettingsFragment(), ConnectionFactory.Updat
} else {
iconFormatPref.setOnPreferenceChangeListener { pref, _ ->
val context = pref.context
clearImageCache(context)
clearCaches(context)
ItemUpdateWidget.updateAllWidgets(context)
true
}
Expand Down Expand Up @@ -349,7 +349,8 @@ class MainSettingsFragment : AbstractSettingsFragment(), ConnectionFactory.Updat
}
}

private fun clearImageCache(context: Context) {
private fun clearCaches(context: Context) {
WebView(context).clearCache(true)
// Get launch intent for application
val restartIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)
restartIntent?.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/java/org/openhab/habdroid/util/PrefKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object PrefKeys {
const val SITEMAP_COMPACT_MODE = "sitemap_compact_mode"
const val SHOW_ICONS = "show_icons"
const val ICON_FORMAT = "iconFormatType"
const val CLEAR_CACHE = "default_openhab_cleacache"
const val CLEAR_CACHE = "default_openhab_clear_cache"
const val CHART_SCALING = "chartScalingFactor"
const val CHART_HQ = "default_openhab_chart_hq"
const val IMAGE_WIDGET_SCALE_TO_FIT = "imageWidgetScaleToFit"
Expand Down
2 changes: 1 addition & 1 deletion mobile/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<string name="main_ui_error">An error occurred while loading Main UI</string>
<string name="frontail_error">An error occurred while loading Frontail. Please note that it\'s not available via openHAB Cloud.</string>
<string name="mainmenu_openhab_selectsitemap">Select default Sitemap</string>
<string name="mainmenu_openhab_clearcache">Clear images cache</string>
<string name="settings_clear_caches">Clear cache</string>

<!-- App settings strings -->
<string name="settings_connection_title">Connection</string>
Expand Down
8 changes: 4 additions & 4 deletions mobile/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@
android:entries="@array/iconTypeNames"
android:entryValues="@array/iconTypeValues"
android:icon="@drawable/ic_image_outline_grey_24dp" />
<Preference
android:clickable="true"
android:key="default_openhab_cleacache"
android:title="@string/mainmenu_openhab_clearcache" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:key="imageWidgetScaleToFit"
Expand Down Expand Up @@ -185,6 +181,10 @@
android:summaryOff="@string/data_saver_off" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_troubleshooting_title">
<Preference
android:clickable="true"
android:key="default_openhab_clear_cache"
android:title="@string/settings_clear_caches" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:key="default_openhab_debug_messages"
Expand Down

0 comments on commit 9bc6f26

Please sign in to comment.