refactor MainContextMenuItemsSettings

This commit is contained in:
veliymolfar 2020-05-06 11:29:42 +03:00
parent 99fafc9a9d
commit 125ede4e5d
3 changed files with 16 additions and 17 deletions

View file

@ -81,7 +81,6 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.StringTokenizer; 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.CONFIGURE_MAP_ITEM_ID_SCHEME;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME; import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS;
@ -1288,38 +1287,38 @@ public class OsmandSettings {
} }
} }
public static class MapContextMenuItemsSettings extends ContextMenuItemsSettings { public static class MainContextMenuItemsSettings extends ContextMenuItemsSettings {
private static final String MAIN_ACTIONS = "main_actions"; private static final String MAIN = "main";
private List<String> mainActionIds = new ArrayList<>(); 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); super(hiddenIds, orderIds);
this.mainActionIds = mainActionIds; this.mainIds = mainIds;
} }
@Override @Override
public ContextMenuItemsSettings newInstance() { public ContextMenuItemsSettings newInstance() {
return new MapContextMenuItemsSettings(); return new MainContextMenuItemsSettings();
} }
@Override @Override
public void readFromJson(JSONObject json, String idScheme) { public void readFromJson(JSONObject json, String idScheme) {
super.readFromJson(json, idScheme); super.readFromJson(json, idScheme);
mainActionIds = readIdsList(json.optJSONArray(MAIN_ACTIONS), idScheme); mainIds = readIdsList(json.optJSONArray(MAIN), idScheme);
} }
@Override @Override
public void writeToJson(JSONObject json, String idScheme) throws JSONException { public void writeToJson(JSONObject json, String idScheme) throws JSONException {
super.writeToJson(json, idScheme); super.writeToJson(json, idScheme);
json.put(MAIN_ACTIONS, getJsonArray(mainActionIds, idScheme)); json.put(MAIN, getJsonArray(mainIds, idScheme));
} }
public List<String> getMainActionIds() { public List<String> getMainIds() {
return Collections.unmodifiableList(mainActionIds); return Collections.unmodifiableList(mainIds);
} }
} }
@ -3655,7 +3654,7 @@ public class OsmandSettings {
.makeProfile().cache(); .makeProfile().cache();
public final ContextMenuItemsPreference CONTEXT_MENU_ACTIONS_ITEMS = 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(); .makeProfile().cache();
public final List<ContextMenuItemsPreference> CONTEXT_MENU_ITEMS_PREFERENCES = Arrays.asList(DRAWER_ITEMS, CONFIGURE_MAP_ITEMS, CONTEXT_MENU_ACTIONS_ITEMS); public final List<ContextMenuItemsPreference> CONTEXT_MENU_ITEMS_PREFERENCES = Arrays.asList(DRAWER_ITEMS, CONFIGURE_MAP_ITEMS, CONTEXT_MENU_ACTIONS_ITEMS);

View file

@ -568,7 +568,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// Action buttons // Action buttons
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false); ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
List<ContextMenuItem> items = adapter.getVisibleItems(); 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 mainAdapter = new ContextMenuAdapter(requireMyApplication());
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication()); ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());

View file

@ -160,8 +160,8 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
private void initDefaultMainActions() { private void initDefaultMainActions() {
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems()); List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode); OsmandSettings.ContextMenuItemsSettings pref = getSettingForScreen(app, screenType).getModeValue(appMode);
if (pref instanceof OsmandSettings.MapContextMenuItemsSettings) { if (pref instanceof OsmandSettings.MainContextMenuItemsSettings) {
mainActionItems = new ArrayList<>(((OsmandSettings.MapContextMenuItemsSettings) pref).getMainActionIds()); mainActionItems = new ArrayList<>(((OsmandSettings.MainContextMenuItemsSettings) pref).getMainIds());
if (mainActionItems.isEmpty()) { if (mainActionItems.isEmpty()) {
for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) { for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) {
mainActionItems.add(defItems.get(i).getId()); mainActionItems.add(defItems.get(i).getId());
@ -253,7 +253,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
FragmentManager fm = getFragmentManager(); FragmentManager fm = getFragmentManager();
final OsmandSettings.ContextMenuItemsSettings prefToSave; final OsmandSettings.ContextMenuItemsSettings prefToSave;
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) { if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
prefToSave = new OsmandSettings.MapContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids); prefToSave = new OsmandSettings.MainContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
} else { } else {
prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids); prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids);
} }