use of android.support.v7.widget.helper.ItemTouchHelper in project noChange by Khalidtoak.
the class DebtorsRecord method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_debtors_record, container, false);
recyclerView = rootView.findViewById(R.id.recyclcer_view_debtors);
searchView = rootView.findViewById(R.id.sv2);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setHasFixedSize(true);
creditorsAndDebtorsDataBase = new CreditorsAndDebtorsDataBase(getContext());
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"), getContext());
recyclerView.setAdapter(adapters);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
String query = searchView.getQuery().toString();
adapters = new Adapters(creditorsAndDebtorsDataBase.retrieveByViewPagerAndSearchedText(query, "Debtors"), getContext());
recyclerView.setAdapter(adapters);
return true;
}
});
// ItemTouch helper to handle swipe to delete the saved News function
new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onSwiped(final RecyclerView.ViewHolder viewHolder, int direction) {
final long id1 = (long) viewHolder.itemView.getTag();
// delete the News with id that was swiped off
new AlertDialog.Builder(getContext()).setMessage("Delete?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// delete the News with id that was swiped off
removeCustomer(id1);
Snackbar.make(getView(), "deleted!!", Snackbar.LENGTH_LONG).show();
// now swap the cursor for proper arrangement
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"));
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
adapters.swapCursor(creditorsAndDebtorsDataBase.retrieveByViewpager("Debtors"));
}
}).show();
Log.d(TAG, "onSwiped: did something happen here??");
Log.d(TAG, "onSwiped: did something happen here??");
}
}).attachToRecyclerView(recyclerView);
return rootView;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project PhoneProfilesPlus by henrichg.
the class ApplicationsDialogPreference method showDialog.
@Override
protected void showDialog(Bundle state) {
MaterialDialog.Builder mBuilder = new MaterialDialog.Builder(getContext()).title(getDialogTitle()).icon(getDialogIcon()).autoDismiss(false).content(getDialogMessage()).customView(R.layout.activity_applications_pref_dialog, false).dividerColor(0);
mBuilder.positiveText(getPositiveButtonText()).negativeText(getNegativeButtonText());
mBuilder.onPositive(new MaterialDialog.SingleButtonCallback() {
@SuppressWarnings("StringConcatenationInLoop")
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
if (shouldPersist()) {
// fill with application strings separated with |
value = "";
if (applicationsList != null) {
for (Application application : applicationsList) {
if (!value.isEmpty())
value = value + "|";
if (application.shortcut)
value = value + "(s)";
value = value + application.packageName + "/" + application.activityName;
if (application.shortcut && (application.shortcutId > 0))
value = value + "#" + application.shortcutId;
value = value + "#" + application.startApplicationDelay;
PPApplication.logE("ApplicationsDialogPreference.onPositive", "value=" + value);
}
}
persistString(value);
setIcons();
setSummaryAMSDP();
}
mDialog.dismiss();
}
});
mBuilder.onNegative(new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog materialDialog, @NonNull DialogAction dialogAction) {
mDialog.dismiss();
}
});
mBuilder.showListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
ApplicationsDialogPreference.this.onShow();
}
});
mDialog = mBuilder.build();
View layout = mDialog.getCustomView();
// noinspection ConstantConditions
AppCompatImageButton addButton = layout.findViewById(R.id.applications_pref_dlg_add);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getContext());
applicationsListView = layout.findViewById(R.id.applications_pref_dlg_listview);
// applicationsListView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
applicationsListView.setLayoutManager(layoutManager);
applicationsListView.setHasFixedSize(true);
linlaProgress = layout.findViewById(R.id.applications_pref_dlg_linla_progress);
rellaDialog = layout.findViewById(R.id.applications_pref_dlg_rella_dialog);
listAdapter = new ApplicationsDialogPreferenceAdapter(context, this, this);
// added touch helper for drag and drop items
ItemTouchHelper.Callback callback = new ItemTouchHelperCallback(listAdapter, false, false);
itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(applicationsListView);
addButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startEditor(null);
}
});
GlobalGUIRoutines.registerOnActivityDestroyListener(this, this);
if (state != null)
mDialog.onRestoreInstanceState(state);
mDialog.setOnDismissListener(this);
mDialog.show();
}
use of android.support.v7.widget.helper.ItemTouchHelper in project Osmand by osmandapp.
the class MeasurementToolFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
editingCtx.setApplication(mapActivity.getMyApplication());
editingCtx.setProgressListener(new MeasurementEditingContext.SnapToRoadProgressListener() {
@Override
public void showProgressBar() {
MeasurementToolFragment.this.showProgressBar();
}
@Override
public void updateProgress(int progress) {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setProgress(progress);
}
@Override
public void hideProgressBar() {
((ProgressBar) mainView.findViewById(R.id.snap_to_road_progress_bar)).setVisibility(View.GONE);
progressBarVisible = false;
}
@Override
public void refresh() {
measurementLayer.refreshMap();
updateText();
}
});
measurementLayer.setEditingCtx(editingCtx);
// Handling screen rotation
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
if (selectedPointFragment != null) {
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
fragment.setListener(createSelectedPointFragmentListener());
}
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
if (optionsFragment != null) {
((OptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
}
Fragment snapToRoadFragment = fragmentManager.findFragmentByTag(SnapToRoadBottomSheetDialogFragment.TAG);
if (snapToRoadFragment != null) {
((SnapToRoadBottomSheetDialogFragment) snapToRoadFragment).setListener(createSnapToRoadFragmentListener());
}
Fragment saveAsNewTrackFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(SaveAsNewTrackBottomSheetDialogFragment.TAG);
if (saveAsNewTrackFragment != null) {
((SaveAsNewTrackBottomSheetDialogFragment) saveAsNewTrackFragment).setListener(createSaveAsNewTrackFragmentListener());
}
// the RecyclerViewFragment will exist without view. This is necessary to remove it.
if (!portrait) {
hidePointsListFragment();
}
editingCtx.getCommandManager().resetMeasurementLayer(measurementLayer);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final int backgroundColor = ContextCompat.getColor(getActivity(), nightMode ? R.color.ctx_menu_info_view_bg_dark : R.color.ctx_menu_info_view_bg_light);
portrait = AndroidUiHelper.isOrientationPortrait(getActivity());
upIcon = getContentIcon(R.drawable.ic_action_arrow_up);
downIcon = getContentIcon(R.drawable.ic_action_arrow_down);
pointsSt = getString(R.string.points).toLowerCase();
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_measurement_tool, null);
mainView = view.findViewById(R.id.main_view);
AndroidUtils.setBackground(mapActivity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
pointsListContainer = view.findViewById(R.id.points_list_container);
if (portrait && pointsListContainer != null) {
pointsListContainer.setBackgroundColor(backgroundColor);
}
if (progressBarVisible) {
showProgressBar();
}
distanceTv = (TextView) mainView.findViewById(R.id.measurement_distance_text_view);
pointsTv = (TextView) mainView.findViewById(R.id.measurement_points_text_view);
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
final NewGpxData newGpxData = editingCtx.getNewGpxData();
if (editingCtx.getNewGpxData() != null) {
ActionType actionType = newGpxData.getActionType();
if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
} else {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
}
} else {
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_ruler));
}
upDownBtn = (ImageView) mainView.findViewById(R.id.up_down_button);
upDownBtn.setImageDrawable(upIcon);
mainView.findViewById(R.id.cancel_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelMovePointMode();
}
});
mainView.findViewById(R.id.cancel_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cancelAddPointBeforeOrAfterMode();
}
});
upDownRow = mainView.findViewById(R.id.up_down_row);
upDownRow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!pointsListOpened && editingCtx.getPointsCount() > 0 && editingCtx.getSelectedPointPosition() == -1) {
showPointsList();
} else {
hidePointsList();
}
}
});
mainView.findViewById(R.id.apply_move_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applyMovePointMode();
}
});
mainView.findViewById(R.id.apply_point_before_after_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
applyAddPointBeforeAfterMode();
}
});
mainView.findViewById(R.id.add_point_before_after_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addPointBeforeAfter();
}
});
mainView.findViewById(R.id.options_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Bundle args = new Bundle();
args.putBoolean(OptionsBottomSheetDialogFragment.SNAP_TO_ROAD_ENABLED_KEY, editingCtx.isInSnapToRoadMode());
args.putBoolean(OptionsBottomSheetDialogFragment.ADD_LINE_MODE_KEY, newGpxData != null);
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(true);
fragment.setListener(createOptionsFragmentListener());
fragment.show(mapActivity.getSupportFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
}
});
undoBtn = ((ImageButton) mainView.findViewById(R.id.undo_point_button));
redoBtn = ((ImageButton) mainView.findViewById(R.id.redo_point_button));
undoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_undo_dark));
undoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().undo();
if (editingCtx.getCommandManager().canUndo()) {
enable(undoBtn);
} else {
disable(undoBtn);
}
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
enable(redoBtn);
updateText();
}
});
redoBtn.setImageDrawable(getContentIcon(R.drawable.ic_action_redo_dark));
redoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editingCtx.getCommandManager().redo();
if (editingCtx.getCommandManager().canRedo()) {
enable(redoBtn);
} else {
disable(redoBtn);
}
hidePointsListIfNoPoints();
if (editingCtx.getPointsCount() > 0) {
enable(upDownBtn);
}
adapter.notifyDataSetChanged();
enable(undoBtn);
updateText();
}
});
mainView.findViewById(R.id.add_point_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
addCenterPoint();
}
});
measurementLayer.setOnSingleTapListener(new MeasurementToolLayer.OnSingleTapListener() {
@Override
public void onAddPoint() {
addPoint();
}
@Override
public void onSelectPoint(int selectedPointPos) {
if (pointsListOpened) {
hidePointsList();
}
if (selectedPointPos != -1) {
openSelectedPointMenu(mapActivity);
}
}
});
measurementLayer.setOnMeasureDistanceToCenterListener(new MeasurementToolLayer.OnMeasureDistanceToCenter() {
@Override
public void onMeasure(float distance) {
String distStr = OsmAndFormatter.getFormattedDistance(distance, mapActivity.getMyApplication());
distanceToCenterTv.setText(" – " + distStr);
}
});
measurementLayer.setOnEnterMovePointModeListener(new MeasurementToolLayer.OnEnterMovePointModeListener() {
@Override
public void onEnterMovePointMode() {
if (pointsListOpened) {
hidePointsList();
}
switchMovePointMode(true);
}
});
if (!editingCtx.getCommandManager().canUndo()) {
disable(undoBtn);
}
if (!editingCtx.getCommandManager().canRedo()) {
disable(redoBtn);
}
if (editingCtx.getPointsCount() < 1) {
disable(upDownBtn);
}
toolBarController = new MeasurementToolBarController(newGpxData);
if (editingCtx.getSelectedPointPosition() != -1) {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_mode_back, R.drawable.ic_action_mode_back);
} else {
toolBarController.setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
}
if (newGpxData != null) {
NewGpxData.ActionType actionType = newGpxData.getActionType();
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
toolBarController.setTitle(getString(R.string.add_route_points));
} else if (actionType == NewGpxData.ActionType.ADD_SEGMENT) {
toolBarController.setTitle(getString(R.string.add_line));
} else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
toolBarController.setTitle(getString(R.string.edit_line));
}
} else {
toolBarController.setTitle(getString(R.string.measurement_tool_action_bar));
}
toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quit(false);
}
});
toolBarController.setOnSaveViewClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (editingCtx.getPointsCount() > 0) {
addToGpx(mapActivity);
} else {
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
}
}
});
toolBarController.setOnSwitchCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
if (!checked) {
disableSnapToRoadMode();
}
}
});
mapActivity.showTopToolbar(toolBarController);
adapter = new MeasurementToolAdapter(getMapActivity(), editingCtx.getPoints(), newGpxData != null ? newGpxData.getActionType() : null);
if (portrait) {
pointsRv = mainView.findViewById(R.id.measure_points_recycler_view);
} else {
pointsRv = new RecyclerView(getActivity());
}
final ItemTouchHelper touchHelper = new ItemTouchHelper(new MeasurementToolItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(pointsRv);
adapter.setAdapterListener(createMeasurementAdapterListener(touchHelper));
pointsRv.setLayoutManager(new LinearLayoutManager(getContext()));
pointsRv.setAdapter(adapter);
enterMeasurementMode();
if (editingCtx.isInSnapToRoadMode()) {
showSnapToRoadControls();
}
if (newGpxData != null && !gpxPointsAdded) {
NewGpxData.ActionType actionType = newGpxData.getActionType();
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
displayRoutePoints();
gpxPointsAdded = true;
} else if (actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
displaySegmentPoints();
gpxPointsAdded = true;
}
}
if (saved == null) {
saved = newGpxData != null && (newGpxData.getActionType() == NewGpxData.ActionType.ADD_ROUTE_POINTS || newGpxData.getActionType() == NewGpxData.ActionType.EDIT_SEGMENT);
}
return view;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project Osmand by osmandapp.
the class MapMarkersHistoryFragment method onCreateView.
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final boolean night = !app.getSettings().isLightContent();
final MapActivity mapActivity = (MapActivity) getActivity();
backgroundPaint.setColor(ContextCompat.getColor(getActivity(), night ? R.color.dashboard_divider_dark : R.color.dashboard_divider_light));
backgroundPaint.setStyle(Paint.Style.FILL_AND_STROKE);
backgroundPaint.setAntiAlias(true);
iconPaint.setAntiAlias(true);
iconPaint.setFilterBitmap(true);
iconPaint.setDither(true);
textPaint.setTextSize(getResources().getDimension(R.dimen.default_desc_text_size));
textPaint.setFakeBoldText(true);
textPaint.setAntiAlias(true);
final String delStr = getString(R.string.shared_string_delete).toUpperCase();
final String activateStr = getString(R.string.local_index_mi_restore).toUpperCase();
Rect bounds = new Rect();
textPaint.getTextBounds(activateStr, 0, activateStr.length(), bounds);
final int activateStrWidth = bounds.width();
final int textHeight = bounds.height();
Fragment historyMarkerMenuFragment = mapActivity.getSupportFragmentManager().findFragmentByTag(HistoryMarkerMenuBottomSheetDialogFragment.TAG);
if (historyMarkerMenuFragment != null) {
((HistoryMarkerMenuBottomSheetDialogFragment) historyMarkerMenuFragment).setListener(createHistoryMarkerMenuListener());
}
final View mainView = inflater.inflate(R.layout.fragment_map_markers_history, container, false);
final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
private float marginSides = getResources().getDimension(R.dimen.list_content_padding);
private Bitmap deleteBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_delete_dark);
private Bitmap resetBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_action_reset_to_default_dark);
private boolean iconHidden;
@Override
public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof MapMarkerHeaderViewHolder) {
return 0;
}
return super.getSwipeDirs(recyclerView, viewHolder);
}
@Override
public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
return false;
}
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
if (actionState == ItemTouchHelper.ACTION_STATE_SWIPE && viewHolder instanceof MapMarkerItemViewHolder) {
if (!iconHidden && isCurrentlyActive) {
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.GONE);
iconHidden = true;
}
View itemView = viewHolder.itemView;
int colorIcon;
int colorText;
if (Math.abs(dX) > itemView.getWidth() / 2) {
colorIcon = R.color.map_widget_blue;
colorText = R.color.map_widget_blue;
} else {
colorIcon = night ? 0 : R.color.icon_color;
colorText = R.color.dashboard_subheader_text_light;
}
if (colorIcon != 0) {
iconPaint.setColorFilter(new PorterDuffColorFilter(ContextCompat.getColor(getActivity(), colorIcon), PorterDuff.Mode.SRC_IN));
}
textPaint.setColor(ContextCompat.getColor(getActivity(), colorText));
float textMarginTop = ((float) itemView.getHeight() - (float) textHeight) / 2;
if (dX > 0) {
c.drawRect(itemView.getLeft(), itemView.getTop(), dX, itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) deleteBitmap.getHeight()) / 2;
c.drawBitmap(deleteBitmap, itemView.getLeft() + marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(delStr, itemView.getLeft() + 2 * marginSides + deleteBitmap.getWidth(), itemView.getTop() + textMarginTop + textHeight, textPaint);
} else {
c.drawRect(itemView.getRight() + dX, itemView.getTop(), itemView.getRight(), itemView.getBottom(), backgroundPaint);
float iconMarginTop = ((float) itemView.getHeight() - (float) resetBitmap.getHeight()) / 2;
c.drawBitmap(resetBitmap, itemView.getRight() - resetBitmap.getWidth() - marginSides, itemView.getTop() + iconMarginTop, iconPaint);
c.drawText(activateStr, itemView.getRight() - resetBitmap.getWidth() - 2 * marginSides - activateStrWidth, itemView.getTop() + textMarginTop + textHeight, textPaint);
}
}
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
}
@Override
public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
if (viewHolder instanceof MapMarkerItemViewHolder) {
((MapMarkerItemViewHolder) viewHolder).optionsBtn.setVisibility(View.VISIBLE);
iconHidden = false;
}
super.clearView(recyclerView, viewHolder);
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, final int direction) {
final int pos = viewHolder.getAdapterPosition();
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
final MapMarker marker = (MapMarker) item;
int snackbarStringRes;
if (direction == ItemTouchHelper.LEFT) {
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
snackbarStringRes = R.string.marker_moved_to_active;
} else {
app.getMapMarkersHelper().removeMarker((MapMarker) item);
snackbarStringRes = R.string.item_removed;
}
snackbar = Snackbar.make(viewHolder.itemView, snackbarStringRes, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (direction == ItemTouchHelper.LEFT) {
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
} else {
app.getMapMarkersHelper().addMarker(marker);
}
}
});
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
snackbar.show();
}
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(recyclerView);
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
@Override
public void onItemClick(View view) {
int pos = recyclerView.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
HistoryMarkerMenuBottomSheetDialogFragment fragment = new HistoryMarkerMenuBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
Bundle arguments = new Bundle();
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_POSITION, pos);
arguments.putString(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_NAME, marker.getName(mapActivity));
arguments.putInt(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_COLOR_INDEX, marker.colorIndex);
arguments.putLong(HistoryMarkerMenuBottomSheetDialogFragment.MARKER_VISITED_DATE, marker.visitedDate);
fragment.setArguments(arguments);
fragment.setListener(createHistoryMarkerMenuListener());
fragment.show(mapActivity.getSupportFragmentManager(), HistoryMarkerMenuBottomSheetDialogFragment.TAG);
}
}
});
final View emptyView = mainView.findViewById(R.id.empty_view);
ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
if (Build.VERSION.SDK_INT >= 18) {
emptyImageView.setImageResource(night ? R.drawable.ic_empty_state_marker_history_night : R.drawable.ic_empty_state_marker_history_day);
} else {
emptyImageView.setVisibility(View.INVISIBLE);
}
recyclerView.setEmptyView(emptyView);
recyclerView.setAdapter(adapter);
app.getMapMarkersHelper().addListener(this);
return mainView;
}
use of android.support.v7.widget.helper.ItemTouchHelper in project Osmand by osmandapp.
the class QuickActionListFragment method setUpQuickActionRV.
private void setUpQuickActionRV() {
adapter = new QuickActionAdapter(new OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
touchHelper.startDrag(viewHolder);
}
});
quickActionRV.setAdapter(adapter);
quickActionRV.setLayoutManager(new LinearLayoutManager(getContext()));
ItemTouchHelper.Callback touchHelperCallback = new QuickActionItemTouchHelperCallback(adapter);
touchHelper = new ItemTouchHelper(touchHelperCallback);
touchHelper.attachToRecyclerView(quickActionRV);
adapter.addItems(quickActionRegistry.getFilteredQuickActions());
quickActionRV.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
if (dy > 0 && fab.getVisibility() == View.VISIBLE)
fab.hide();
else if (dy < 0 && fab.getVisibility() != View.VISIBLE)
fab.show();
}
});
}
Aggregations