From 6bd0b972579e364605f5d155e895633a73bf3b3e Mon Sep 17 00:00:00 2001 From: adbenitez Date: Wed, 4 Oct 2023 15:38:56 +0200 Subject: [PATCH] save map preferences per account, not only per chat id --- .../securesms/map/MapActivity.java | 9 +++++---- .../securesms/map/MapDataManager.java | 4 ++++ .../thoughtcrime/securesms/util/Prefs.java | 20 +++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/org/thoughtcrime/securesms/map/MapActivity.java b/src/org/thoughtcrime/securesms/map/MapActivity.java index 3ec93678d..889d4ebce 100644 --- a/src/org/thoughtcrime/securesms/map/MapActivity.java +++ b/src/org/thoughtcrime/securesms/map/MapActivity.java @@ -120,9 +120,10 @@ public class MapActivity extends BaseActivity implements Observer, inputAwareContainer.addOnKeyboardHiddenListener(this); inputAwareContainer.addOnKeyboardShownListener(this); - final LatLng lastMapCenter = Prefs.getMapCenter(this.getApplicationContext(), chatId); + final int accountId = DcHelper.getContext(this.getApplicationContext()).getAccountId(); + final LatLng lastMapCenter = Prefs.getMapCenter(this.getApplicationContext(), accountId, chatId); if (lastMapCenter != null) { - double lastZoom = Prefs.getMapZoom(this.getApplicationContext(), chatId); + double lastZoom = Prefs.getMapZoom(this.getApplicationContext(), accountId, chatId); mapboxMap.setCameraPosition(new CameraPosition.Builder() .target(lastMapCenter) .zoom(lastZoom) @@ -215,8 +216,8 @@ public class MapActivity extends BaseActivity implements Observer, protected void onDestroy() { super.onDestroy(); if (mapDataManager != null) { - Prefs.setMapCenter(this.getApplicationContext(), mapDataManager.getChatId(), mapboxMap.getCameraPosition().target); - Prefs.setMapZoom(this.getApplicationContext(), mapDataManager.getChatId(), mapboxMap.getCameraPosition().zoom); + Prefs.setMapCenter(this.getApplicationContext(), mapDataManager.getAccountId(), mapDataManager.getChatId(), mapboxMap.getCameraPosition().target); + Prefs.setMapZoom(this.getApplicationContext(), mapDataManager.getAccountId(), mapDataManager.getChatId(), mapboxMap.getCameraPosition().zoom); mapDataManager.onDestroy(); } if (markerViewManager != null) { diff --git a/src/org/thoughtcrime/securesms/map/MapDataManager.java b/src/org/thoughtcrime/securesms/map/MapDataManager.java index 39df85a96..c12d20ad7 100644 --- a/src/org/thoughtcrime/securesms/map/MapDataManager.java +++ b/src/org/thoughtcrime/securesms/map/MapDataManager.java @@ -343,6 +343,10 @@ public class MapDataManager implements DcEventCenter.DcEventDelegate, return chatId; } + public int getAccountId() { + return dcContext.getAccountId(); + } + private void showLineLayer(MapSource source) { LineLayer lineLayer = (LineLayer) mapboxStyle.getLayer(source.getLineLayer()); if (lineLayer != null) { diff --git a/src/org/thoughtcrime/securesms/util/Prefs.java b/src/org/thoughtcrime/securesms/util/Prefs.java index c127de055..1ee7deb98 100644 --- a/src/org/thoughtcrime/securesms/util/Prefs.java +++ b/src/org/thoughtcrime/securesms/util/Prefs.java @@ -281,26 +281,26 @@ public class Prefs { // map - public static void setMapCenter(Context context, int chatId, LatLng latLng) { - setLongPreference(context, MAP_CENTER_LATITUDE+chatId, Double.doubleToRawLongBits(latLng.getLatitude())); - setLongPreference(context, MAP_CENTER_LONGITUDE+chatId, Double.doubleToRawLongBits(latLng.getLongitude())); + public static void setMapCenter(Context context, int accountId, int chatId, LatLng latLng) { + setLongPreference(context, MAP_CENTER_LATITUDE+accountId+"."+chatId, Double.doubleToRawLongBits(latLng.getLatitude())); + setLongPreference(context, MAP_CENTER_LONGITUDE+accountId+"."+chatId, Double.doubleToRawLongBits(latLng.getLongitude())); } - public static void setMapZoom(Context context, int chatId, double zoom) { - setLongPreference(context, MAP_ZOOM+chatId, Double.doubleToRawLongBits(zoom)); + public static void setMapZoom(Context context, int accountId, int chatId, double zoom) { + setLongPreference(context, MAP_ZOOM+accountId+"."+chatId, Double.doubleToRawLongBits(zoom)); } - public static LatLng getMapCenter(Context context, int chatId) { - long latitude = getLongPreference(context, MAP_CENTER_LATITUDE+chatId, Long.MAX_VALUE); - long longitude = getLongPreference(context, MAP_CENTER_LONGITUDE+chatId, Long.MAX_VALUE); + public static LatLng getMapCenter(Context context, int accountId, int chatId) { + long latitude = getLongPreference(context, MAP_CENTER_LATITUDE+accountId+"."+chatId, Long.MAX_VALUE); + long longitude = getLongPreference(context, MAP_CENTER_LONGITUDE+accountId+"."+chatId, Long.MAX_VALUE); if (latitude == Long.MAX_VALUE || longitude == Long.MAX_VALUE) { return null; } return new LatLng(Double.longBitsToDouble(latitude), Double.longBitsToDouble(longitude)); } - public static double getMapZoom(Context context, int chatId) { - long zoom = getLongPreference(context, MAP_ZOOM+chatId, Double.doubleToLongBits(MINIMUM_ZOOM)); + public static double getMapZoom(Context context, int accountId, int chatId) { + long zoom = getLongPreference(context, MAP_ZOOM+accountId+"."+chatId, Double.doubleToLongBits(MINIMUM_ZOOM)); return Double.longBitsToDouble(zoom); }