This commit is contained in:
veliymolfar 2020-04-15 17:10:54 +03:00
parent 18d6a67adb
commit 7aa3948188
4 changed files with 60 additions and 52 deletions

View file

@ -41,7 +41,7 @@
<string name="shared_string_drawer">Drawer</string>
<string name="ui_customization">UI Customization</string>
<string name="ui_customization_short_descr">Drawer items, context menu</string>
<string name="ui_customization_description">Customize the quantity of items in Drawer, Configure map and context menu.\n\nYou can disable unused plugins, to hide all its controls from the application.</string>
<string name="ui_customization_description">Customize the quantity of items in Drawer, Configure map and context menu.\n\nYou can disable unused plugins, to hide all its controls from the application %1$s.</string>
<string name="shared_string_min">Min</string>
<string name="shared_string_square">Square</string>
<string name="shared_string_octagon">Octagon</string>

View file

@ -39,7 +39,7 @@ import net.osmand.plus.profiles.SelectCopyAppModeBottomSheet;
import net.osmand.plus.settings.ConfigureMenuRootFragment.ScreenType;
import net.osmand.plus.settings.bottomsheets.ChangeGeneralProfilesPrefBottomSheet;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.AdapterItem;
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.RearrangeMenuAdapterItem;
import net.osmand.plus.settings.RearrangeMenuItemsAdapter.MenuItemsAdapterListener;
import org.apache.commons.logging.Log;
@ -61,6 +61,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
implements SelectCopyAppModeBottomSheet.CopyAppModePrefsListener {
public static final String TAG = ConfigureMenuItemsFragment.class.getName();
public static final int MAIN_BUTTONS_QUANTITY = 4;
private static final Log LOG = PlatformUtil.getLog(ConfigureMenuItemsFragment.class.getName());
private static final String APP_MODE_KEY = "app_mode_key";
private static final String ITEM_TYPE_KEY = "item_type_key";
@ -172,7 +173,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
TextView toolbarTitle = root.findViewById(R.id.toolbar_title);
ImageButton toolbarButton = root.findViewById(R.id.close_button);
RecyclerView recyclerView = root.findViewById(R.id.profiles_list);
recyclerView.setPadding(0, 0, 0, AndroidUtils.dpToPx(app, 72));
recyclerView.setPadding(0, 0, 0, (int) app.getResources().getDimension(R.dimen.dialog_button_ex_min_width));
toolbar.setBackgroundColor(nightMode
? getResources().getColor(R.color.list_background_color_dark)
: getResources().getColor(R.color.list_background_color_light));
@ -213,9 +214,9 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
@Override
public void onButtonClicked(int position) {
AdapterItem adapterItem = rearrangeAdapter.getItem(position);
if (adapterItem.getValue() instanceof ContextMenuItem) {
ContextMenuItem menuItemBase = (ContextMenuItem) adapterItem.getValue();
RearrangeMenuAdapterItem rearrangeMenuAdapterItem = rearrangeAdapter.getItem(position);
if (rearrangeMenuAdapterItem.getValue() instanceof ContextMenuItem) {
ContextMenuItem menuItemBase = (ContextMenuItem) rearrangeMenuAdapterItem.getValue();
menuItemBase.setHidden(!menuItemBase.isHidden());
if (menuItemBase.isHidden()) {
hiddenMenuItems.add(menuItemBase.getId());
@ -292,35 +293,36 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
return root;
}
private List<AdapterItem> getAdapterItems() {
List<AdapterItem> items = new ArrayList<>();
items.add(new AdapterItem(DESCRIPTION, screenType));
private List<RearrangeMenuAdapterItem> getAdapterItems() {
List<RearrangeMenuAdapterItem> items = new ArrayList<>();
items.add(new RearrangeMenuAdapterItem(DESCRIPTION, screenType));
List<AdapterItem> visible = getItemsForRearrangeAdapter(hiddenMenuItems, wasReset ? null : menuItemsOrder, false);
List<AdapterItem> hiddenItems = getItemsForRearrangeAdapter(hiddenMenuItems, wasReset ? null : menuItemsOrder, true);
List<RearrangeMenuAdapterItem> visible = getItemsForRearrangeAdapter(hiddenMenuItems, wasReset ? null : menuItemsOrder, false);
List<RearrangeMenuAdapterItem> hiddenItems = getItemsForRearrangeAdapter(hiddenMenuItems, wasReset ? null : menuItemsOrder, true);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
for (int i =0; i<visible.size(); i++){
for (int i = 0; i < visible.size(); i++) {
ContextMenuItem value = (ContextMenuItem) visible.get(i).getValue();
if (value.getId() != null && value.getId().equals(MAP_CONTEXT_MENU_MORE_ID)){
if (i >3){
AdapterItem third = visible.get(3);
visible.set(3,visible.get(i));
menuItemsOrder.put(((ContextMenuItem) third.getValue()).getId(),i);
menuItemsOrder.put(((ContextMenuItem) visible.get(i).getValue()).getId(),3);
if (value.getId() != null && value.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
int buttonMoreIndex = MAIN_BUTTONS_QUANTITY - 1;
if (i > buttonMoreIndex) {
RearrangeMenuAdapterItem third = visible.get(buttonMoreIndex);
visible.set(buttonMoreIndex, visible.get(i));
menuItemsOrder.put(((ContextMenuItem) third.getValue()).getId(), i);
menuItemsOrder.put(((ContextMenuItem) visible.get(i).getValue()).getId(), buttonMoreIndex);
}
}
}
List<AdapterItem> main = new ArrayList<>();
int actionsIndex = Math.min(4, visible.size());
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));
}
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr)));
items.add(new RearrangeMenuAdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.main_actions, R.string.main_actions_descr)));
items.addAll(main);
items.add(new AdapterItem(HEADER, new RearrangeMenuItemsAdapter.HeaderItem(R.string.additional_actions, R.string.additional_actions_descr)));
List<AdapterItem> additional = new ArrayList<>();
for (int i = 4; i < visible.size(); i++) {
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);
@ -328,11 +330,11 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
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.add(new RearrangeMenuAdapterItem(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(
items.add(new RearrangeMenuAdapterItem(DIVIDER, 1));
items.add(new RearrangeMenuAdapterItem(BUTTON, new RearrangeMenuItemsAdapter.ButtonItem(
R.string.reset_to_default,
R.drawable.ic_action_reset_to_default_dark,
new View.OnClickListener() {
@ -347,7 +349,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
rearrangeAdapter.updateItems(getAdapterItems());
}
})));
items.add(new AdapterItem(BUTTON, new RearrangeMenuItemsAdapter.ButtonItem(
items.add(new RearrangeMenuAdapterItem(BUTTON, new RearrangeMenuItemsAdapter.ButtonItem(
R.string.copy_from_other_profile,
R.drawable.ic_action_copy,
new View.OnClickListener() {
@ -411,7 +413,7 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
}
public static OsmandSettings.ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) {
public static OsmandSettings.ContextMenuItemsPreference getSettingForScreen(OsmandApplication app, ScreenType screenType) throws IllegalArgumentException {
switch (screenType) {
case DRAWER:
return app.getSettings().DRAWER_ITEMS;
@ -430,23 +432,23 @@ public class ConfigureMenuItemsFragment extends BaseOsmAndFragment
}
}
public List<AdapterItem> getItemsForRearrangeAdapter(@Nullable List<String> hiddenItemsIds, @Nullable HashMap<String, Integer> itemsOrderIds, boolean hidden) {
public List<RearrangeMenuAdapterItem> getItemsForRearrangeAdapter(@Nullable List<String> hiddenItemsIds, @Nullable HashMap<String, Integer> itemsOrderIds, boolean hidden) {
List<ContextMenuItem> defItems = contextMenuAdapter.getDefaultItems();
if (itemsOrderIds == null || itemsOrderIds.isEmpty()) {
initDefaultOrders(defItems);
} else {
sortByCustomOrder(defItems, itemsOrderIds);
}
List<AdapterItem> visibleItems = new ArrayList<>();
List<AdapterItem> hiddenItems = new ArrayList<>();
List<RearrangeMenuAdapterItem> visibleItems = new ArrayList<>();
List<RearrangeMenuAdapterItem> hiddenItems = new ArrayList<>();
for (ContextMenuItem item : defItems) {
String id = item.getId();
if (hiddenItemsIds != null && hiddenItemsIds.contains(id)) {
item.setHidden(true);
hiddenItems.add(new AdapterItem(MENU_ITEM, item));
hiddenItems.add(new RearrangeMenuAdapterItem(MENU_ITEM, item));
} else {
item.setHidden(false);
visibleItems.add(new AdapterItem(MENU_ITEM, item));
visibleItems.add(new RearrangeMenuAdapterItem(MENU_ITEM, item));
}
}
return hidden ? hiddenItems : visibleItems;

View file

@ -117,7 +117,9 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
toolbarSubTitle.setText(appMode.toHumanString());
toolbarSubTitle.setVisibility(View.VISIBLE);
List<Object> items = new ArrayList<>();
items.add(getString(R.string.ui_customization_description));
String plugins = getString(R.string.prefs_plugins);
String description = String.format(getString(R.string.ui_customization_description), plugins);
items.add(description);
items.addAll(Arrays.asList(ScreenType.values()));
CustomizationItemsAdapter adapter = new CustomizationItemsAdapter(items, new OnCustomizationItemClickListener() {
@Override
@ -199,10 +201,9 @@ public class ConfigureMenuRootFragment extends BaseOsmAndFragment {
final Object currentItem = items.get(position);
if (holder instanceof DescriptionHolder) {
DescriptionHolder descriptionHolder = (DescriptionHolder) holder;
String plugins = getString(R.string.prefs_plugins) + '.';
String description = String.format(getString(R.string.ltr_or_rtl_combine_via_space), (String) currentItem, plugins);
String plugins = getString(R.string.prefs_plugins);
setupClickableText(
descriptionHolder.description, description, plugins, new Intent(app, PluginsActivity.class));
descriptionHolder.description, (String) currentItem, plugins, new Intent(app, PluginsActivity.class));
descriptionHolder.image.setVisibility(View.GONE);
} else {
final ScreenType item = (ScreenType) currentItem;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.settings;
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
@ -37,6 +38,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_RENDERING_CATE
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;
import static net.osmand.plus.settings.ConfigureMenuItemsFragment.MAIN_BUTTONS_QUANTITY;
public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
@ -44,14 +46,14 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
private OsmandApplication app;
private UiUtilities uiUtilities;
private boolean nightMode;
private List<AdapterItem> items;
private List<RearrangeMenuAdapterItem> items;
private MenuItemsAdapterListener listener;
private int activeColorRes;
private int textColorRes;
public RearrangeMenuItemsAdapter(OsmandApplication app,
List<AdapterItem> items) {
List<RearrangeMenuAdapterItem> items) {
this.app = app;
this.items = items;
uiUtilities = app.getUIUtilities();
@ -66,7 +68,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
@Override
public int getItemViewType(int position) {
AdapterItem item = items.get(position);
RearrangeMenuAdapterItem item = items.get(position);
return item.type.ordinal();
}
@ -100,12 +102,12 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
@SuppressLint("ClickableViewAccessibility")
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
AdapterItem item = items.get(position);
RearrangeMenuAdapterItem item = items.get(position);
if (holder instanceof DescriptionHolder) {
DescriptionHolder h = (DescriptionHolder) holder;
ScreenType screenType = (ScreenType) item.value;
int paddingStart = AndroidUtils.dpToPx(app, 56);
int paddingTop = AndroidUtils.dpToPx(app, 16);
int paddingStart = (int) app.getResources().getDimension(R.dimen.toolbar_height);
int paddingTop = (int) app.getResources().getDimension(R.dimen.content_padding);
h.description.setText(String.format(app.getString(R.string.reorder_or_hide_from), app.getString(screenType.titleRes)));
h.image.setImageResource(nightMode ? screenType.imageNightRes : screenType.imageDayRes);
if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
@ -127,7 +129,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
h.title.setText(R.string.shared_string_divider);
h.title.setTypeface(FontCache.getFont(app, app.getString(R.string.font_roboto_medium)));
h.title.setTextColor(app.getResources().getColor(activeColorRes));
h.title.setTextSize(15);
h.title.setTextSize(TypedValue.COMPLEX_UNIT_PX, app.getResources().getDimension(R.dimen.default_list_text_size));
h.description.setText(R.string.divider_descr);
h.icon.setVisibility(View.GONE);
h.actionIcon.setVisibility(View.GONE);
@ -137,7 +139,7 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
|| MAP_RENDERING_CATEGORY_ID.equals(id)) {
h.title.setText(menuItem.getTitle());
h.title.setTypeface(FontCache.getFont(app, app.getString(R.string.font_roboto_medium)));
h.title.setTextSize(15);
h.title.setTextSize(TypedValue.COMPLEX_UNIT_PX, app.getResources().getDimension(R.dimen.default_list_text_size));
h.description.setText(R.string.move_inside_category);
h.icon.setVisibility(View.GONE);
h.actionIcon.setVisibility(View.GONE);
@ -193,6 +195,8 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
} else if (holder instanceof HeaderHolder) {
HeaderHolder h = (HeaderHolder) holder;
HeaderItem header = (HeaderItem) item.value;
h.title.setTypeface(FontCache.getFont(app, app.getString(R.string.font_roboto_medium)));
h.title.setTextSize(TypedValue.COMPLEX_UNIT_PX, app.getResources().getDimension(R.dimen.default_list_text_size));
h.title.setText(header.titleRes);
h.description.setText(header.descrRes);
h.moveIcon.setVisibility(View.GONE);
@ -230,12 +234,13 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
return false;
}
int buttonMoreIndex = MAIN_BUTTONS_QUANTITY + 1;
if (menuItemFrom.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
if (to > 5) {
if (to > buttonMoreIndex) {
return false;
}
} else if (menuItemTo.getId().equals(MAP_CONTEXT_MENU_MORE_ID)) {
if (from > 5) {
if (from > buttonMoreIndex) {
return false;
}
}
@ -359,11 +364,11 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
}
}
public static class AdapterItem {
public static class RearrangeMenuAdapterItem {
private AdapterItemType type;
private Object value;
public AdapterItem(AdapterItemType type, Object value) {
public RearrangeMenuAdapterItem(AdapterItemType type, Object value) {
this.type = type;
this.value = value;
}
@ -427,11 +432,11 @@ public class RearrangeMenuItemsAdapter extends RecyclerView.Adapter<RecyclerView
this.listener = listener;
}
public AdapterItem getItem(int position) {
public RearrangeMenuAdapterItem getItem(int position) {
return items.get(position);
}
public void updateItems(List<AdapterItem> items) {
public void updateItems(List<RearrangeMenuAdapterItem> items) {
this.items = items;
notifyDataSetChanged();
}