Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save map preferences per account, not only per chat id #2715

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/org/thoughtcrime/securesms/map/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ protected void onCreate(Bundle savedInstanceState) {
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)
Expand Down Expand Up @@ -215,8 +216,8 @@ protected void onPause() {
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) {
Expand Down
4 changes: 4 additions & 0 deletions src/org/thoughtcrime/securesms/map/MapDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,10 @@ public int getChatId() {
return chatId;
}

public int getAccountId() {
return dcContext.getAccountId();
}

private void showLineLayer(MapSource source) {
LineLayer lineLayer = (LineLayer) mapboxStyle.getLayer(source.getLineLayer());
if (lineLayer != null) {
Expand Down
20 changes: 10 additions & 10 deletions src/org/thoughtcrime/securesms/util/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,26 @@ public static String getNotificationLedColor(Context context) {

// 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);
}

Expand Down