Working geofavorites

This commit is contained in:
Daniele Verducci (Slimpenguin)
2024-02-20 14:02:51 +01:00
parent fd4a9c1f5d
commit 739399f54b
7 changed files with 225 additions and 14 deletions
@@ -1,12 +1,17 @@
package it.danieleverducci.nextcloudmaps.utils;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.preference.PreferenceManager;
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_LAST_SELECTED_LIST_VIEW = "SETTING_LAST_SELECTED_LIST_VIEW";
static private final String SETTING_LAST_MAP_POSITION_LAT = "SETTING_LAST_MAP_POSITION_LAT";
static private final String SETTING_LAST_MAP_POSITION_LNG = "SETTING_LAST_MAP_POSITION_LNG";
static private final String SETTING_LAST_MAP_POSITION_ZOOM = "SETTING_LAST_MAP_POSITION_ZOOM";
public static int getGeofavoriteListSortBy(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
@@ -27,4 +32,26 @@ public class SettingsManager {
PreferenceManager.getDefaultSharedPreferences(context)
.edit().putBoolean(SETTING_LAST_SELECTED_LIST_VIEW, value).apply();
}
/**
* Returns the last saved position
* @param context
* @return double[lat,lng,zoom]
*/
public static double[] getLastMapPosition(Context context) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
return new double[] {
(double) sp.getFloat(SETTING_LAST_MAP_POSITION_LAT, 0.0f),
(double) sp.getFloat(SETTING_LAST_MAP_POSITION_LNG, 0.0f),
(double) sp.getFloat(SETTING_LAST_MAP_POSITION_ZOOM, 10.0f),
};
}
public static void setLastMapPosition(Context context, double lat, double lng, double zoom) {
PreferenceManager.getDefaultSharedPreferences(context).edit()
.putFloat(SETTING_LAST_MAP_POSITION_LAT, (float)lat)
.putFloat(SETTING_LAST_MAP_POSITION_LNG, (float)lng)
.putFloat(SETTING_LAST_MAP_POSITION_ZOOM, (float)zoom)
.apply();
}
}