context menu actions fixes / tracker item fix / ui fixes

This commit is contained in:
veliymolfar 2020-04-29 15:22:47 +03:00
parent 602670fd28
commit 1736b3c789
10 changed files with 233 additions and 45 deletions

View file

@ -91,6 +91,9 @@ public interface OsmAndCustomizationConstants {
String MAP_CONTEXT_MENU_CREATE_POI = MAP_CONTEXT_MENU_ACTIONS + "create_poi";
String MAP_CONTEXT_MENU_MODIFY_OSM_NOTE = MAP_CONTEXT_MENU_ACTIONS + "modify_osm_note";
String MAP_CONTEXT_MENU_OPEN_OSM_NOTE = MAP_CONTEXT_MENU_ACTIONS + "open_osm_note";
String MAP_CONTEXT_MENU_AUDIO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "audio_note";
String MAP_CONTEXT_MENU_VIDEO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "video_note";
String MAP_CONTEXT_MENU_PHOTO_NOTE = MAP_CONTEXT_MENU_ACTIONS + "photo_note";
//Plug-in's IDs:
String PLUGIN_OSMAND_MONITOR = "osmand.monitoring";

View file

@ -11,6 +11,8 @@
Thx - Hardy
-->
<string name="shared_string_add_edit">Add / Edit</string>
<string name="parking_positions">Parking positions</string>
<string name="create_edit_poi">Create/Edit POI</string>
<string name="download_unsupported_action">Unsupported action %1$s</string>
<string name="extra_maps_menu_group">Extra maps</string>

View file

@ -49,6 +49,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID;
public class ContextMenuAdapter {
@ -171,7 +172,7 @@ public class ContextMenuAdapter {
return order;
}
}
return defaultOrder;
return defaultOrder == -1 ? items.size() - 1 : defaultOrder;
}
public ArrayAdapter<ContextMenuItem> createListAdapter(final Activity activity, final boolean lightTheme) {
@ -579,7 +580,7 @@ public class ContextMenuAdapter {
List<ContextMenuItem> items = new ArrayList<>();
for (ContextMenuItem item : this.items) {
String id = item.getId();
if (id != null && id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id)) {
if (id != null && id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id) || id != null && id.startsWith(AIDL_LAYERS_PREFIX)) {
items.add(item);
}
}

View file

@ -81,6 +81,7 @@ 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;
@ -1176,8 +1177,10 @@ public class OsmandSettings {
public static class ContextMenuItemsSettings implements Serializable {
public static final String HIDDEN = "hidden";
public static final String ORDER = "order";
public static final String MAIN_ACTIONS = "main_actions";
private List<String> hiddenIds = new ArrayList<>();
private List<String> orderIds = new ArrayList<>();
private List<String> mainActionIds = new ArrayList<>();
public ContextMenuItemsSettings() {
@ -1188,6 +1191,12 @@ public class OsmandSettings {
this.orderIds = orderIds;
}
public ContextMenuItemsSettings(@NonNull List<String> mainActionIds, @NonNull List<String> hiddenIds, @NonNull List<String> orderIds) {
this.mainActionIds = mainActionIds;
this.hiddenIds = hiddenIds;
this.orderIds = orderIds;
}
public void readFromJsonString(String jsonString, @NonNull String idScheme) {
if (Algorithms.isEmpty(jsonString)) {
return;
@ -1196,6 +1205,9 @@ public class OsmandSettings {
JSONObject json = new JSONObject(jsonString);
hiddenIds = readIdsList(json.optJSONArray(HIDDEN), idScheme);
orderIds = readIdsList(json.optJSONArray(ORDER), idScheme);
if (idScheme.equals(MAP_CONTEXT_MENU_ACTIONS)) {
mainActionIds = readIdsList(json.optJSONArray(MAIN_ACTIONS), idScheme);
}
} catch (JSONException e) {
LOG.error("Error converting to json string: " + e);
}
@ -1206,9 +1218,13 @@ public class OsmandSettings {
if (jsonArray != null) {
for (int i = 0; i < jsonArray.length(); i++) {
String id = jsonArray.optString(i);
if (id.startsWith(AIDL_LAYERS_PREFIX)) {
list.add(id);
} else {
list.add(idScheme + id);
}
}
}
return list;
}
@ -1217,6 +1233,9 @@ public class OsmandSettings {
JSONObject json = new JSONObject();
json.put(HIDDEN, getJsonArray(hiddenIds, idScheme));
json.put(ORDER, getJsonArray(orderIds, idScheme));
if (idScheme.equals(MAP_CONTEXT_MENU_ACTIONS)) {
json.put(MAIN_ACTIONS, getJsonArray(mainActionIds, idScheme));
}
return json.toString();
} catch (JSONException e) {
LOG.error("Error converting to json string: " + e);
@ -1241,6 +1260,10 @@ public class OsmandSettings {
public List<String> getOrderIds() {
return Collections.unmodifiableList(orderIds);
}
public List<String> getMainActionIds() {
return Collections.unmodifiableList(mainActionIds);
}
}
public class EnumIntPreference<E extends Enum<E>> extends CommonPreference<E> {
@ -3581,6 +3604,9 @@ public class OsmandSettings {
@Nullable
public ContextMenuItemsPreference getContextMenuItemsPreference(@NonNull String id) {
if (id.startsWith(AIDL_LAYERS_PREFIX)) {
return CONFIGURE_MAP_ITEMS;
}
for (ContextMenuItemsPreference preference : CONTEXT_MENU_ITEMS_PREFERENCES) {
if (id.startsWith(preference.idScheme)) {
return preference;

View file

@ -1038,7 +1038,9 @@ public class MapActivityActions implements DialogProvider {
ItemBuilder divider = new ItemBuilder().setLayout(R.layout.drawer_divider);
divider.setId(DRAWER_DIVIDER_ID);
divider.setPosition(dividerItemIndex >= 0 ? dividerItemIndex : 8);
int position = dividerItemIndex >= 0 ? dividerItemIndex : 8;
divider.setPosition(position);
divider.setOrder(position);
optionsMenuHelper.addItem(divider.createItem());
return optionsMenuHelper;

View file

@ -96,6 +96,9 @@ import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AUDIO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_PHOTO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_VIDEO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.RECORDING_LAYER;
@ -660,6 +663,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
return;
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_arecord, app)
.setId(MAP_CONTEXT_MENU_AUDIO_NOTE)
.setIcon(R.drawable.ic_action_micro_dark)
.setOrder(TAKE_AUDIO_NOTE_ITEM_ORDER)
.setListener(new ContextMenuAdapter.ItemClickListener() {
@ -672,6 +676,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
})
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_vrecord, app)
.setId(MAP_CONTEXT_MENU_VIDEO_NOTE)
.setIcon(R.drawable.ic_action_video_dark)
.setOrder(TAKE_VIDEO_NOTE_ITEM_ORDER)
.setListener(new ItemClickListener() {
@ -684,6 +689,7 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
})
.createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.recording_context_menu_precord, app)
.setId(MAP_CONTEXT_MENU_PHOTO_NOTE)
.setIcon(R.drawable.ic_action_photo_dark)
.setOrder(TAKE_PHOTO_NOTE_ITEM_ORDER)
.setListener(new ItemClickListener() {

View file

@ -568,6 +568,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
// TODO refactor section
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
List<ContextMenuItem> items = new ArrayList<>();
List<String> mainIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get().getMainActionIds();
for (ContextMenuItem item : adapter.getItems()) {
if (!item.isHidden()) {
items.add(item);
@ -575,6 +576,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
}
ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());
if (!mainIds.isEmpty()){
for (ContextMenuItem item : items) {
if (mainIds.contains(item.getId())) {
mainAdapter.addItem(item);
} else {
additionalAdapter.addItem(item);
}
}
} else {
for (int i = 0; i < items.size(); i++) {
if (i < MAIN_BUTTONS_QUANTITY) {
mainAdapter.addItem(items.get(i));
@ -582,6 +593,7 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
additionalAdapter.addItem(items.get(i));
}
}
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
@ -591,10 +603,16 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter);
ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter);
if (!mainIds.isEmpty()){
for (ContextMenuItem item: mainAdapter.getItems()) {
buttons.addView(getActionView(item, mainAdapter.getItems().indexOf(item), mainAdapter, additionalAdapter, mainListener, additionalListener), params);
}
} else {
int mainButtonsQuantity = Math.min(MAIN_BUTTONS_QUANTITY, items.size());
for (int i = 0; i < mainButtonsQuantity; i++) {
buttons.addView(getActionView(items.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params);
}
}
buttons.setGravity(Gravity.CENTER);
//Bottom buttons

View file

@ -68,12 +68,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
private static final String ITEM_TYPE_KEY = "item_type_key";
private static final String ITEMS_ORDER_KEY = "items_order_key";
private static final String HIDDEN_ITEMS_KEY = "hidden_items_key";
private static final String MAIN_ACTIONS_ITEMS_KEY = "main_actions_items_key";
private static final String CONFIGURE_MENU_ITEMS_TAG = "configure_menu_items_tag";
private static final String IS_CHANGED_KEY = "is_changed_key";
private RearrangeMenuItemsAdapter rearrangeAdapter;
private HashMap<String, Integer> menuItemsOrder;
private ContextMenuAdapter contextMenuAdapter;
private List<String> hiddenMenuItems;
private List<String> mainActionItems;
private ApplicationMode appMode;
private LayoutInflater mInflater;
private OsmandApplication app;
@ -81,6 +83,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
private boolean nightMode;
private boolean wasReset = false;
private boolean isChanged = false;
private Activity activity;
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
@ -90,6 +93,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
outState.putSerializable(ITEM_TYPE_KEY, screenType);
outState.putString(APP_MODE_KEY, appMode.getStringKey());
outState.putBoolean(IS_CHANGED_KEY, isChanged);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
outState.putStringArrayList(MAIN_ACTIONS_ITEMS_KEY, new ArrayList<>(mainActionItems));
}
}
public static ConfigureMenuItemsFragment showInstance(
@ -127,14 +133,15 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
app = requireMyApplication();
nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME;
mInflater = UiUtilities.getInflater(app, nightMode);
if (savedInstanceState != null) {
appMode = ApplicationMode.valueOfStringKey(savedInstanceState.getString(APP_MODE_KEY), null);
screenType = (ScreenType) savedInstanceState.getSerializable(ITEM_TYPE_KEY);
hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY);
menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);
isChanged = savedInstanceState.getBoolean(IS_CHANGED_KEY);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
mainActionItems = savedInstanceState.getStringArrayList(MAIN_ACTIONS_ITEMS_KEY);
}
} else {
hiddenMenuItems = new ArrayList<>(getSettingForScreen(app, screenType).getModeValue(appMode).getHiddenIds());
menuItemsOrder = new HashMap<>();
@ -143,6 +150,10 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
menuItemsOrder.put(orderIds.get(i), i);
}
}
nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME;
mInflater = UiUtilities.getInflater(app, nightMode);
mainActionItems = new ArrayList<>();
activity = getActivity();
instantiateContextMenuAdapter();
if (menuItemsOrder.isEmpty()) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems();
@ -151,10 +162,23 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
menuItemsOrder.put(defItems.get(i).getId(), i);
}
}
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
initDefaultMainActions();
}
}
private void initDefaultMainActions() {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems();
initDefaultOrders(defItems);
mainActionItems = new ArrayList<>(getSettingForScreen(app, screenType).getModeValue(appMode).getMainActionIds());
if (mainActionItems.isEmpty()) {
for (int i = 0; i < MAIN_BUTTONS_QUANTITY; i++) {
mainActionItems.add(defItems.get(i).getId());
}
}
}
private void instantiateContextMenuAdapter() {
Activity activity = getActivity();
if (activity instanceof MapActivity) {
switch (screenType) {
case DRAWER:
@ -214,6 +238,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
@Override
public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
mainActionItems = rearrangeAdapter.getMainActionsIds();
}
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
rearrangeAdapter.notifyDataSetChanged();
@ -226,10 +253,14 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
if (rearrangeMenuAdapterItem.getValue() instanceof ContextMenuItem) {
ContextMenuItem menuItemBase = (ContextMenuItem) rearrangeMenuAdapterItem.getValue();
menuItemBase.setHidden(!menuItemBase.isHidden());
String id = menuItemBase.getId();
if (menuItemBase.isHidden()) {
hiddenMenuItems.add(menuItemBase.getId());
hiddenMenuItems.add(id);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
mainActionItems.remove(id);
}
} else {
hiddenMenuItems.remove(menuItemBase.getId());
hiddenMenuItems.remove(id);
}
wasReset = false;
isChanged = true;
@ -273,7 +304,12 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
}
FragmentManager fm = getFragmentManager();
OsmandSettings.ContextMenuItemsSettings prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids);
OsmandSettings.ContextMenuItemsSettings prefToSave;
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
prefToSave = new OsmandSettings.ContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
} else {
prefToSave = new OsmandSettings.ContextMenuItemsSettings(hiddenMenuItems, ids);
}
if (fm != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fm,
getSettingForScreen(app, screenType).getId(),
@ -301,6 +337,22 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
return root;
}
@Override
public void onResume() {
super.onResume();
if (activity instanceof MapActivity) {
((MapActivity) activity).disableDrawer();
}
}
@Override
public void onStop() {
super.onStop();
if (activity instanceof MapActivity) {
((MapActivity) activity).enableDrawer();
}
}
private List<RearrangeMenuAdapterItem> getAdapterItems() {
List<RearrangeMenuAdapterItem> items = new ArrayList<>();
items.add(new RearrangeMenuAdapterItem(DESCRIPTION, screenType));
@ -322,18 +374,20 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
List<RearrangeMenuAdapterItem> main = new ArrayList<>();
int actionsIndex = Math.min(MAIN_BUTTONS_QUANTITY, visible.size());
for (int i = 0; i < actionsIndex; i++) {
main.add(visible.get(i));
List<RearrangeMenuAdapterItem> additional = new ArrayList<>();
for (RearrangeMenuAdapterItem adapterItem : visible) {
if (mainActionItems.contains(((ContextMenuItem) adapterItem.getValue()).getId())) {
main.add(adapterItem);
} else {
additional.add(adapterItem);
}
}
items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr)));
items.addAll(main);
if (!additional.isEmpty()) {
items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr)));
List<RearrangeMenuAdapterItem> additional = new ArrayList<>();
for (int i = MAIN_BUTTONS_QUANTITY; i < visible.size(); i++) {
additional.add(visible.get(i));
}
items.addAll(additional);
}
} else {
items.addAll(visible);
}
@ -354,6 +408,10 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
isChanged = true;
getSettingForScreen(app, screenType).resetModeToDefault(appMode);
instantiateContextMenuAdapter();
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
mainActionItems.clear();
initDefaultMainActions();
}
rearrangeAdapter.updateItems(getAdapterItems());
}
})));

