Show snackbar when activate marker from history

This commit is contained in:
PavelRatushny 2017-09-22 15:29:35 +03:00
parent 546c6c18a8
commit ae2ef2a107
2 changed files with 27 additions and 0 deletions

View file

@ -212,6 +212,9 @@ public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHel
if (snackbar != null && snackbar.isShown()) { if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss(); snackbar.dismiss();
} }
if (adapter != null) {
adapter.hideSnackbar();
}
} }
private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() { private HistoryMarkerMenuBottomSheetDialogFragment.HistoryMarkerMenuFragmentListener createHistoryMarkerMenuListener() {

View file

@ -1,11 +1,15 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -30,6 +34,7 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
private OsmandApplication app; private OsmandApplication app;
private List<Object> items = new ArrayList<>(); private List<Object> items = new ArrayList<>();
private MapMarkersHistoryAdapterListener listener; private MapMarkersHistoryAdapterListener listener;
private Snackbar snackbar;
public MapMarkersHistoryAdapter(OsmandApplication app) { public MapMarkersHistoryAdapter(OsmandApplication app) {
this.app = app; this.app = app;
@ -130,6 +135,19 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
} }
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0); app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
notifyItemRemoved(position); notifyItemRemoved(position);
snackbar = Snackbar.make(itemViewHolder.itemView, app.getString(R.string.marker_moved_to_active), Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
notifyDataSetChanged();
}
});
View snackBarView = snackbar.getView();
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
tv.setTextColor(ContextCompat.getColor(app, R.color.color_dialog_buttons_dark));
snackbar.show();
} }
}); });
itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE); itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
@ -165,6 +183,12 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<RecyclerView.
} }
} }
public void hideSnackbar() {
if (snackbar != null && snackbar.isShown()) {
snackbar.dismiss();
}
}
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
Object item = items.get(position); Object item = items.get(position);