Remove unnecessary item touch helper
This commit is contained in:
parent
fa1bca7c10
commit
c93859b117
6 changed files with 29 additions and 42 deletions
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
|
||||||
<string name="shared_string_downloading_formatted">Downloading %s</string>
|
<string name="shared_string_downloading_formatted">Downloading %s</string>
|
||||||
<string name="edit_profiles_descr">You can’t delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom.</string>
|
<string name="edit_profiles_descr">You can’t delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom.</string>
|
||||||
<string name="edit_profiles">Edit profiles</string>
|
<string name="edit_profiles">Edit profiles</string>
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.profiles;
|
||||||
|
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
|
||||||
public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||||
|
@ -24,6 +25,9 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
|
||||||
|
if (isImmobileViewHolder(viewHolder)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
|
||||||
int swipeFlags = 0;
|
int swipeFlags = 0;
|
||||||
return makeMovementFlags(dragFlags, swipeFlags);
|
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) {
|
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder source, RecyclerView.ViewHolder target) {
|
||||||
int from = source.getAdapterPosition();
|
int from = source.getAdapterPosition();
|
||||||
int to = target.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 false;
|
||||||
}
|
}
|
||||||
return itemMoveCallback.onItemMove(from, to);
|
return itemMoveCallback.onItemMove(from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isImmobileViewHolder(RecyclerView.ViewHolder viewHolder) {
|
||||||
|
return viewHolder instanceof ImmobileViewHolder;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||||
|
|
||||||
|
@ -56,4 +65,11 @@ public class ReorderItemTouchHelperCallback extends ItemTouchHelper.Callback {
|
||||||
|
|
||||||
void onItemDismiss(RecyclerView.ViewHolder holder);
|
void onItemDismiss(RecyclerView.ViewHolder holder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class ImmobileViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
|
||||||
|
public ImmobileViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -28,6 +28,7 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
|
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -93,7 +94,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
|
||||||
quickActionRV.setAdapter(adapter);
|
quickActionRV.setAdapter(adapter);
|
||||||
quickActionRV.setLayoutManager(new LinearLayoutManager(getContext()));
|
quickActionRV.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||||
|
|
||||||
ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter);
|
ItemTouchHelper.Callback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter);
|
||||||
touchHelper = new ItemTouchHelper(touchHelperCallback);
|
touchHelper = new ItemTouchHelper(touchHelperCallback);
|
||||||
touchHelper.attachToRecyclerView(quickActionRV);
|
touchHelper.attachToRecyclerView(quickActionRV);
|
||||||
adapter.addItems(quickActionRegistry.getFilteredQuickActions());
|
adapter.addItems(quickActionRegistry.getFilteredQuickActions());
|
||||||
|
@ -187,7 +188,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
|
||||||
adapter.addItems(quickActionRegistry.getFilteredQuickActions());
|
adapter.addItems(quickActionRegistry.getFilteredQuickActions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
|
public class QuickActionAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
|
||||||
public static final int SCREEN_ITEM_TYPE = 1;
|
public static final int SCREEN_ITEM_TYPE = 1;
|
||||||
public static final int SCREEN_HEADER_TYPE = 2;
|
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 TextView headerName;
|
||||||
|
|
||||||
public QuickActionHeaderVH(View itemView) {
|
public QuickActionHeaderVH(View itemView) {
|
||||||
|
|
|
@ -20,6 +20,7 @@ import android.widget.TextView;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
|
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
|
||||||
|
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -67,7 +68,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
QuickActionItemTouchHelperCallback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter);
|
ReorderItemTouchHelperCallback touchHelperCallback = new ReorderItemTouchHelperCallback(adapter);
|
||||||
touchHelper = new ItemTouchHelper(touchHelperCallback);
|
touchHelper = new ItemTouchHelper(touchHelperCallback);
|
||||||
touchHelper.attachToRecyclerView(list);
|
touchHelper.attachToRecyclerView(list);
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
||||||
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
|
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements QuickActionItemTouchHelperCallback.OnItemMoveCallback {
|
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
|
||||||
|
|
||||||
private List<T> itemsList = new ArrayList<>();
|
private List<T> itemsList = new ArrayList<>();
|
||||||
private final QuickActionListFragment.OnStartDragListener onStartDragListener;
|
private final QuickActionListFragment.OnStartDragListener onStartDragListener;
|
||||||
|
|
|
@ -77,9 +77,9 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
|
||||||
protected void setupPreferences() {
|
protected void setupPreferences() {
|
||||||
setupRouteParametersImage();
|
setupRouteParametersImage();
|
||||||
|
|
||||||
Preference vehicleParametersInfo = findPreference(ROUTE_PARAMETERS_INFO);
|
Preference routeParametersInfo = findPreference(ROUTE_PARAMETERS_INFO);
|
||||||
vehicleParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
routeParametersInfo.setIcon(getContentIcon(R.drawable.ic_action_info_dark));
|
||||||
vehicleParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext())));
|
routeParametersInfo.setTitle(getString(R.string.route_parameters_info, getSelectedAppMode().toHumanString(getContext())));
|
||||||
|
|
||||||
setupRoutingPrefs();
|
setupRoutingPrefs();
|
||||||
setupTimeConditionalRoutingPref();
|
setupTimeConditionalRoutingPref();
|
||||||
|
|
Loading…
Reference in a new issue