@@ -16,8 +16,10 @@ import androidx.appcompat.widget.SwitchCompat
1616import androidx.fragment.app.DialogFragment
1717import androidx.localbroadcastmanager.content.LocalBroadcastManager
1818import androidx.preference.PreferenceManager
19+ import android.content.SharedPreferences
1920import org.osmdroid.config.Configuration
2021import java.io.File
22+ import androidx.core.content.edit
2123
2224
2325class CacheSettingsFragment : DialogFragment () {
@@ -30,18 +32,21 @@ class CacheSettingsFragment : DialogFragment() {
3032 val inflater = requireActivity().layoutInflater
3133 @SuppressLint(" InflateParams" ) val view =
3234 inflater.inflate(R .layout.fragment_cache_settings, null )
33- val prefs = PreferenceManager .getDefaultSharedPreferences(requireActivity().applicationContext)
35+ val defaultPrefs = PreferenceManager .getDefaultSharedPreferences(requireActivity().applicationContext)
36+ val cachePrefs: SharedPreferences = requireActivity().getSharedPreferences(" cache_prefs" , Context .MODE_PRIVATE )
3437 val tvExternalStorageRoot = view.findViewById<TextView >(R .id.tvExternalStorageRoot)
3538 val swExternalStorage = view.findViewById<SwitchCompat >(R .id.swExternalStorage)
3639 etTileCache = view.findViewById(R .id.etTileCache)
3740 etCacheSize = view.findViewById(R .id.etCacheSize)
3841 val basePath = Configuration .getInstance().osmdroidBasePath
3942 val storageRoot = basePath?.absolutePath ? : getString(R .string.unknown_symbol)
4043 tvExternalStorageRoot.text = getString(R .string.storage_root, storageRoot)
41- val currentExternalStorage = prefs.getBoolean(PREF_EXTERNAL_STORAGE , false )
44+ val currentExternalStorage = cachePrefs.getBoolean(PREF_EXTERNAL_STORAGE ,
45+ defaultPrefs.getBoolean(PREF_EXTERNAL_STORAGE , false )
46+ )
4247 swExternalStorage.isChecked = currentExternalStorage
43- val currentTileCache = prefs .getString(PREF_TILE_CACHE , DEFAULT_TILE_CACHE )
44- val currentCacheSize = prefs .getInt(PREF_CACHE_SIZE , DEFAULT_CACHE_SIZE )
48+ val currentTileCache = defaultPrefs .getString(PREF_TILE_CACHE , DEFAULT_TILE_CACHE )
49+ val currentCacheSize = defaultPrefs .getInt(PREF_CACHE_SIZE , DEFAULT_CACHE_SIZE )
4550 etTileCache.setText(currentTileCache)
4651 etCacheSize.setText(currentCacheSize.toString())
4752 builder.setView(view)
@@ -56,13 +61,12 @@ class CacheSettingsFragment : DialogFragment() {
5661 }
5762
5863 if (newCacheSize > 0 ) {
59- val editor = prefs.edit()
60- editor.apply {
61- putBoolean(PREF_EXTERNAL_STORAGE , newExternalStorage)
64+ defaultPrefs.edit().apply {
6265 putString(PREF_TILE_CACHE , newTileCache)
6366 putInt(PREF_CACHE_SIZE , newCacheSize)
6467 apply ()
6568 }
69+ cachePrefs.edit { putBoolean(PREF_EXTERNAL_STORAGE , newExternalStorage) }
6670 val cacheDir = File (" $storageRoot /$newTileCache " )
6771 if (cacheDir.mkdirs()) {
6872 Log .i(TAG , " Tile cache created: $newTileCache " )
@@ -71,7 +75,7 @@ class CacheSettingsFragment : DialogFragment() {
7175 configuration.osmdroidTileCache = cacheDir
7276 configuration.tileFileSystemCacheMaxBytes =
7377 newCacheSize.toLong() * 1024 * 1024
74- configuration.save(requireActivity().applicationContext, prefs )
78+ configuration.save(requireActivity().applicationContext, defaultPrefs )
7579 val intent = Intent (ACTION_CACHE_CHANGED );
7680 val localBroadcastManager = LocalBroadcastManager .getInstance(
7781 requireActivity()
@@ -94,7 +98,6 @@ class CacheSettingsFragment : DialogFragment() {
9498 return dialog
9599 }
96100
97-
98101 override fun onResume () {
99102 super .onResume()
100103 val dialog = dialog as AlertDialog ?
0 commit comments