diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 5a31278996..d3fbbe47fb 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + After you tap Apply, deleted profiles will be lost completely. Downloading %s You can’t delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom. Edit profiles diff --git a/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java index d81efb9ee2..4b24954760 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ReorderItemTouchHelperCallback.java @@ -2,6 +2,7 @@ package net.osmand.plus.profiles; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.helper.ItemTouchHelper; +import android.view.View; public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback { @@ -24,6 +25,9 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback { @Override public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { + if (isImmobileViewHolder(viewHolder)) { + return 0; + } int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN; int swipeFlags = 0; return makeMovementFlags(dragFlags, swipeFlags); @@ -33,12 +37,17 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback { public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { int from = source.getAdapterPosition(); int to = target.getAdapterPosition(); - if (from == RecyclerView.NO_POSITION || to == RecyclerView.NO_POSITION) { + if (from == RecyclerView.NO_POSITION || to == RecyclerView.NO_POSITION + || isImmobileViewHolder(source) || isImmobileViewHolder(target)) { return false; } return itemMoveCallback.onItemMove(from, to); } + private boolean isImmobileViewHolder(RecyclerView.ViewHolder viewHolder) { + return viewHolder instanceof ImmobileViewHolder; + } + @Override public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) { @@ -56,4 +65,11 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback { void onItemDismiss(RecyclerView.ViewHolder holder); } + + public static class ImmobileViewHolder extends RecyclerView.ViewHolder { + + public ImmobileViewHolder(View itemView) { + super(itemView); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java deleted file mode 100644 index 4e9ff399b5..0000000000 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionItemTouchHelperCallback.java +++ /dev/null @@ -1,33 +0,0 @@ -package net.osmand.plus.quickaction; - -import android.support.v7.widget.RecyclerView; - -import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; - -/** - * Created by okorsun on 21.12.16. - */ - -public class QuickActionItemTouchHelperCallback extends ReorderItemTouchHelperCallback { - - QuickActionItemTouchHelperCallback(OnItemMoveCallback itemMoveCallback) { - super(itemMoveCallback); - } - - @Override - public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) { - return !isaHeaderType(viewHolder) ? super.getMovementFlags(recyclerView, viewHolder) : 0; - } - - @Override - public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) { - if (isaHeaderType(source) || isaHeaderType(target)) { - return false; - } - return super.onMove(recyclerView, source, target); - } - - private boolean isaHeaderType(RecyclerView.ViewHolder viewHolder) { - return viewHolder.getItemViewType() == QuickActionListFragment.QuickActionAdapter.SCREEN_HEADER_TYPE; - } -} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index d4bb874bb9..72be7ca32a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -28,6 +28,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; +import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; import java.util.ArrayList; import java.util.Collections; @@ -93,7 +94,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick quickActionRV.setAdapter(adapter); quickActionRV.setLayoutManager(new LinearLayoutManager(getContext())); - ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter); + ItemTouchHelper.Callback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter); touchHelper = new ItemTouchHelper(touchHelperCallback); touchHelper.attachToRecyclerView(quickActionRV); adapter.addItems(quickActionRegistry.getFilteredQuickActions()); @@ -187,7 +188,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick adapter.addItems(quickActionRegistry.getFilteredQuickActions()); } - public class QuickActionAdapter extends RecyclerView.Adapter implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { + public class QuickActionAdapter extends RecyclerView.Adapter implements ReorderItemTouchHelperCallback.OnItemMoveCallback { public static final int SCREEN_ITEM_TYPE = 1; public static final int SCREEN_HEADER_TYPE = 2; @@ -411,7 +412,8 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick } } - public class QuickActionHeaderVH extends RecyclerView.ViewHolder { + public class QuickActionHeaderVH extends ReorderItemTouchHelperCallback.ImmobileViewHolder { + public TextView headerName; public QuickActionHeaderVH(View itemView) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java index f3258317c7..abad8a7432 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java @@ -20,6 +20,7 @@ import android.widget.TextView; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; +import net.osmand.plus.profiles.ReorderItemTouchHelperCallback; import java.util.ArrayList; import java.util.Collections; @@ -67,7 +68,7 @@ public abstract class SwitchableAction extends QuickAction { } }); - QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter); + ReorderItemTouchHelperCallback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter); touchHelper = new ItemTouchHelper(touchHelperCallback); touchHelper.attachToRecyclerView(list); @@ -116,7 +117,7 @@ public abstract class SwitchableAction extends QuickAction { fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG); } - protected class Adapter extends RecyclerView.Adapter implements QuickActionItemTouchHelperCallback.OnItemMoveCallback { + protected class Adapter extends RecyclerView.Adapter implements ReorderItemTouchHelperCallback.OnItemMoveCallback { private List itemsList = new ArrayList<>(); private final QuickActionListFragment.OnStartDragListener onStartDragListener; diff --git a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java index b23081f31c..80bb914eb0 100644 --- a/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/RouteParametersFragment.java @@ -77,9 +77,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP protected void setupPreferences() { setupRouteParametersImage(); - Preference vehicleParametersInfo = findPreference(ROUTE_PARAMETERS_INFO); - vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); - vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext()))); + Preference routeParametersInfo = findPreference(ROUTE_PARAMETERS_INFO); + routeParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark)); + routeParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext()))); setupRoutingPrefs(); setupTimeConditionalRoutingPref();