Skip to content

Commit

Permalink
Merge pull request #21686 from osmandapp/fix_#21408
Browse files Browse the repository at this point in the history
Fix #21408
  • Loading branch information
Chumva authored Jan 8, 2025
2 parents a91d43a + 0c441a1 commit 96dc7fc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void apply() {
renameButton();
}
}
stateBean.setupButtonState(buttonState);
stateBean.setupButtonState(app, buttonState);
mapButtonsHelper.addQuickActionButtonState(buttonState);
}

Expand Down Expand Up @@ -144,6 +144,7 @@ private void readButtonState(@NonNull JSONObject json) {
buttonState = new QuickActionButtonState(app, id);
stateBean = new ButtonStateBean(id);
stateBean.name = object.optString("name");
stateBean.enabled = object.optBoolean("enabled");

String iconName = object.optString("icon");
if (!Algorithms.isEmpty(iconName)) {
Expand Down Expand Up @@ -178,6 +179,7 @@ void writeToJson(@NonNull JSONObject json) throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("id", buttonState.getId());
jsonObject.put("name", buttonState.hasCustomName() ? buttonState.getName() : "");
jsonObject.put("enabled", buttonState.isEnabled());

if (buttonState.getIconPref().isSet()) {
jsonObject.put("icon", buttonState.getIconPref().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import androidx.annotation.NonNull;

import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;

public class ButtonStateBean {
Expand All @@ -12,13 +15,20 @@ public class ButtonStateBean {
public int size = -1;
public int cornerRadius = -1;
public float opacity = -1;
public boolean enabled;

public ButtonStateBean(@NonNull String id) {
this.id = id;
}

public void setupButtonState(@NonNull QuickActionButtonState buttonState) {
public void setupButtonState(@NonNull OsmandApplication app,
@NonNull QuickActionButtonState buttonState) {
OsmandSettings settings = app.getSettings();
ApplicationMode appMode = settings.getApplicationMode();
long time = settings.getLastModePreferencesEditTime(appMode);

buttonState.setName(name);
buttonState.setEnabled(enabled);

if (!Algorithms.isEmpty(icon)) {
buttonState.getIconPref().set(icon);
Expand All @@ -32,11 +42,13 @@ public void setupButtonState(@NonNull QuickActionButtonState buttonState) {
if (opacity >= 0) {
buttonState.getOpacityPref().set(opacity);
}
settings.setLastModePreferencesEditTime(appMode, time);
}

@NonNull
public static ButtonStateBean toStateBean(@NonNull QuickActionButtonState state) {
ButtonStateBean bean = new ButtonStateBean(state.getId());
bean.enabled = state.isEnabled();
if (state.hasCustomName()) {
bean.name = state.getName();
}
Expand Down

0 comments on commit 96dc7fc

Please sign in to comment.