Moved shared preferences in their own class

This commit is contained in:
Daniele Verducci (Slimpenguin) 2024-02-17 06:58:35 +01:00
parent 367d6d0a74
commit a1d6f1dabe
4 changed files with 48 additions and 10 deletions

View File

@ -61,6 +61,7 @@ import it.danieleverducci.nextcloudmaps.api.ApiProvider;
import it.danieleverducci.nextcloudmaps.model.Geofavorite; import it.danieleverducci.nextcloudmaps.model.Geofavorite;
import it.danieleverducci.nextcloudmaps.utils.GeoUriParser; import it.danieleverducci.nextcloudmaps.utils.GeoUriParser;
import it.danieleverducci.nextcloudmaps.utils.IntentGenerator; import it.danieleverducci.nextcloudmaps.utils.IntentGenerator;
import it.danieleverducci.nextcloudmaps.utils.SettingsManager;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
@ -106,8 +107,9 @@ public class MainActivity extends NextcloudMapsStyledActivity implements OnSorti
preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
int sortRule = preferences.getInt(getString(R.string.setting_sort_by), SORT_BY_CREATED);
boolean gridViewEnabled = preferences.getBoolean(getString(R.string.setting_grid_view_enabled), false); int sortRule = SettingsManager.getGeofavoriteListSortBy(this);
boolean gridViewEnabled = SettingsManager.isGeofavoriteListShownAsGrid(this);
recyclerView = findViewById(R.id.recycler_view); recyclerView = findViewById(R.id.recycler_view);
layoutManager = new StaggeredGridLayoutManager(gridViewEnabled ? 2 : 1, StaggeredGridLayoutManager.VERTICAL); layoutManager = new StaggeredGridLayoutManager(gridViewEnabled ? 2 : 1, StaggeredGridLayoutManager.VERTICAL);

View File

@ -0,0 +1,44 @@
package it.danieleverducci.nextcloudmaps.utils;
import android.content.Context;
import androidx.preference.PreferenceManager;
import it.danieleverducci.nextcloudmaps.R;
import it.danieleverducci.nextcloudmaps.activity.main.GeofavoriteAdapter;
public class SettingsManager {
static private final String SETTING_SORT_BY = "SETTING_SORT_BY";
static private final String SETTING_GRID_VIEW_ENABLED = "SETTING_GRID_VIEW_ENABLED";
static private final String SETTING_LAST_SELECTED_LIST_VIEW = "SETTING_LAST_SELECTED_LIST_VIEW";
public static int getGeofavoriteListSortBy(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getInt(SETTING_SORT_BY, GeofavoriteAdapter.SORT_BY_CREATED);
}
public static void setGeofavoriteListSortBy(Context context, int value) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit().putInt(SETTING_SORT_BY, value).apply();
}
public static boolean isGeofavoriteListShownAsGrid(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(SETTING_GRID_VIEW_ENABLED, false);
}
public static void setGeofavoriteListShownAsGrid(Context context, boolean value) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit().putBoolean(SETTING_GRID_VIEW_ENABLED, value).apply();
}
public static boolean isGeofavoriteListShownAsMap(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getBoolean(SETTING_LAST_SELECTED_LIST_VIEW, false);
}
public static void setGeofavoriteListShownAsMap(Context context, boolean value) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit().putBoolean(SETTING_LAST_SELECTED_LIST_VIEW, value).apply();
}
}

View File

@ -93,10 +93,6 @@
<string name="url_license" translatable="false">https://raw.githubusercontent.com/penguin86/nextcloud-maps-client/master/LICENSE</string> <string name="url_license" translatable="false">https://raw.githubusercontent.com/penguin86/nextcloud-maps-client/master/LICENSE</string>
<string name="url_maps" translatable="false">https://donate.openstreetmap.org</string> <string name="url_maps" translatable="false">https://donate.openstreetmap.org</string>
<!-- Settings -->
<string name="setting_sort_by">SETTING_SORT_BY</string>
<string name="setting_grid_view_enabled">SETTING_GRID_VIEW_ENABLED</string>
<!-- Menu --> <!-- Menu -->
<string name="new_geobookmark_gps">Crea dalla posizione corrente</string> <string name="new_geobookmark_gps">Crea dalla posizione corrente</string>
<string name="new_geobookmark_map">Crea dalla mappa</string> <string name="new_geobookmark_map">Crea dalla mappa</string>

View File

@ -92,10 +92,6 @@
<string name="url_license" translatable="false">https://raw.githubusercontent.com/penguin86/nextcloud-maps-client/master/LICENSE</string> <string name="url_license" translatable="false">https://raw.githubusercontent.com/penguin86/nextcloud-maps-client/master/LICENSE</string>
<string name="url_maps" translatable="false">https://donate.openstreetmap.org</string> <string name="url_maps" translatable="false">https://donate.openstreetmap.org</string>
<!-- Settings -->
<string name="setting_sort_by">SETTING_SORT_BY</string>
<string name="setting_grid_view_enabled">SETTING_GRID_VIEW_ENABLED</string>
<!-- Menu --> <!-- Menu -->
<string name="new_geobookmark_gps">New from current position</string> <string name="new_geobookmark_gps">New from current position</string>
<string name="new_geobookmark_map">New from map</string> <string name="new_geobookmark_map">New from map</string>