refactor MainContextMenuItemsSettings
This commit is contained in:
parent
99fafc9a9d
commit
125ede4e5d
3 changed files with 16 additions and 17 deletions
|
@ -81,7 +81,6 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONFIGURE_MAP_ITEM_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS;
|
||||
|
@ -1288,38 +1287,38 @@ public class OsmandSettings {
|
|||
}
|
||||
}
|
||||
|
||||
public static class MapContextMenuItemsSettings extends ContextMenuItemsSettings {
|
||||
private static final String MAIN_ACTIONS = "main_actions";
|
||||
private List<String> mainActionIds = new ArrayList<>();
|
||||
public static class MainContextMenuItemsSettings extends ContextMenuItemsSettings {
|
||||
private static final String MAIN = "main";
|
||||
private List<String> mainIds = new ArrayList<>();
|
||||
|
||||
public MapContextMenuItemsSettings() {
|
||||
public MainContextMenuItemsSettings() {
|
||||
|
||||
}
|
||||
|
||||
public MapContextMenuItemsSettings(@NonNull List<String> mainActionIds, @NonNull List<String> hiddenIds, @NonNull List<String> orderIds) {
|
||||
public MainContextMenuItemsSettings(@NonNull List<String> mainIds, @NonNull List<String> hiddenIds, @NonNull List<String> orderIds) {
|
||||
super(hiddenIds, orderIds);
|
||||
this.mainActionIds = mainActionIds;
|
||||
this.mainIds = mainIds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContextMenuItemsSettings newInstance() {
|
||||
return new MapContextMenuItemsSettings();
|
||||
return new MainContextMenuItemsSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromJson(JSONObject json, String idScheme) {
|
||||
super.readFromJson(json, idScheme);
|
||||
mainActionIds = readIdsList(json.optJSONArray(MAIN_ACTIONS), idScheme);
|
||||
mainIds = readIdsList(json.optJSONArray(MAIN), idScheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToJson(JSONObject json, String idScheme) throws JSONException {
|
||||
super.writeToJson(json, idScheme);
|
||||
json.put(MAIN_ACTIONS, getJsonArray(mainActionIds, idScheme));
|
||||
json.put(MAIN, getJsonArray(mainIds, idScheme));
|
||||
}
|
||||
|
||||
public List<String> getMainActionIds() {
|
||||
return Collections.unmodifiableList(mainActionIds);
|
||||
public List<String> getMainIds() {
|
||||
return Collections.unmodifiableList(mainIds);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3655,7 +3654,7 @@ public class OsmandSettings {
|
|||
.makeProfile().cache();
|
||||
|
||||
public final ContextMenuItemsPreference CONTEXT_MENU_ACTIONS_ITEMS =
|
||||
(ContextMenuItemsPreference) new ContextMenuItemsPreference("configure_map_items", MAP_CONTEXT_MENU_ACTIONS, new MapContextMenuItemsSettings())
|
||||
(ContextMenuItemsPreference) new ContextMenuItemsPreference("configure_map_items", MAP_CONTEXT_MENU_ACTIONS, new MainContextMenuItemsSettings())
|
||||
.makeProfile().cache();
|
||||
|
||||
public final List<ContextMenuItemsPreference> CONTEXT_MENU_ITEMS_PREFERENCES = Arrays.asList(DRAWER_ITEMS, CONFIGURE_MAP_ITEMS, CONTEXT_MENU_ACTIONS_ITEMS);
|
||||
|
|
|
@ -568,7 +568,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
|
|||
// Action buttons
|
||||
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
|
||||
List<ContextMenuItem> items = adapter.getVisibleItems();
|
||||
List<String> mainIds = ((OsmandSettings.MapContextMenuItemsSettings) app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainActionIds();
|
||||
List<String> mainIds = ((OsmandSettings.MainContextMenuItemsSettings) app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainIds();
|
||||
ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
|
||||
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());
|
||||
|
||||
|
|
|
@ -160,8 +160,8 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
|||
private void initDefaultMainActions() {
|
||||
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
|
||||
OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
|
||||
if (pref instanceof OsmandSettings.MapContextMenuItemsSettings) {
|
||||
mainActionItems = new ArrayList<>(((OsmandSettings.MapContextMenuItemsSettings) pref).getMainActionIds());
|
||||
if (pref instanceof OsmandSettings.MainContextMenuItemsSettings) {
|
||||
mainActionItems = new ArrayList<>(((OsmandSettings.MainContextMenuItemsSettings) pref).getMainIds());
|
||||
if (mainActionItems.isEmpty()) {
|
||||
for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) {
|
||||
mainActionItems.add(defItems.get(i).getId());
|
||||
|
@ -253,7 +253,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
|
|||
FragmentManager fm = getFragmentManager();
|
||||
final OsmandSettings.ContextMenuItemsSettings prefToSave;
|
||||
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
|
||||
prefToSave = new OsmandSettings.MapContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
|
||||
prefToSave = new OsmandSettings.MainContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
|
||||
} else {
|
||||
prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue