Show snackbar when toggle switch in groups
This commit is contained in:
parent
91170823ae
commit
fdd2c80244
4 changed files with 39 additions and 4 deletions
|
@ -9,6 +9,7 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="group_will_be_removed_after_restart">Group will be removed after restart</string>
|
||||
<string name="show_guide_line">Show guide line</string>
|
||||
<string name="show_arrows_on_the_map">Show arrows on the map</string>
|
||||
<string name="show_passed">Show passed</string>
|
||||
|
|
|
@ -139,6 +139,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
if (viewPager.getCurrentItem() != 0) {
|
||||
activeFragment.updateAdapter();
|
||||
historyFragment.hideSnackbar();
|
||||
groupsFragment.hideSnackbar();
|
||||
}
|
||||
orderByModeTitle.setVisibility(View.VISIBLE);
|
||||
viewPager.setCurrentItem(0);
|
||||
|
@ -159,6 +160,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
|
|||
activeFragment.stopLocationUpdate();
|
||||
if (viewPager.getCurrentItem() != 2) {
|
||||
historyFragment.updateAdapter();
|
||||
groupsFragment.hideSnackbar();
|
||||
activeFragment.hideSnackbar();
|
||||
}
|
||||
orderByModeTitle.setVisibility(View.GONE);
|
||||
|
|
|
@ -83,6 +83,12 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
|
|||
}
|
||||
}
|
||||
|
||||
void hideSnackbar() {
|
||||
if (adapter != null) {
|
||||
adapter.hideSnackbar();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLocation(Location location) {
|
||||
boolean newLocation = this.location == null && location != null;
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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.view.LayoutInflater;
|
||||
|
@ -7,6 +8,7 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.IconsCache;
|
||||
|
@ -49,6 +51,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
private boolean useCenter;
|
||||
private boolean showDirectionEnabled;
|
||||
private List<MapMarker> showDirectionMarkers;
|
||||
private Snackbar snackbar;
|
||||
|
||||
public MapMarkersGroupsAdapter(MapActivity mapActivity) {
|
||||
this.mapActivity = mapActivity;
|
||||
|
@ -308,13 +311,30 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
|
||||
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||
groupHeader.getGroup().setDisabled(!b);
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||
groupHeader.getGroup().setDisabled(!enabled);
|
||||
MapMarkersHelper.MarkersSyncGroup syncGroup = app.getMapMarkersHelper().getGroup(groupHeader.getGroup().getGroupKey());
|
||||
if (syncGroup != null) {
|
||||
app.getMapMarkersHelper().updateSyncGroupDisabled(syncGroup.getId(), !b);
|
||||
app.getMapMarkersHelper().updateSyncGroupDisabled(syncGroup.getId(), !enabled);
|
||||
}
|
||||
if (!enabled) {
|
||||
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
groupHeader.getGroup().setDisabled(false);
|
||||
MapMarkersHelper.MarkersSyncGroup syncGroup = app.getMapMarkersHelper().getGroup(groupHeader.getGroup().getGroupKey());
|
||||
if (syncGroup != null) {
|
||||
app.getMapMarkersHelper().updateSyncGroupDisabled(syncGroup.getId(), false);
|
||||
}
|
||||
headerViewHolder.disableGroupSwitch.setChecked(true);
|
||||
}
|
||||
});
|
||||
View snackBarView = snackbar.getView();
|
||||
TextView tv = (TextView) snackBarView.findViewById(android.support.design.R.id.snackbar_action);
|
||||
tv.setTextColor(ContextCompat.getColor(mapActivity, R.color.color_dialog_buttons_dark));
|
||||
snackbar.show();
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
@ -344,6 +364,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
}
|
||||
}
|
||||
|
||||
public void hideSnackbar() {
|
||||
if (snackbar != null && snackbar.isShown()) {
|
||||
snackbar.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Object item = items.get(position);
|
||||
|
|
Loading…
Reference in a new issue