Add undo for swipe in history
This commit is contained in:
parent
56ebb8b33c
commit
e21014a9dc
3 changed files with 38 additions and 3 deletions
|
@ -301,6 +301,20 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addMarker(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
markersDbHelper.addMarker(marker);
|
||||
if (marker.history) {
|
||||
mapMarkersHistory.add(marker);
|
||||
sortMarkers(mapMarkersHistory, true);
|
||||
} else {
|
||||
mapMarkers.add(marker);
|
||||
checkAndFixActiveMarkersOrderIfNeeded();
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreMarkerFromHistory(MapMarker marker, int position) {
|
||||
if (marker != null) {
|
||||
markersDbHelper.restoreMapMarkerFromHistory(marker);
|
||||
|
|
|
@ -106,6 +106,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
activeFragment.startLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 0) {
|
||||
activeFragment.updateAdapter();
|
||||
historyFragment.hideSnackbar();
|
||||
}
|
||||
viewPager.setCurrentItem(0);
|
||||
optionsButton.setVisibility(View.VISIBLE);
|
||||
|
|
|
@ -9,12 +9,12 @@ import android.graphics.PorterDuffColorFilter;
|
|||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
@ -35,6 +35,7 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
|||
private Paint backgroundPaint = new Paint();
|
||||
private Paint iconPaint = new Paint();
|
||||
private Paint textPaint = new Paint();
|
||||
private Snackbar snackbar;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
|
@ -140,16 +141,29 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
||||
int pos = viewHolder.getAdapterPosition();
|
||||
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;
|
||||
if (direction == ItemTouchHelper.LEFT) {
|
||||
app.getMapMarkersHelper().restoreMarkerFromHistory((MapMarker) item, 0);
|
||||
} else {
|
||||
app.getMapMarkersHelper().removeMarkerFromHistory((MapMarker) item);
|
||||
}
|
||||
adapter.notifyItemRemoved(pos);
|
||||
snackbar = Snackbar.make(viewHolder.itemView, R.string.item_removed, 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);
|
||||
}
|
||||
}
|
||||
});
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -183,6 +197,12 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
|
|||
return recyclerView;
|
||||
}
|
||||
|
||||
void hideSnackbar() {
|
||||
if (snackbar != null && snackbar.isShown()) {
|
||||
snackbar.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() {
|
||||
return new HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue