Merge pull request #2715 from deltachat/adb/issue-2714

save map preferences per account, not only per chat id
This commit is contained in:
Asiel Díaz Benítez
2023-10-04 16:31:07 -04:00
committed by GitHub
3 changed files with 19 additions and 14 deletions
@@ -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) {
@@ -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) {
+10 -10
View File
@@ -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);
}