Allow bulk select as intermediate points
This commit is contained in:
parent
7cd2c6f819
commit
8f87964750
5 changed files with 126 additions and 30 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="select_destination_and_intermediate_points">Select waypoints</string>
|
||||
<string name="layer_amenity_label">Text labels</string>
|
||||
<string name="loading_smth">Loading %1$s …</string>
|
||||
<string name="map_widget_plain_time">Current time</string>
|
||||
|
|
|
@ -28,6 +28,7 @@ import net.osmand.plus.GPXUtilities.WptPt;
|
|||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.util.MapUtils;
|
||||
import android.app.Activity;
|
||||
|
@ -37,6 +38,7 @@ import android.content.DialogInterface;
|
|||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.text.Spannable;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -71,12 +73,14 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
public static final int DELETE_ID = 2;
|
||||
public static final int DELETE_ACTION_ID = 3;
|
||||
public static final int SHARE_ID = 4;
|
||||
public static final int SELECT_DESTINATIONS_ID = 5;
|
||||
public static final int SELECT_DESTINATIONS_ACTION_MODE_ID = 6;
|
||||
|
||||
private FavouritesAdapter favouritesAdapter;
|
||||
private FavouritesDbHelper helper;
|
||||
|
||||
private boolean selectionMode = false;
|
||||
private Set<FavouritePoint> favoritesToDelete = new LinkedHashSet<FavouritePoint>();
|
||||
private Set<FavouritePoint> favoritesSelected = new LinkedHashSet<FavouritePoint>();
|
||||
private Set<String> groupsToDelete = new LinkedHashSet<String>();
|
||||
private Comparator<FavouritePoint> favoritesComparator;
|
||||
private ActionMode actionMode;
|
||||
|
@ -131,11 +135,11 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
for (FavouritePoint fp : favoritesToDelete) {
|
||||
for (FavouritePoint fp : favoritesSelected) {
|
||||
helper.deleteFavourite(fp);
|
||||
publishProgress(fp);
|
||||
}
|
||||
favoritesToDelete.clear();
|
||||
favoritesSelected.clear();
|
||||
for (String group : groupsToDelete) {
|
||||
helper.deleteGroup(group);
|
||||
publishProgress(group);
|
||||
|
@ -158,6 +162,14 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
favouritesAdapter.sort(favoritesComparator);
|
||||
|
||||
}
|
||||
|
||||
private void updateSelectionMode(ActionMode m) {
|
||||
if(favoritesSelected.size() > 0) {
|
||||
m.setTitle(favoritesSelected.size() + " " + getMyApplication().getString(R.string.selected));
|
||||
} else{
|
||||
m.setTitle("");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
|
||||
|
@ -166,10 +178,11 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
FavouritePoint model = favouritesAdapter.getChild(groupPosition, childPosition);
|
||||
ch.setChecked(!ch.isChecked());
|
||||
if (ch.isChecked()) {
|
||||
favoritesToDelete.add(model);
|
||||
favoritesSelected.add(model);
|
||||
} else {
|
||||
favoritesToDelete.remove(model);
|
||||
favoritesSelected.remove(model);
|
||||
}
|
||||
updateSelectionMode(actionMode);
|
||||
} else {
|
||||
final QuickAction qa = new QuickAction(v);
|
||||
final OsmandSettings settings = getMyApplication().getSettings();
|
||||
|
@ -276,6 +289,9 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
} else if (item.getItemId() == IMPORT_ID) {
|
||||
importFile();
|
||||
return true;
|
||||
} else if (item.getItemId() == SELECT_DESTINATIONS_ID) {
|
||||
selectDestinations();
|
||||
return true;
|
||||
} else if (item.getItemId() == SHARE_ID) {
|
||||
shareFavourites();
|
||||
return true;
|
||||
|
@ -290,6 +306,30 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private void selectDestinations() {
|
||||
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
if (targetPointsHelper.getIntermediatePoints().size() > 0) {
|
||||
final FragmentActivity act = getActivity();
|
||||
Builder builder = new AlertDialog.Builder(act);
|
||||
builder.setTitle(R.string.new_directions_point_dialog);
|
||||
builder.setItems(
|
||||
new String[] { act.getString(R.string.keep_intermediate_points),
|
||||
act.getString(R.string.clear_intermediate_points)},
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == 1) {
|
||||
targetPointsHelper.clearPointToNavigate(false);
|
||||
}
|
||||
enterIntermediatesMode();
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
} else {
|
||||
enterIntermediatesMode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.export_fav, R.drawable.ic_action_search_light,
|
||||
|
@ -325,15 +365,18 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
// }
|
||||
// });
|
||||
if (!mi.isActionViewExpanded()) {
|
||||
createMenuItem(menu, EXPORT_ID, R.string.export_fav, R.drawable.ic_action_gsave_light,
|
||||
R.drawable.ic_action_gsave_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
createMenuItem(menu, SHARE_ID, R.string.share_fav, R.drawable.ic_action_gshare_light,
|
||||
R.drawable.ic_action_gshare_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
createMenuItem(menu, SELECT_DESTINATIONS_ID, R.string.select_destination_and_intermediate_points, R.drawable.ic_action_flage_light,
|
||||
R.drawable.ic_action_flage_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
createMenuItem(menu, DELETE_ID, R.string.default_buttons_delete, R.drawable.ic_action_delete_light,
|
||||
R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
createMenuItem(menu, EXPORT_ID, R.string.export_fav, R.drawable.ic_action_gsave_light,
|
||||
R.drawable.ic_action_gsave_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
createMenuItem(menu, IMPORT_ID, R.string.import_fav, R.drawable.ic_action_grefresh_light,
|
||||
R.drawable.ic_action_grefresh_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM
|
||||
| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
|
||||
createMenuItem(menu, DELETE_ID, R.string.default_buttons_delete, R.drawable.ic_action_delete_light,
|
||||
R.drawable.ic_action_delete_dark, MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -344,6 +387,59 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
public void hideProgressBar() {
|
||||
getSherlockActivity().setSupportProgressBarIndeterminateVisibility(false);
|
||||
}
|
||||
|
||||
private void enterIntermediatesMode() {
|
||||
actionMode = getSherlockActivity().startActionMode(new Callback() {
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
||||
selectionMode = true;
|
||||
createMenuItem(menu, SELECT_DESTINATIONS_ACTION_MODE_ID, R.string.select_destination_and_intermediate_points,
|
||||
R.drawable.ic_action_flage_light, R.drawable.ic_action_flage_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
updateSelectionMode(actionMode);
|
||||
favoritesSelected.clear();
|
||||
groupsToDelete.clear();
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode mode) {
|
||||
selectionMode = false;
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
||||
if (item.getItemId() == SELECT_DESTINATIONS_ACTION_MODE_ID) {
|
||||
selectDestinationImpl();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void selectDestinationImpl() {
|
||||
if(!favoritesSelected.isEmpty()) {
|
||||
final TargetPointsHelper targetPointsHelper = getMyApplication().getTargetPointsHelper();
|
||||
for(FavouritePoint fp : favoritesSelected) {
|
||||
targetPointsHelper.navigateToPoint(new LatLon(fp.getLatitude(), fp.getLongitude()), false,
|
||||
targetPointsHelper.getIntermediatePoints().size() + 1,
|
||||
getString(R.string.favorite) + ": " + fp.getName());
|
||||
}
|
||||
targetPointsHelper.updateRoutingHelper();
|
||||
IntermediatePointsDialog.openIntermediatePointsDialog(getActivity(), getMyApplication(), false);
|
||||
//MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
}
|
||||
|
||||
private void enterDeleteMode() {
|
||||
actionMode = getSherlockActivity().startActionMode(new Callback() {
|
||||
|
@ -354,9 +450,10 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
createMenuItem(menu, DELETE_ACTION_ID, R.string.default_buttons_delete,
|
||||
R.drawable.ic_action_delete_light, R.drawable.ic_action_delete_dark,
|
||||
MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||
favoritesToDelete.clear();
|
||||
favoritesSelected.clear();
|
||||
groupsToDelete.clear();
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
updateSelectionMode(mode);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -384,10 +481,10 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
|
||||
private void deleteFavoritesAction() {
|
||||
if (groupsToDelete.size() + favoritesToDelete.size() > 0) {
|
||||
if (groupsToDelete.size() + favoritesSelected.size() > 0) {
|
||||
|
||||
Builder b = new AlertDialog.Builder(getActivity());
|
||||
b.setMessage(getString(R.string.favorite_delete_multiple, favoritesToDelete.size(), groupsToDelete.size()));
|
||||
b.setMessage(getString(R.string.favorite_delete_multiple, favoritesSelected.size(), groupsToDelete.size()));
|
||||
b.setPositiveButton(R.string.default_buttons_delete, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
@ -671,7 +768,7 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
groupsToDelete.add(model);
|
||||
List<FavouritePoint> fvs = helper.getFavoriteGroups().get(model);
|
||||
if (fvs != null) {
|
||||
favoritesToDelete.addAll(fvs);
|
||||
favoritesSelected.addAll(fvs);
|
||||
}
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
} else {
|
||||
|
@ -710,16 +807,16 @@ public class FavouritesTreeFragment extends OsmandExpandableListFragment {
|
|||
final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item);
|
||||
if (selectionMode) {
|
||||
ch.setVisibility(View.VISIBLE);
|
||||
ch.setChecked(favoritesToDelete.contains(model));
|
||||
ch.setChecked(favoritesSelected.contains(model));
|
||||
row.findViewById(R.id.favourite_icon).setVisibility(View.GONE);
|
||||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (ch.isChecked()) {
|
||||
favoritesToDelete.add(model);
|
||||
favoritesSelected.add(model);
|
||||
} else {
|
||||
favoritesToDelete.remove(model);
|
||||
favoritesSelected.remove(model);
|
||||
if (groupsToDelete.contains(model.getCategory())) {
|
||||
groupsToDelete.remove(model.getCategory());
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
|
|
|
@ -43,7 +43,7 @@ public class IntermediatePointsDialog {
|
|||
openIntermediatePointsDialog(mapActivity, (OsmandApplication) mapActivity.getApplication(), false);
|
||||
}
|
||||
|
||||
public static void openIntermediatePointsDialog(final MapActivity activity,
|
||||
public static void openIntermediatePointsDialog(final Activity activity,
|
||||
final OsmandApplication app, final boolean changeOrder){
|
||||
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||
final List<LatLon> intermediates = targets.getIntermediatePointsWithTarget();
|
||||
|
@ -127,7 +127,7 @@ public class IntermediatePointsDialog {
|
|||
dlg.show();
|
||||
}
|
||||
|
||||
private static void applySortTargets(AlertDialog dlg, final MapActivity activity, final List<LatLon> intermediates,
|
||||
private static void applySortTargets(AlertDialog dlg, final Activity activity, final List<LatLon> intermediates,
|
||||
final TIntArrayList originalPositions,
|
||||
final List<String> names, final ArrayAdapter<LatLon> listadapter, final ProgressBar pb, final TextView textInfo) {
|
||||
dlg.setOnShowListener(new OnShowListener() {
|
||||
|
@ -146,7 +146,12 @@ public class IntermediatePointsDialog {
|
|||
|
||||
protected int[] doInBackground(Void[] params) {
|
||||
ArrayList<LatLon> lt = new ArrayList<LatLon>(intermediates);
|
||||
LatLon start = new LatLon(activity.getMapView().getLatitude(), activity.getMapView().getLongitude());
|
||||
LatLon start ;
|
||||
if(activity instanceof MapActivity) {
|
||||
start = new LatLon(((MapActivity) activity).getMapView().getLatitude(), ((MapActivity) activity).getMapView().getLongitude());
|
||||
} else {
|
||||
start = lt.get(0);
|
||||
}
|
||||
LatLon end = lt.remove(lt.size() - 1);
|
||||
return new TspAnt().readGraph(lt, start, end).solve();
|
||||
};
|
||||
|
|
|
@ -119,9 +119,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.I
|
|||
|
||||
@Override
|
||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if(tileBox.getZoom() < 11) {
|
||||
return false;
|
||||
}
|
||||
List<FavouritePoint> favs = new ArrayList<FavouritePoint>();
|
||||
getFavoriteFromPoint(tileBox, point, favs);
|
||||
if(!favs.isEmpty() && (tileBox.getZoom() > 14 || favs.size() < 6)){
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.QuadRect;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
|
@ -201,15 +200,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
|
||||
@Override
|
||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||
if(tileBox.getZoom() < 11) {
|
||||
return false;
|
||||
}
|
||||
List<WptPt> favs = new ArrayList<WptPt>();
|
||||
getWptFromPoint(tileBox, point, favs);
|
||||
if(!favs.isEmpty() && (tileBox.getZoom() > 14 || favs.size() < 6)){
|
||||
List<WptPt> gpxPoints = new ArrayList<WptPt>();
|
||||
getWptFromPoint(tileBox, point, gpxPoints);
|
||||
if(!gpxPoints.isEmpty() && (tileBox.getZoom() > 14 || gpxPoints.size() < 6)){
|
||||
StringBuilder res = new StringBuilder();
|
||||
int i = 0;
|
||||
for(WptPt fav : favs) {
|
||||
for(WptPt fav : gpxPoints) {
|
||||
if (i++ > 0) {
|
||||
res.append("\n\n");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue