Fixes bug: unable to share favourites.
This commit is contained in:
parent
e3f5765c3e
commit
3b5e02b109
1 changed files with 32 additions and 39 deletions
|
@ -1,6 +1,5 @@
|
||||||
package net.osmand.plus.activities;
|
package net.osmand.plus.activities;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -8,10 +7,10 @@ import android.content.res.Resources;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
|
import android.support.v4.content.FileProvider;
|
||||||
import android.support.v4.view.MenuItemCompat;
|
import android.support.v4.view.MenuItemCompat;
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.view.ActionMode;
|
import android.support.v7.view.ActionMode;
|
||||||
|
@ -58,6 +57,7 @@ import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
@ -85,14 +85,14 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
private FavouritesDbHelper helper;
|
private FavouritesDbHelper helper;
|
||||||
|
|
||||||
private boolean selectionMode = false;
|
private boolean selectionMode = false;
|
||||||
private Set<FavouritePoint> favoritesSelected = new LinkedHashSet<FavouritePoint>();
|
private Set<FavouritePoint> favoritesSelected = new LinkedHashSet<>();
|
||||||
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<FavoriteGroup>();
|
private Set<FavoriteGroup> groupsToDelete = new LinkedHashSet<>();
|
||||||
private ActionMode actionMode;
|
private ActionMode actionMode;
|
||||||
private SearchView searchView;
|
private SearchView searchView;
|
||||||
Drawable arrowImage;
|
Drawable arrowImage;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Context activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
|
|
||||||
helper = getMyApplication().getFavorites();
|
helper = getMyApplication().getFavorites();
|
||||||
|
@ -207,7 +207,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
for (int i = 0; i < list.length; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
list[i] = gs.get(i).name;
|
list[i] = gs.get(i).name;
|
||||||
}
|
}
|
||||||
cat.setAdapter(new ArrayAdapter<String>(ctx, R.layout.list_textview, list));
|
cat.setAdapter(new ArrayAdapter<>(ctx, R.layout.list_textview, list));
|
||||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||||
builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -216,7 +216,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
point.setName(newName);
|
point.setName(newName);
|
||||||
point.setCategory(cat.getText().toString());
|
point.setCategory(cat.getText().toString());
|
||||||
point.setDescription(editDescr.getText().toString());
|
point.setDescription(editDescr.getText().toString());
|
||||||
AlertDialog.Builder builder1 = helper.checkDuplicates(point, helper, ctx);
|
AlertDialog.Builder builder1 = FavouritesDbHelper.checkDuplicates(point, helper, ctx);
|
||||||
|
|
||||||
if (builder1 != null) {
|
if (builder1 != null) {
|
||||||
builder1.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
builder1.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||||
|
@ -568,14 +568,24 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(GPXFile gpxFile) {
|
protected void onPostExecute(GPXFile gpxFile) {
|
||||||
hideProgressBar();
|
hideProgressBar();
|
||||||
final Intent sendIntent = new Intent();
|
File dir = new File(getActivity().getCacheDir(), "share");
|
||||||
sendIntent.setAction(Intent.ACTION_SEND);
|
if (!dir.exists()) {
|
||||||
sendIntent.putExtra(Intent.EXTRA_TEXT, "Favourites.gpx:\n\n\n" + GPXUtilities.asString(gpxFile, getMyApplication()));
|
dir.mkdir();
|
||||||
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
|
}
|
||||||
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(helper.getExternalFile()));
|
File src = helper.getExternalFile();
|
||||||
// sendIntent.setType("application/gpx+xml");
|
File dst = new File(dir, src.getName());
|
||||||
sendIntent.setType("text/plain");
|
try {
|
||||||
startActivity(sendIntent);
|
Algorithms.fileCopy(src, dst);
|
||||||
|
final Intent sendIntent = new Intent();
|
||||||
|
sendIntent.setAction(Intent.ACTION_SEND);
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_TEXT, "Favourites.gpx:\n\n\n" + GPXUtilities.asString(gpxFile, getMyApplication()));
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
|
||||||
|
sendIntent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getActivity(), "net.osmand.fileprovider", dst));
|
||||||
|
sendIntent.setType("text/plain");
|
||||||
|
startActivity(sendIntent);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -635,24 +645,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
class FavouritesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
|
class FavouritesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
|
||||||
|
|
||||||
private static final boolean showOptionsButton = false;
|
private static final boolean showOptionsButton = false;
|
||||||
Map<FavoriteGroup, List<FavouritePoint>> favoriteGroups = new LinkedHashMap<FavoriteGroup, List<FavouritePoint>>();
|
Map<FavoriteGroup, List<FavouritePoint>> favoriteGroups = new LinkedHashMap<>();
|
||||||
List<FavoriteGroup> groups = new ArrayList<FavoriteGroup>();
|
List<FavoriteGroup> groups = new ArrayList<FavoriteGroup>();
|
||||||
Filter myFilter;
|
Filter myFilter;
|
||||||
private Set<?> filter;
|
private Set<?> filter;
|
||||||
|
|
||||||
public void deleteFavoritePoint(FavouritePoint p) {
|
|
||||||
if (favoriteGroups.containsKey(p.getCategory())) {
|
|
||||||
favoriteGroups.get(p.getCategory()).remove(p);
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteCategory(String p) {
|
|
||||||
favoriteGroups.remove(p);
|
|
||||||
groups.remove(p);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void synchronizeGroups() {
|
public void synchronizeGroups() {
|
||||||
favoriteGroups.clear();
|
favoriteGroups.clear();
|
||||||
groups.clear();
|
groups.clear();
|
||||||
|
@ -662,9 +659,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
boolean empty = true;
|
boolean empty = true;
|
||||||
if (flt == null || flt.contains(key)) {
|
if (flt == null || flt.contains(key)) {
|
||||||
empty = false;
|
empty = false;
|
||||||
favoriteGroups.put(key, new ArrayList<FavouritePoint>(key.points));
|
favoriteGroups.put(key, new ArrayList<>(key.points));
|
||||||
} else {
|
} else {
|
||||||
ArrayList<FavouritePoint> list = new ArrayList<FavouritePoint>();
|
ArrayList<FavouritePoint> list = new ArrayList<>();
|
||||||
for (FavouritePoint p : key.points) {
|
for (FavouritePoint p : key.points) {
|
||||||
if (flt.contains(p)) {
|
if (flt.contains(p)) {
|
||||||
list.add(p);
|
list.add(p);
|
||||||
|
@ -791,7 +788,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
TextView distanceText = (TextView) row.findViewById(R.id.distance);
|
TextView distanceText = (TextView) row.findViewById(R.id.distance);
|
||||||
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
|
ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon);
|
||||||
|
|
||||||
final FavouritePoint model = (FavouritePoint) getChild(groupPosition, childPosition);
|
final FavouritePoint model = getChild(groupPosition, childPosition);
|
||||||
row.setTag(model);
|
row.setTag(model);
|
||||||
|
|
||||||
if (showOptionsButton) {
|
if (showOptionsButton) {
|
||||||
|
@ -835,10 +832,6 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
favoritesSelected.add(model);
|
favoritesSelected.add(model);
|
||||||
} else {
|
} else {
|
||||||
favoritesSelected.remove(model);
|
favoritesSelected.remove(model);
|
||||||
if (groupsToDelete.contains(model.getCategory())) {
|
|
||||||
groupsToDelete.remove(model.getCategory());
|
|
||||||
favouritesAdapter.notifyDataSetInvalidated();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateSelectionMode(actionMode);
|
updateSelectionMode(actionMode);
|
||||||
}
|
}
|
||||||
|
@ -876,14 +869,14 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
results.values = null;
|
results.values = null;
|
||||||
results.count = 1;
|
results.count = 1;
|
||||||
} else {
|
} else {
|
||||||
Set<Object> filter = new HashSet<Object>();
|
Set<Object> filter = new HashSet<>();
|
||||||
String cs = constraint.toString().toLowerCase();
|
String cs = constraint.toString().toLowerCase();
|
||||||
for (FavoriteGroup g : helper.getFavoriteGroups()) {
|
for (FavoriteGroup g : helper.getFavoriteGroups()) {
|
||||||
if (g.name.toLowerCase().indexOf(cs) != -1) {
|
if (g.name.toLowerCase().contains(cs)) {
|
||||||
filter.add(g);
|
filter.add(g);
|
||||||
} else {
|
} else {
|
||||||
for (FavouritePoint fp : g.points) {
|
for (FavouritePoint fp : g.points) {
|
||||||
if (fp.getName().toLowerCase().indexOf(cs) != -1) {
|
if (fp.getName().toLowerCase().contains(cs)) {
|
||||||
filter.add(fp);
|
filter.add(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue