From d94620328b86fe0d38f67d32ed2cf63d8b8fe750 Mon Sep 17 00:00:00 2001 From: andrekir Date: Thu, 8 Sep 2022 17:34:00 -0300 Subject: [PATCH] handle prefs ArrayIndexOutOfBoundsException --- .../main/java/com/geeksville/mesh/ui/MapFragment.kt | 12 +++++------- app/src/main/res/values-pl/arrays.xml | 13 ------------- 2 files changed, 5 insertions(+), 20 deletions(-) delete mode 100644 app/src/main/res/values-pl/arrays.xml diff --git a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt index 3f2742b72..e97bedc11 100644 --- a/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt +++ b/app/src/main/java/com/geeksville/mesh/ui/MapFragment.kt @@ -95,9 +95,8 @@ class MapFragment : ScreenFragment("Map"), Logging { val mapStyles by lazy { resources.getStringArray(R.array.map_styles) } /// Load preferences and its value - val prefs = UIViewModel.getPreferences(context!!) - val editor: SharedPreferences.Editor = prefs.edit() - val mapStyleInt = prefs.getInt(mapStyleId, 1) + val editor: SharedPreferences.Editor = mPrefs.edit() + val mapStyleInt = mPrefs.getInt(mapStyleId, 1) debug("mapStyleId from prefs: $mapStyleInt") builder.setSingleChoiceItems(mapStyles, mapStyleInt) { dialog, which -> @@ -210,10 +209,9 @@ class MapFragment : ScreenFragment("Map"), Logging { } private fun loadOnlineTileSourceBase(): ITileSource { - val prefs = context?.getSharedPreferences(uiPrefs, Context.MODE_PRIVATE) - val mapSourceId = prefs?.getInt(mapStyleId, 1) - debug("mapStyleId from prefs: $mapSourceId") - return CustomTileSource.mTileSources[mapSourceId!!] + val id = mPrefs.getInt(mapStyleId, 1) + debug("mapStyleId from prefs: $id") + return CustomTileSource.mTileSources.getOrNull(id) ?: CustomTileSource.DEFAULT_TILE_SOURCE } override fun onPause() { diff --git a/app/src/main/res/values-pl/arrays.xml b/app/src/main/res/values-pl/arrays.xml deleted file mode 100644 index c9a2f062c..000000000 --- a/app/src/main/res/values-pl/arrays.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - Ulice - Teren - Jasny - Ciemny - Satelita - Satelita (wraz z ulicami) - Natężenie ruchu (jasny) - Natężenie ruchu (ciemy) - - \ No newline at end of file