initial rearrange menu items implementation
This commit is contained in:
parent
07cc37f791
commit
065f281f92
9 changed files with 345 additions and 514 deletions
|
@ -4,9 +4,18 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:background="?attr/list_background_color"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/selectable_list_item"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -23,6 +23,8 @@ import androidx.annotation.ColorRes;
|
|||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.IdRes;
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
@ -33,6 +35,8 @@ import net.osmand.plus.activities.HelpActivity;
|
|||
import net.osmand.plus.activities.actions.AppModeDialog;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.dialogs.HelpArticleDialogFragment;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -40,11 +44,19 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.APP_PROFILES_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.CONFIGURE_MAP_ITEM_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_ITEM_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ACTIONS;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.MENU_ITEM;
|
||||
|
||||
public class ContextMenuAdapter {
|
||||
private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class);
|
||||
|
||||
|
@ -114,7 +126,6 @@ public class ContextMenuAdapter {
|
|||
this.DEFAULT_LAYOUT_ID = defaultLayoutId;
|
||||
}
|
||||
|
||||
|
||||
public void setChangeAppModeListener(ConfigureMapMenu.OnClickListener changeAppModeListener) {
|
||||
this.changeAppModeListener = changeAppModeListener;
|
||||
}
|
||||
|
@ -536,4 +547,94 @@ public class ContextMenuAdapter {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void initDefaultOrders(@NonNull List<ContextMenuItem> items) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
items.get(i).setOrder(i);
|
||||
}
|
||||
}
|
||||
|
||||
public List<AdapterItem> getItemsForRearrangeAdapter(@NonNull ScreenType screenType, @Nullable List<String> hiddenItemsIds, @Nullable HashMap<String, Integer> itemsOrderIds, boolean hidden) {
|
||||
String idScheme = "";
|
||||
switch (screenType) {
|
||||
case DRAWER:
|
||||
idScheme = DRAWER_ITEM_ID_SCHEME;
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
idScheme = CONFIGURE_MAP_ITEM_ID_SCHEME;
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
idScheme = MAP_CONTEXT_MENU_ACTIONS;
|
||||
break;
|
||||
}
|
||||
if (itemsOrderIds == null || itemsOrderIds.isEmpty()) {
|
||||
initDefaultOrders(items);
|
||||
} else {
|
||||
reorderMenuItems(items, itemsOrderIds);
|
||||
}
|
||||
List<AdapterItem> visibleItems = new ArrayList<>();
|
||||
List<AdapterItem> hiddenItems = new ArrayList<>();
|
||||
for (ContextMenuItem item : items) {
|
||||
String id = item.getId();
|
||||
if (id != null && id.startsWith(idScheme) && !APP_PROFILES_ID.equals(id)) {
|
||||
if (hiddenItemsIds != null && hiddenItemsIds.contains(id)) {
|
||||
item.setHidden(true);
|
||||
hiddenItems.add(new AdapterItem(MENU_ITEM, item));
|
||||
} else {
|
||||
item.setHidden(false);
|
||||
visibleItems.add(new AdapterItem(MENU_ITEM, item));
|
||||
}
|
||||
}
|
||||
}
|
||||
return hidden ? hiddenItems : visibleItems;
|
||||
}
|
||||
|
||||
public List<ContextMenuItem> getDefaultItems(ScreenType screenType) {
|
||||
String idScheme = "";
|
||||
switch (screenType) {
|
||||
case DRAWER:
|
||||
idScheme = DRAWER_ITEM_ID_SCHEME;
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
idScheme = CONFIGURE_MAP_ITEM_ID_SCHEME;
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
idScheme = MAP_CONTEXT_MENU_ACTIONS;
|
||||
break;
|
||||
}
|
||||
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)) {
|
||||
items.add(item);
|
||||
}
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void reorderMenuItems(@NonNull List<ContextMenuItem> defaultItems, @NonNull HashMap<String, Integer> itemsOrder) {
|
||||
for (ContextMenuItem item : defaultItems) {
|
||||
Integer order = itemsOrder.get(item.getId());
|
||||
if (order != null) {
|
||||
item.setOrder(order);
|
||||
}
|
||||
}
|
||||
Collections.sort(defaultItems, new Comparator<ContextMenuItem>() {
|
||||
@Override
|
||||
public int compare(ContextMenuItem item1, ContextMenuItem item2) {
|
||||
int order1 = item1.getOrder();
|
||||
int order2 = item2.getOrder();
|
||||
return (order1 < order2) ? -1 : ((order1 == order2) ? 0 : 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getMenuItemsOrder(@NonNull List<String> ids) {
|
||||
HashMap<String, Integer> result = new HashMap<>();
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
result.put(ids.get(i), i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
|
@ -30,6 +30,7 @@ public class ContextMenuItem {
|
|||
private final boolean category;
|
||||
private final boolean clickable;
|
||||
private final boolean skipPaintingWithoutColor;
|
||||
private boolean hidden;
|
||||
private final int pos;
|
||||
private int order;
|
||||
private String description;
|
||||
|
@ -150,6 +151,10 @@ public class ContextMenuItem {
|
|||
return clickable;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public int getPos() {
|
||||
return pos;
|
||||
}
|
||||
|
@ -182,6 +187,10 @@ public class ContextMenuItem {
|
|||
return hideDivider;
|
||||
}
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
|
|
@ -3389,9 +3389,14 @@ public class OsmandSettings {
|
|||
public final ListStringPreference HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS = (ListStringPreference)
|
||||
new ListStringPreference("hidden_context_menu_actions_items", null, ",,").makeProfile().cache();
|
||||
|
||||
public final ListStringPreference CONTEXT_MENU_ACTIONS_ITEMS_ORDER = (ListStringPreference)
|
||||
new ListStringPreference("context_menu_actions_items_order", null, ",,").makeProfile().cache();
|
||||
|
||||
public final ListStringPreference HIDDEN_CONFIGURE_MAP_ITEMS = (ListStringPreference)
|
||||
new ListStringPreference("hidden_configure_map_items", null, ",,").makeProfile().cache();
|
||||
|
||||
public final ListStringPreference CONFIGURE_MAP_ITEMS_ORDER = (ListStringPreference)
|
||||
new ListStringPreference("configure_map_items_order", null, ",,").makeProfile().cache();
|
||||
|
||||
public final ListStringPreference DRAWER_ITEMS_ORDER = (ListStringPreference)
|
||||
new ListStringPreference("drawer_items_order", null, ",,").makeProfile().cache();
|
||||
|
|
|
@ -65,7 +65,6 @@ import net.osmand.plus.routepreparationmenu.WaypointsFragment;
|
|||
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.settings.BaseSettingsFragment;
|
||||
import net.osmand.plus.settings.MenuItemsManager;
|
||||
import net.osmand.plus.views.BaseMapLayer;
|
||||
import net.osmand.plus.views.MapControlsLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
|
@ -82,7 +81,6 @@ import java.io.File;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_MAP_ID;
|
||||
|
@ -988,33 +986,6 @@ public class MapActivityActions implements DialogProvider {
|
|||
divider.setPosition(dividerItemIndex >= 0 ? dividerItemIndex : 8);
|
||||
optionsMenuHelper.addItem(divider.createItem());
|
||||
|
||||
List<ContextMenuItem> items = optionsMenuHelper.getItems();
|
||||
List<ContextMenuItem> newItems = new ArrayList<>();
|
||||
List<String> hiddenIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
|
||||
|
||||
MenuItemsManager manager = new MenuItemsManager(app);
|
||||
LinkedHashMap<String, Integer> order = manager.getDrawerItemsSavedOrder();
|
||||
|
||||
if (hiddenIds != null){
|
||||
for (ContextMenuItem item: items){
|
||||
if (!hiddenIds.contains(item.getId())){
|
||||
newItems.add(item);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
newItems.addAll(items);
|
||||
}
|
||||
|
||||
for (ContextMenuItem item: newItems){
|
||||
Integer o = order.get(item.getId());
|
||||
if (o == null){
|
||||
o = item.getOrder();
|
||||
}
|
||||
item.setOrder(o);
|
||||
}
|
||||
|
||||
optionsMenuHelper.updateItems(newItems);
|
||||
optionsMenuHelper.sortItemsByOrder();
|
||||
return optionsMenuHelper;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -22,60 +22,59 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityActions;
|
||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||
import net.osmand.plus.dialogs.ConfigureMapMenu;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.AdapterItem;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.HeaderItem;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.ButtonItem;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.MenuItemBase;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.MenuItemsAdapterListener;
|
||||
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem;
|
||||
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.plus.settings.MenuItemsAdapter.AdapterItemType.HEADER;
|
||||
import static net.osmand.plus.settings.MenuItemsAdapter.AdapterItemType.DIVIDER;
|
||||
import static net.osmand.plus.settings.MenuItemsAdapter.AdapterItemType.DESCRIPTION;
|
||||
import static net.osmand.plus.settings.MenuItemsAdapter.AdapterItemType.BUTTON;
|
||||
import static net.osmand.plus.settings.MenuItemsAdapter.AdapterItemType.MENU_ITEM;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.BUTTON;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DESCRIPTION;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.DIVIDER;
|
||||
import static net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItemType.HEADER;
|
||||
|
||||
public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
||||
|
||||
public static final String TAG = ConfigureMenuItemsFragment.class.getName();
|
||||
private static final String ITEM_TYPE_KEY = "item_type_key";
|
||||
private static String ITEMS_ORDER_KEY = "items_order_key";
|
||||
private static String HIDDEN_ITEMS_KEY = "hidden_items_key";
|
||||
private static String CONFIGURE_MENU_ITEMS_TAG = "configure_menu_items_tag";
|
||||
private OsmandApplication app;
|
||||
private boolean nightMode;
|
||||
private ScreenType type;
|
||||
private LayoutInflater mInflater;
|
||||
private MenuItemsManager menuItemsManager;
|
||||
private static final String ITEMS_ORDER_KEY = "items_order_key";
|
||||
private static final String HIDDEN_ITEMS_KEY = "hidden_items_key";
|
||||
private static final String CONFIGURE_MENU_ITEMS_TAG = "configure_menu_items_tag";
|
||||
private RearrangeMenuItemsAdapter rearrangeAdapter;
|
||||
private HashMap<String, Integer> menuItemsOrder;
|
||||
private ContextMenuAdapter contextMenuAdapter;
|
||||
private List<String> hiddenMenuItems;
|
||||
private MenuItemsAdapter adapter;
|
||||
private LayoutInflater mInflater;
|
||||
private OsmandApplication app;
|
||||
private ScreenType screenType;
|
||||
private boolean nightMode;
|
||||
private boolean wasReset = false;
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putSerializable(ITEM_TYPE_KEY, type);
|
||||
outState.putStringArrayList(HIDDEN_ITEMS_KEY, new ArrayList<>(hiddenMenuItems));
|
||||
outState.putSerializable(ITEMS_ORDER_KEY, menuItemsOrder);
|
||||
outState.putSerializable(ITEM_TYPE_KEY, screenType);
|
||||
}
|
||||
|
||||
public static ConfigureMenuItemsFragment showInstance(@NonNull FragmentManager fm, @NonNull ScreenType type) {
|
||||
ConfigureMenuItemsFragment fragment = new ConfigureMenuItemsFragment();
|
||||
fragment.setType(type);
|
||||
fragment.setScreenType(type);
|
||||
fm.beginTransaction()
|
||||
.replace(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(CONFIGURE_MENU_ITEMS_TAG)
|
||||
|
@ -89,20 +88,31 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
app = requireMyApplication();
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
mInflater = UiUtilities.getInflater(app, nightMode);
|
||||
menuItemsManager = new MenuItemsManager(app);
|
||||
// MapActivityActions mapActivityActions = new MapActivityActions(getActivity())
|
||||
|
||||
Activity activity = getActivity();
|
||||
if (activity instanceof MapActivity) {
|
||||
switch (screenType) {
|
||||
case DRAWER:
|
||||
MapActivityActions mapActivityActions = new MapActivityActions((MapActivity) activity);
|
||||
contextMenuAdapter = mapActivityActions.createMainOptionsMenu();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
ConfigureMapMenu configureMapMenu = new ConfigureMapMenu();
|
||||
contextMenuAdapter = configureMapMenu.createListAdapter((MapActivity) activity);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (savedInstanceState != null
|
||||
&& savedInstanceState.containsKey(ITEM_TYPE_KEY)
|
||||
&& savedInstanceState.containsKey(HIDDEN_ITEMS_KEY)
|
||||
&& savedInstanceState.containsKey(ITEMS_ORDER_KEY)) {
|
||||
type = (ScreenType) savedInstanceState.getSerializable(ITEM_TYPE_KEY);
|
||||
screenType = (ScreenType) savedInstanceState.getSerializable(ITEM_TYPE_KEY);
|
||||
hiddenMenuItems = savedInstanceState.getStringArrayList(HIDDEN_ITEMS_KEY);
|
||||
menuItemsOrder = (HashMap<String,Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);
|
||||
menuItemsOrder = (HashMap<String, Integer>) savedInstanceState.getSerializable(ITEMS_ORDER_KEY);
|
||||
} else {
|
||||
hiddenMenuItems = menuItemsManager.getHiddenItemsIds(type);
|
||||
// TODO
|
||||
menuItemsOrder = menuItemsManager.getDrawerItemsSavedOrder();
|
||||
hiddenMenuItems = getHiddenItemsIds(screenType);
|
||||
menuItemsOrder = contextMenuAdapter.getMenuItemsOrder(getItemsIdsOrder(screenType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -121,16 +131,18 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
? getResources().getColor(R.color.text_color_primary_dark)
|
||||
: getResources().getColor(R.color.list_background_color_dark));
|
||||
toolbarButton.setImageDrawable(getPaintedContentIcon(R.drawable.ic_arrow_back, getResources().getColor(R.color.text_color_secondary_light)));
|
||||
toolbarTitle.setText(type.titleRes);
|
||||
toolbarTitle.setText(screenType.titleRes);
|
||||
toolbarButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showExitDialog();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
rearrangeAdapter = new RearrangeMenuItemsAdapter(app, getAdapterItems());
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(app));
|
||||
adapter = new MenuItemsAdapter(app, getAdapterItems());
|
||||
final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
|
||||
final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(rearrangeAdapter));
|
||||
touchHelper.attachToRecyclerView(recyclerView);
|
||||
MenuItemsAdapterListener listener = new MenuItemsAdapterListener() {
|
||||
private int fromPosition;
|
||||
|
@ -146,32 +158,34 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
|
||||
toPosition = holder.getAdapterPosition();
|
||||
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
|
||||
adapter.notifyDataSetChanged();
|
||||
rearrangeAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onButtonClicked(int position) {
|
||||
AdapterItem adapterItem = adapter.getItem(position);
|
||||
if (adapterItem.getValue() instanceof MenuItemBase) {
|
||||
MenuItemBase menuItemBase = (MenuItemBase) adapterItem.getValue();
|
||||
menuItemBase.toggleHidden();
|
||||
AdapterItem adapterItem = rearrangeAdapter.getItem(position);
|
||||
if (adapterItem.getValue() instanceof ContextMenuItem) {
|
||||
ContextMenuItem menuItemBase = (ContextMenuItem) adapterItem.getValue();
|
||||
menuItemBase.setHidden(!menuItemBase.isHidden());
|
||||
if (menuItemBase.isHidden()) {
|
||||
hiddenMenuItems.add(menuItemBase.getId());
|
||||
} else {
|
||||
hiddenMenuItems.remove(menuItemBase.getId());
|
||||
}
|
||||
adapter.updateItems(getAdapterItems());
|
||||
wasReset = false;
|
||||
rearrangeAdapter.updateItems(getAdapterItems());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemMoved(String id, int position) {
|
||||
menuItemsOrder.put(id, position);
|
||||
wasReset = false;
|
||||
}
|
||||
};
|
||||
adapter.setListener(listener);
|
||||
recyclerView.setAdapter(adapter);
|
||||
rearrangeAdapter.setListener(listener);
|
||||
recyclerView.setAdapter(rearrangeAdapter);
|
||||
View cancelButton = root.findViewById(R.id.dismiss_button);
|
||||
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -190,15 +204,18 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
applyButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
menuItemsManager.saveHiddenItemsIds(type, hiddenMenuItems);
|
||||
List<MenuItemBase> defaultItems;
|
||||
defaultItems = menuItemsManager.getDrawerItemsDefault();
|
||||
menuItemsManager.reorderMenuItems(defaultItems, menuItemsOrder);
|
||||
if (wasReset) {
|
||||
resetMenuItems(screenType);
|
||||
} else {
|
||||
saveHiddenItemsIds(screenType, hiddenMenuItems);
|
||||
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems(screenType);
|
||||
contextMenuAdapter.reorderMenuItems(defItems, menuItemsOrder);
|
||||
List<String> ids = new ArrayList<>();
|
||||
for (MenuItemBase item : defaultItems) {
|
||||
for (ContextMenuItem item : defItems) {
|
||||
ids.add(item.getId());
|
||||
}
|
||||
menuItemsManager.saveItemsIdsOrder(type, ids);
|
||||
saveItemsIdsOrder(screenType, ids);
|
||||
}
|
||||
dismissFragment();
|
||||
}
|
||||
});
|
||||
|
@ -208,9 +225,40 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
return root;
|
||||
}
|
||||
|
||||
private List<AdapterItem> getAdapterItems() {
|
||||
List<AdapterItem> items = new ArrayList<>();
|
||||
items.add(new AdapterItem(DESCRIPTION, screenType));
|
||||
|
||||
List<AdapterItem> visible = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, false);
|
||||
List<AdapterItem> hiddenItems = contextMenuAdapter.getItemsForRearrangeAdapter(screenType, hiddenMenuItems, wasReset ? null : menuItemsOrder, true);
|
||||
items.addAll(visible);
|
||||
if (!hiddenItems.isEmpty()) {
|
||||
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.shared_string_hidden, R.string.hidden_items_descr)));
|
||||
items.addAll(hiddenItems);
|
||||
}
|
||||
items.add(new AdapterItem(DIVIDER, 1));
|
||||
items.add(new AdapterItem(BUTTON, new RearrangeMenuItemsAdapter.ButtonItem(
|
||||
R.string.reset_to_default,
|
||||
R.drawable.ic_action_reset_to_default_dark,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
public void onClick(View view) {
|
||||
hiddenMenuItems.clear();
|
||||
menuItemsOrder.clear();
|
||||
wasReset = true;
|
||||
rearrangeAdapter.updateItems(getAdapterItems());
|
||||
}
|
||||
})));
|
||||
items.add(new AdapterItem(BUTTON, new RearrangeMenuItemsAdapter.ButtonItem(
|
||||
R.string.copy_from_other_profile,
|
||||
R.drawable.ic_action_copy,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
}
|
||||
})));
|
||||
return items;
|
||||
}
|
||||
|
||||
public void showExitDialog() {
|
||||
|
@ -235,170 +283,74 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public void setType(@NonNull ScreenType type) {
|
||||
this.type = type;
|
||||
private void setScreenType(@NonNull ScreenType screenType) {
|
||||
this.screenType = screenType;
|
||||
}
|
||||
|
||||
private List<AdapterItem> getAdapterItems() {
|
||||
List<AdapterItem> items = new ArrayList<>();
|
||||
items.add(new AdapterItem(DESCRIPTION, type));
|
||||
private void resetMenuItems(@NonNull ScreenType screenType) {
|
||||
saveHiddenItemsIds(screenType, null);
|
||||
saveItemsIdsOrder(screenType, null);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private List<String> getHiddenItemsIds(@NonNull ScreenType type) {
|
||||
List<String> hiddenItemsIds = null;
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
items.addAll(getDrawerAdapterItems());
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
items.addAll(getConfigureMapAdapterItems());
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
items.addAll(getContextMenuActionsAdapterItems());
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
|
||||
break;
|
||||
}
|
||||
items.add(new AdapterItem(DIVIDER, 1));
|
||||
items.add(new AdapterItem(BUTTON, new ButtonItem(
|
||||
R.string.reset_to_default,
|
||||
R.drawable.ic_action_reset_to_default_dark,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
hiddenMenuItems.clear();
|
||||
menuItemsOrder.clear();
|
||||
menuItemsManager.resetMenuItems(type);
|
||||
adapter.updateItems(getAdapterItems());
|
||||
}
|
||||
})));
|
||||
items.add(new AdapterItem(BUTTON, new ButtonItem(
|
||||
R.string.copy_from_other_profile,
|
||||
R.drawable.ic_action_copy,
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
//TODO
|
||||
}
|
||||
})));
|
||||
return items;
|
||||
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
|
||||
}
|
||||
|
||||
public List<MenuItemBase> getDrawerItems(boolean hidden) {
|
||||
|
||||
List<MenuItemBase> items = new ArrayList<>();
|
||||
List<MenuItemBase> drawerItems = menuItemsManager.getDrawerItemsDefault();
|
||||
|
||||
for (MenuItemBase menuItemBase : drawerItems) {
|
||||
Integer order = menuItemsOrder.get(menuItemBase.getId());
|
||||
if (order == null) {
|
||||
order = menuItemBase.getOrder();
|
||||
@NonNull
|
||||
private List<String> getItemsIdsOrder(@NonNull ScreenType type) {
|
||||
List<String> hiddenItemsIds = null;
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
hiddenItemsIds = app.getSettings().DRAWER_ITEMS_ORDER.getStringsList();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
hiddenItemsIds = app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.getStringsList();
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
hiddenItemsIds = app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.getStringsList();
|
||||
break;
|
||||
}
|
||||
menuItemBase.setOrder(order);
|
||||
// menuItemBase.setHidden(hiddenMenuItems.contains(menuItemBase.getId()));
|
||||
|
||||
return hiddenItemsIds != null ? new ArrayList<>(hiddenItemsIds) : new ArrayList<String>();
|
||||
}
|
||||
|
||||
Collections.sort(drawerItems, new Comparator<MenuItemBase>() {
|
||||
@Override
|
||||
public int compare(MenuItemBase item1, MenuItemBase item2) {
|
||||
int order1 = item1.getOrder();
|
||||
int order2 = item2.getOrder();
|
||||
return (order1 < order2) ? -1 : ((order1 == order2) ? 0 : 1);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
for (MenuItemBase drawerItem : drawerItems) {
|
||||
if (hidden && hiddenMenuItems.contains(drawerItem.getId())) {
|
||||
drawerItem.setHidden(true);
|
||||
items.add(drawerItem);
|
||||
} else if (!hidden && !hiddenMenuItems.contains(drawerItem.getId())) {
|
||||
drawerItem.setHidden(false);
|
||||
items.add(drawerItem);
|
||||
private void saveHiddenItemsIds(@NonNull ScreenType type, @Nullable List<String> hiddenItemsIds) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return items;
|
||||
|
||||
private void saveItemsIdsOrder(@NonNull ScreenType type, @Nullable List<String> itemsIdsOrder) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder);
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
app.getSettings().CONFIGURE_MAP_ITEMS_ORDER.setStringsList(itemsIdsOrder);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
app.getSettings().CONTEXT_MENU_ACTIONS_ITEMS_ORDER.setStringsList(itemsIdsOrder);
|
||||
break;
|
||||
}
|
||||
|
||||
private List<AdapterItem> getDrawerAdapterItems() {
|
||||
List<AdapterItem> active = convertToAdapterItems(getDrawerItems(false));
|
||||
List<AdapterItem> hidden = convertToAdapterItems(getDrawerItems(true));
|
||||
List<AdapterItem> items = new ArrayList<>(active);
|
||||
if (!hidden.isEmpty()) {
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.shared_string_hidden,
|
||||
R.string.hidden_items_descr,
|
||||
false)
|
||||
));
|
||||
items.addAll(hidden);
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<AdapterItem> convertToAdapterItems(List<MenuItemBase> itemBaseList) {
|
||||
List<AdapterItem> items = new ArrayList<>();
|
||||
for (MenuItemBase menuItem : itemBaseList) {
|
||||
items.add(new AdapterItem(MENU_ITEM, menuItem));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<AdapterItem> getConfigureMapAdapterItems() {
|
||||
List<AdapterItem> items = new ArrayList<>();
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.main_actions,
|
||||
R.string.main_actions_descr,
|
||||
false)
|
||||
));
|
||||
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.additional_actions,
|
||||
R.string.additional_actions_descr,
|
||||
false)
|
||||
));
|
||||
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.shared_string_hidden,
|
||||
R.string.hidden_items_descr,
|
||||
false)
|
||||
));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
private List<AdapterItem> getContextMenuActionsAdapterItems() {
|
||||
List<AdapterItem> items = new ArrayList<>();
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.shared_string_show,
|
||||
R.string.move_inside_category,
|
||||
false)
|
||||
));
|
||||
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.map_widget_map_rendering,
|
||||
R.string.move_inside_category,
|
||||
false)
|
||||
));
|
||||
|
||||
items.add(new AdapterItem(HEADER, new HeaderItem(
|
||||
R.string.shared_string_hidden,
|
||||
R.string.reset_items_descr,
|
||||
false)
|
||||
));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
// private List<MenuItemBase> getDrawerItems() {
|
||||
// List<MenuItemBase> items = new ArrayList<>();
|
||||
//
|
||||
// return items;
|
||||
// }
|
||||
|
||||
// private List<MenuItemBase> getConfigureMapItems() {
|
||||
// List<MenuItemBase> items = new ArrayList<>();
|
||||
//
|
||||
// return items;
|
||||
// }
|
||||
|
||||
// private List<MenuItemBase> getContextMenuActionsItems() {
|
||||
// List<MenuItemBase> items = new ArrayList<>();
|
||||
//
|
||||
// return items;
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -49,7 +49,6 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
|
|||
private OsmandApplication app;
|
||||
private LayoutInflater mInflater;
|
||||
private boolean nightMode;
|
||||
private MenuItemsManager menuItemsManager;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -57,7 +56,6 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
|
|||
app = requireMyApplication();
|
||||
nightMode = !app.getSettings().isLightContent();
|
||||
mInflater = UiUtilities.getInflater(app, nightMode);
|
||||
menuItemsManager = new MenuItemsManager(app);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -204,18 +202,20 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
|
||||
private String getSubTitleText(ScreenType type) {
|
||||
int allCount = 0;
|
||||
int hiddenCount = 0;
|
||||
List<String> hiddenItems = null;
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
allCount = menuItemsManager.getDrawerIdsDefaultOrder().size();
|
||||
hiddenCount = menuItemsManager.getHiddenItemsIds(type).size();
|
||||
hiddenItems = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
hiddenItems = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
hiddenItems = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
|
||||
break;
|
||||
}
|
||||
int hiddenCount = hiddenItems != null ? hiddenItems.size() : 0;
|
||||
int allCount = 0;
|
||||
String amount = getString(R.string.n_items_of_z, String.valueOf(allCount - hiddenCount), String.valueOf(allCount));
|
||||
return getString(R.string.ltr_or_rtl_combine_via_colon, getString(R.string.shared_string_items), amount);
|
||||
}
|
||||
|
|
|
@ -1,184 +0,0 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.settings.MenuItemsAdapter.MenuItemBase;
|
||||
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
|
||||
import net.osmand.plus.OsmandSettings.ListStringPreference;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_BUILDS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_MAP_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_CONFIGURE_SCREEN_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DASHBOARD_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIRECTIONS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DOWNLOAD_MAPS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_HELP_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MAP_MARKERS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MEASURE_DISTANCE_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MY_PLACES_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_OSMAND_LIVE_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_PLUGINS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_TRAVEL_GUIDES_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_AVOID_ROAD;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CHANGE_MARKER_POSITION;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_DOWNLOAD_MAP;
|
||||
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_MEASURE_DISTANCE;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MODIFY_OSM_CHANGE;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MODIFY_OSM_NOTE;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MODIFY_POI;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_SEARCH_NEARBY;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_UPDATE_MAP;
|
||||
|
||||
public class MenuItemsManager {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public MenuItemsManager(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
List<MenuItemBase> getDrawerItemsDefault() {
|
||||
List<MenuItemBase> items = new ArrayList<>();
|
||||
items.add(new MenuItemBase(DRAWER_DASHBOARD_ID, R.string.home, R.string.app_name_osmand, R.drawable.map_dashboard, 0, false));
|
||||
items.add(new MenuItemBase(DRAWER_MAP_MARKERS_ID, R.string.map_markers, R.string.app_name_osmand, R.drawable.ic_action_flag_dark, 1, false));
|
||||
items.add(new MenuItemBase(DRAWER_MY_PLACES_ID, R.string.shared_string_my_places, R.string.app_name_osmand, R.drawable.ic_action_fav_dark, 2, false));
|
||||
items.add(new MenuItemBase(DRAWER_SEARCH_ID, R.string.shared_string_search, R.string.app_name_osmand, R.drawable.ic_action_search_dark, 3, false));
|
||||
items.add(new MenuItemBase(DRAWER_DIRECTIONS_ID, R.string.get_directions, R.string.app_name_osmand, R.drawable.ic_action_gdirections_dark, 4, false));
|
||||
items.add(new MenuItemBase(DRAWER_CONFIGURE_MAP_ID, R.string.configure_map, R.string.app_name_osmand, R.drawable.ic_action_layers, 5, false));
|
||||
items.add(new MenuItemBase(DRAWER_DOWNLOAD_MAPS_ID, R.string.shared_string_download_map, R.string.app_name_osmand, R.drawable.ic_type_archive, 6, false));
|
||||
items.add(new MenuItemBase(DRAWER_OSMAND_LIVE_ID, R.string.osm_live, R.string.app_name_osmand, R.drawable.ic_action_osm_live, 7, false));
|
||||
items.add(new MenuItemBase(DRAWER_TRAVEL_GUIDES_ID, R.string.wikivoyage_travel_guide, R.string.app_name_osmand, R.drawable.ic_action_travel, 8, false));
|
||||
items.add(new MenuItemBase(DRAWER_MEASURE_DISTANCE_ID, R.string.measurement_tool, R.string.app_name_osmand, R.drawable.ic_action_ruler, 9, false));
|
||||
items.add(new MenuItemBase(DRAWER_DIVIDER_ID, R.string.shared_string_divider, R.string.divider_descr, 0, 10, false));
|
||||
items.add(new MenuItemBase(DRAWER_CONFIGURE_SCREEN_ID, R.string.layer_map_appearance, R.string.app_name_osmand, R.drawable.ic_configure_screen_dark, 11, false));
|
||||
items.add(new MenuItemBase(DRAWER_PLUGINS_ID, R.string.plugins_screen, R.string.app_name_osmand, R.drawable.ic_extension_dark, 12, false));
|
||||
items.add(new MenuItemBase(DRAWER_SETTINGS_ID + ".new", R.string.shared_string_settings, R.string.app_name_osmand, R.drawable.ic_action_settings, 13, false));
|
||||
items.add(new MenuItemBase(DRAWER_HELP_ID, R.string.shared_string_help, R.string.app_name_osmand, R.drawable.ic_action_help, 14, false));
|
||||
if (Version.isDeveloperVersion(app)) {
|
||||
items.add(new MenuItemBase(DRAWER_BUILDS_ID, R.string.version_settings, R.string.developer_plugin, R.drawable.ic_action_gabout_dark, 15, false));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public List<String> getHiddenItemsIds(@NonNull ScreenType type) {
|
||||
List<String> hiddenItemsIds = null;
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_DRAWER_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.getStringsList();
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
hiddenItemsIds = app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.getStringsList();
|
||||
break;
|
||||
}
|
||||
return hiddenItemsIds != null ? hiddenItemsIds : new ArrayList<String>();
|
||||
}
|
||||
|
||||
public void saveHiddenItemsIds(@NonNull ScreenType type, @Nullable List<String> hiddenItemsIds) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
app.getSettings().HIDDEN_CONFIGURE_MAP_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
app.getSettings().HIDDEN_CONTEXT_MENU_ACTIONS_ITEMS.setStringsList(hiddenItemsIds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveItemsIdsOrder(@NonNull ScreenType type, @Nullable List<String> itemsIdsOrder) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(itemsIdsOrder);
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void reorderMenuItems(@NonNull List<MenuItemBase> defaultItems, @NonNull HashMap<String, Integer> itemsOrder) {
|
||||
for (MenuItemBase item : defaultItems) {
|
||||
Integer order = itemsOrder.get(item.getId());
|
||||
if (order != null) {
|
||||
item.setOrder(order);
|
||||
}
|
||||
}
|
||||
Collections.sort(defaultItems, new Comparator<MenuItemBase>() {
|
||||
@Override
|
||||
public int compare(MenuItemBase item1, MenuItemBase item2) {
|
||||
int order1 = item1.getOrder();
|
||||
int order2 = item2.getOrder();
|
||||
return (order1 < order2) ? -1 : ((order1 == order2) ? 0 : 1);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void resetMenuItems(@NonNull ScreenType type) {
|
||||
switch (type) {
|
||||
case DRAWER:
|
||||
app.getSettings().DRAWER_ITEMS_ORDER.setStringsList(null);
|
||||
app.getSettings().HIDDEN_DRAWER_ITEMS.setStringsList(null);
|
||||
break;
|
||||
case CONFIGURE_MAP:
|
||||
break;
|
||||
case CONTEXT_MENU_ACTIONS:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getDrawerIdsDefaultOrder() {
|
||||
return getMenuItemsIdsDefaultOrder(getDrawerItemsDefault());
|
||||
}
|
||||
|
||||
public LinkedHashMap<String, Integer> getDrawerItemsSavedOrder() {
|
||||
return getMenuItemsOrder(app.getSettings().DRAWER_ITEMS_ORDER);
|
||||
}
|
||||
|
||||
private List<String> getMenuItemsIdsDefaultOrder(List<MenuItemBase> items) {
|
||||
List<String> itemsIds = new ArrayList<>();
|
||||
for (MenuItemBase item : items) {
|
||||
itemsIds.add(item.getId());
|
||||
}
|
||||
return itemsIds;
|
||||
}
|
||||
|
||||
private LinkedHashMap<String, Integer> getMenuItemsOrder(ListStringPreference preference) {
|
||||
List<String> ids = preference.getStringsList();
|
||||
if (ids == null) {
|
||||
ids = getDrawerIdsDefaultOrder();
|
||||
}
|
||||
LinkedHashMap<String, Integer> result = new LinkedHashMap<>();
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
result.put(ids.get(i), i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ import androidx.core.view.MotionEventCompat;
|
|||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -28,8 +29,12 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_DIVIDER_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATEGORY_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.RENDERING_ITEMS_ID_SCHEME;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID;
|
||||
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_ITEMS_ID_SCHEME;
|
||||
|
||||
public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||
implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
@ -40,7 +45,7 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
private int activeColorRes;
|
||||
|
||||
|
||||
MenuItemsAdapter(OsmandApplication app,
|
||||
public RearrangeMenuItemsAdapter(OsmandApplication app,
|
||||
List<AdapterItem> items) {
|
||||
this.app = app;
|
||||
this.items = items;
|
||||
|
@ -95,17 +100,35 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
h.image.setImageResource(nightMode ? screenType.imageNightRes : screenType.imageDayRes);
|
||||
} else if (holder instanceof ItemHolder) {
|
||||
final ItemHolder h = (ItemHolder) holder;
|
||||
MenuItemBase menuItem = (MenuItemBase) item.value;
|
||||
h.title.setText(menuItem.titleRes);
|
||||
h.description.setText(String.valueOf(menuItem.order));
|
||||
if (DRAWER_DIVIDER_ID.equals(menuItem.id)) {
|
||||
ContextMenuItem menuItem = (ContextMenuItem) item.value;
|
||||
String id = menuItem.getId();
|
||||
if (DRAWER_DIVIDER_ID.equals(menuItem.getId())) {
|
||||
h.title.setText(R.string.shared_string_divider);
|
||||
h.description.setText(R.string.divider_descr);
|
||||
h.icon.setVisibility(View.GONE);
|
||||
h.actionIcon.setVisibility(View.GONE);
|
||||
h.moveIcon.setVisibility(View.VISIBLE);
|
||||
h.divider.setVisibility(View.VISIBLE);
|
||||
} else if (SHOW_CATEGORY_ID.equals(id)
|
||||
|| MAP_RENDERING_CATEGORY_ID.equals(id)) {
|
||||
h.title.setText(menuItem.getTitle());
|
||||
h.description.setText(R.string.move_inside_category);
|
||||
h.icon.setVisibility(View.GONE);
|
||||
h.actionIcon.setVisibility(View.GONE);
|
||||
h.moveIcon.setVisibility(View.GONE);
|
||||
h.divider.setVisibility(View.VISIBLE);
|
||||
h.movable = false;
|
||||
} else {
|
||||
h.icon.setImageDrawable(uiUtilities.getIcon(menuItem.iconRes, nightMode));
|
||||
if (menuItem.getIcon() != -1) {
|
||||
h.icon.setImageDrawable(uiUtilities.getIcon(menuItem.getIcon(), nightMode));
|
||||
h.icon.setVisibility(View.VISIBLE);
|
||||
h.actionIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
h.title.setText(menuItem.getTitle());
|
||||
h.description.setText(String.valueOf(menuItem.getOrder()));
|
||||
h.divider.setVisibility(View.GONE);
|
||||
h.moveIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
h.actionIcon.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -124,7 +147,7 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
return false;
|
||||
}
|
||||
});
|
||||
if (menuItem.hidden) {
|
||||
if (menuItem.isHidden()) {
|
||||
h.moveIcon.setVisibility(View.GONE);
|
||||
h.actionIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_undo, R.color.color_osm_edit_create));
|
||||
} else {
|
||||
|
@ -137,22 +160,7 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
HeaderItem header = (HeaderItem) item.value;
|
||||
h.title.setText(header.titleRes);
|
||||
h.description.setText(header.descrRes);
|
||||
h.movable = header.movable;
|
||||
if (header.movable) {
|
||||
h.moveIcon.setVisibility(View.VISIBLE);
|
||||
h.moveIcon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_item_move, activeColorRes));
|
||||
h.moveIcon.setOnTouchListener(new View.OnTouchListener() {
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent event) {
|
||||
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
|
||||
listener.onDragStarted(holder);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
h.moveIcon.setVisibility(View.GONE);
|
||||
}
|
||||
} else if (holder instanceof ButtonHolder) {
|
||||
ButtonHolder h = (ButtonHolder) holder;
|
||||
ButtonItem button = (ButtonItem) item.value;
|
||||
|
@ -173,19 +181,25 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
public boolean onItemMove(int from, int to) {
|
||||
Object itemFrom = items.get(from).value;
|
||||
Object itemTo = items.get(to).value;
|
||||
if (itemFrom instanceof MenuItemBase
|
||||
&& itemTo instanceof MenuItemBase) {
|
||||
MenuItemBase menuItemFrom = (MenuItemBase) itemFrom;
|
||||
MenuItemBase menuItemTo = (MenuItemBase) itemTo;
|
||||
if (itemFrom instanceof ContextMenuItem
|
||||
&& itemTo instanceof ContextMenuItem) {
|
||||
ContextMenuItem menuItemFrom = (ContextMenuItem) itemFrom;
|
||||
ContextMenuItem menuItemTo = (ContextMenuItem) itemTo;
|
||||
|
||||
int orderFrom = menuItemFrom.order;
|
||||
int orderTo = menuItemTo.order;
|
||||
int orderFrom = menuItemFrom.getOrder();
|
||||
int orderTo = menuItemTo.getOrder();
|
||||
|
||||
menuItemFrom.order = orderTo;
|
||||
menuItemTo.order = orderFrom;
|
||||
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)
|
||||
|| menuItemTo.isHidden()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
listener.onItemMoved(menuItemFrom.id, orderTo);
|
||||
listener.onItemMoved(menuItemTo.id, orderFrom);
|
||||
menuItemFrom.setOrder(orderTo);
|
||||
menuItemTo.setOrder(orderFrom);
|
||||
|
||||
listener.onItemMoved(menuItemFrom.getId(), orderTo);
|
||||
listener.onItemMoved(menuItemTo.getId(), orderFrom);
|
||||
|
||||
Collections.swap(items, from, to);
|
||||
notifyItemMoved(from, to);
|
||||
|
@ -224,6 +238,8 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
private ImageView icon;
|
||||
private ImageView actionIcon;
|
||||
private ImageView moveIcon;
|
||||
private View divider;
|
||||
private boolean movable = true;
|
||||
|
||||
ItemHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -232,11 +248,12 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
actionIcon = itemView.findViewById(R.id.action_icon);
|
||||
icon = itemView.findViewById(R.id.icon);
|
||||
moveIcon = itemView.findViewById(R.id.move_icon);
|
||||
divider = itemView.findViewById(R.id.divider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMovingDisabled() {
|
||||
return false;
|
||||
return !movable;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,7 +277,6 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
private ImageView moveIcon;
|
||||
private TextView title;
|
||||
private TextView description;
|
||||
private boolean movable;
|
||||
|
||||
HeaderHolder(@NonNull View itemView) {
|
||||
super(itemView);
|
||||
|
@ -271,7 +287,7 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
|
||||
@Override
|
||||
public boolean isMovingDisabled() {
|
||||
return !movable;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -294,11 +310,11 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
}
|
||||
}
|
||||
|
||||
static class AdapterItem {
|
||||
public static class AdapterItem {
|
||||
private AdapterItemType type;
|
||||
private Object value;
|
||||
|
||||
AdapterItem(AdapterItemType type, Object value) {
|
||||
public AdapterItem(AdapterItemType type, Object value) {
|
||||
this.type = type;
|
||||
this.value = value;
|
||||
}
|
||||
|
@ -312,78 +328,30 @@ public class MenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
|
|||
}
|
||||
}
|
||||
|
||||
public static class MenuItemBase {
|
||||
private String id;
|
||||
@StringRes
|
||||
private int titleRes;
|
||||
@StringRes
|
||||
private int descrRes;
|
||||
@DrawableRes
|
||||
private int iconRes;
|
||||
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
private int order;
|
||||
|
||||
public void setHidden(boolean hidden) {
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
private boolean hidden;
|
||||
|
||||
public MenuItemBase(String id, int titleRes, int descrRes, int iconRes, int order, boolean hidden) {
|
||||
this.id = id;
|
||||
this.titleRes = titleRes;
|
||||
this.descrRes = descrRes;
|
||||
this.iconRes = iconRes;
|
||||
this.order = order;
|
||||
this.hidden = hidden;
|
||||
}
|
||||
|
||||
public void toggleHidden() {
|
||||
hidden = !hidden;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
}
|
||||
|
||||
static class ButtonItem {
|
||||
public static class ButtonItem {
|
||||
@StringRes
|
||||
private int titleRes;
|
||||
@DrawableRes
|
||||
private int iconRes;
|
||||
private View.OnClickListener listener;
|
||||
|
||||
ButtonItem(int titleRes, int iconRes, View.OnClickListener listener) {
|
||||
public ButtonItem(int titleRes, int iconRes, View.OnClickListener listener) {
|
||||
this.titleRes = titleRes;
|
||||
this.iconRes = iconRes;
|
||||
this.listener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
static class HeaderItem {
|
||||
public static class HeaderItem {
|
||||
@StringRes
|
||||
private int titleRes;
|
||||
@StringRes
|
||||
private int descrRes;
|
||||
boolean movable;
|
||||
|
||||
HeaderItem(int titleRes, int descrRes, boolean movable) {
|
||||
public HeaderItem(int titleRes, int descrRes) {
|
||||
this.titleRes = titleRes;
|
||||
this.descrRes = descrRes;
|
||||
this.movable = movable;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue