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
@@ -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();
}
}