View file

@ -59,6 +59,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
private LayoutInflater mInflater;
private boolean nightMode;
private ApplicationMode appMode;
private Activity activity;
public static boolean showInstance(@NonNull FragmentManager fragmentManager,
Fragment target,
@ -86,6 +87,7 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
app = requireMyApplication();
nightMode = app.getSettings().OSMAND_THEME.getModeValue(appMode) == OsmandSettings.OSMAND_DARK_THEME;
mInflater = UiUtilities.getInflater(app, nightMode);
activity = getActivity();
}
@Nullable
@ -154,6 +156,22 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
outState.putString(APP_MODE_KEY, getAppMode().getStringKey());
}
@Override
public void onResume() {
super.onResume();
if (activity instanceof MapActivity) {
((MapActivity) activity).disableDrawer();
}
}
@Override
public void onStop() {
super.onStop();
if (activity instanceof MapActivity) {
((MapActivity) activity).enableDrawer();
}
}
public void setAppMode(ApplicationMode appMode) {
this.appMode = appMode;
}

View file

@ -28,19 +28,27 @@ import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static net.osmand.aidl.ConnectedApp.AIDL_LAYERS_PREFIX;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONTOUR_LINES;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_BUILDS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.GPX_FILES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AUDIO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_EDIT_GPX_WP;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARK_AS_PARKING_LOC;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MODIFY_OSM_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MORE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_PHOTO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_VIDEO_NOTE;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_SOURCE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_EDITS;
@ -209,6 +217,9 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
if (id.equals(MAP_CONTEXT_MENU_CREATE_POI)) {
h.title.setText(R.string.create_edit_poi);
}
if (id.equals(MAP_CONTEXT_MENU_ADD_ID)) {
h.title.setText(R.string.shared_string_add_edit);
}
} else if (holder instanceof HeaderHolder) {
HeaderHolder h = (HeaderHolder) holder;
HeaderItem header = (HeaderItem) item.value;
@ -217,6 +228,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
h.title.setText(header.titleRes);
h.description.setText(header.descrRes);
h.moveIcon.setVisibility(View.GONE);
h.movable = header.titleRes == R.string.additional_actions;
} else if (holder instanceof ButtonHolder) {
ButtonHolder h = (ButtonHolder) holder;
ButtonItem button = (ButtonItem) item.value;
@ -237,6 +249,21 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
public boolean onItemMove(int from, int to) {
Object itemFrom = items.get(from).value;
Object itemTo = items.get(to).value;
if (itemFrom instanceof ContextMenuItem
&& ((ContextMenuItem) itemFrom).getId().startsWith(MAP_CONTEXT_MENU_ACTIONS)
&& itemTo instanceof HeaderItem
&& ((HeaderItem) itemTo).titleRes == R.string.additional_actions) {
ContextMenuItem menuItemFrom = (ContextMenuItem) itemFrom;
int headerMaxIndex = MAIN_BUTTONS_QUANTITY + 2;
if (to >= headerMaxIndex || menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
return false;
}
Collections.swap(items, from, to);
notifyItemMoved(from, to);
return true;
}
if (itemFrom instanceof ContextMenuItem
&& itemTo instanceof ContextMenuItem) {
ContextMenuItem menuItemFrom = (ContextMenuItem) itemFrom;
@ -247,17 +274,23 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
if (menuItemFrom.getId().startsWith(SHOW_ITEMS_ID_SCHEME) && menuItemTo.getId().startsWith(RENDERING_ITEMS_ID_SCHEME)
|| menuItemFrom.getId().startsWith(RENDERING_ITEMS_ID_SCHEME) && menuItemTo.getId().startsWith(SHOW_ITEMS_ID_SCHEME)
|| menuItemFrom.getId().startsWith(RENDERING_ITEMS_ID_SCHEME) && menuItemTo.getId().startsWith(AIDL_LAYERS_PREFIX)
|| menuItemFrom.getId().startsWith(AIDL_LAYERS_PREFIX) && menuItemTo.getId().startsWith(RENDERING_ITEMS_ID_SCHEME)
|| menuItemTo.isHidden()) {
return false;
}
int buttonMoreIndex = MAIN_BUTTONS_QUANTITY + 1;
if (menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
if (to > buttonMoreIndex) {
return false;
// item "Actions" should not left "Main actions" section
if (menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID) || menuItemTo.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
int additionalHeaderIndex = 0;
for (int i = 0; i < items.size(); i++) {
Object value = items.get(i).getValue();
if (value instanceof HeaderItem && ((HeaderItem) value).titleRes == R.string.additional_actions) {
additionalHeaderIndex = i;
break;
}
} else if (menuItemTo.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
if (from > buttonMoreIndex) {
}
if (to >= additionalHeaderIndex || from > additionalHeaderIndex) {
return false;
}
}
@ -348,6 +381,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
private ImageView moveIcon;
private TextView title;
private TextView description;
private boolean movable = true;
HeaderHolder(@NonNull View itemView) {
super(itemView);
@ -358,7 +392,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
@Override
public boolean isMovingDisabled() {
return true;
return !movable;
}
}
@ -471,6 +505,9 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
case UNDERLAY_MAP:
return R.string.shared_string_online_maps;
case RECORDING_LAYER:
case MAP_CONTEXT_MENU_AUDIO_NOTE:
case MAP_CONTEXT_MENU_VIDEO_NOTE:
case MAP_CONTEXT_MENU_PHOTO_NOTE:
return R.string.audionotes_plugin_name;
case CONTOUR_LINES:
case TERRAIN:
@ -481,8 +518,25 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
case MAP_CONTEXT_MENU_MODIFY_OSM_NOTE:
case MAP_CONTEXT_MENU_OPEN_OSM_NOTE:
return R.string.osm_settings;
case MAP_CONTEXT_MENU_MARK_AS_PARKING_LOC:
return R.string.parking_positions;
default:
return R.string.app_name_osmand;
}
}
public List<String> getMainActionsIds() {
List<String> ids = new ArrayList<>();
for (RearrangeMenuAdapterItem adapterItem : items) {
Object value = adapterItem.getValue();
if (value instanceof ContextMenuItem) {
ids.add(((ContextMenuItem) value).getId());
} else if (value instanceof HeaderItem
&& (((HeaderItem) value).titleRes == R.string.additional_actions
|| ((HeaderItem) value).titleRes == R.string.shared_string_hidden)) {
break;
}
}
return ids;
}
}