Added new menu for favorite group
This commit is contained in:
parent
f7611dbb67
commit
e5a34159f5
3 changed files with 155 additions and 112 deletions
|
@ -141,11 +141,13 @@
|
|||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/show_on_map_switch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content"
|
||||
android:clickable="false"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/dashboard_divider"/>
|
||||
|
|
|
@ -5,9 +5,11 @@ import android.content.Context;
|
|||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.ListPopupWindow;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -21,15 +23,22 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.IconsCache;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "EditFavoriteGroupDialogFragment";
|
||||
|
@ -72,7 +81,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
final View view = inflater.inflate(R.layout.fragment_data_storage_place_dialog, container,
|
||||
final View view = inflater.inflate(R.layout.edit_fav_fragment, container,
|
||||
false);
|
||||
if (group == null) {
|
||||
return view;
|
||||
|
@ -80,9 +89,11 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
|
||||
IconsCache ic = app.getIconsCache();
|
||||
|
||||
final TextView title = (TextView) view.findViewById(R.id.title);
|
||||
title.setText(Algorithms.isEmpty(group.name) ? app.getString(R.string.shared_string_favorites) : group.name);
|
||||
View editNameView = view.findViewById(R.id.edit_name_view);
|
||||
((ImageView) view.findViewById(R.id.edit_name_icon))
|
||||
.setImageDrawable(ic.getIcon(R.drawable.ic_action_edit_dark));
|
||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_edit_dark));
|
||||
editNameView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
@ -94,7 +105,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
int topPadding = AndroidUtils.dpToPx(activity, 4f);
|
||||
b.setView(nameEditText, leftPadding, topPadding, leftPadding, topPadding);
|
||||
b.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
b.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
b.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String name = nameEditText.getText().toString();
|
||||
|
@ -102,7 +113,9 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
if (nameChanged) {
|
||||
getMyApplication().getFavorites()
|
||||
.editFavouriteGroup(group, name, group.color, group.visible);
|
||||
updateParentFragment();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
b.show();
|
||||
|
@ -111,7 +124,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
|
||||
final View changeColorView = view.findViewById(R.id.change_color_view);
|
||||
((ImageView) view.findViewById(R.id.change_color_icon))
|
||||
.setImageDrawable(ic.getIcon(R.drawable.ic_action_appearance));
|
||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_appearance));
|
||||
updateColorView(changeColorView);
|
||||
changeColorView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -134,10 +147,11 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
if (color != group.color) {
|
||||
getMyApplication().getFavorites()
|
||||
.editFavouriteGroup(group, group.name, color, group.visible);
|
||||
updateParentFragment();
|
||||
}
|
||||
}
|
||||
popup.dismiss();
|
||||
updateColorView(changeColorView);
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
popup.show();
|
||||
|
@ -146,33 +160,64 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
|
||||
View showOnMapView = view.findViewById(R.id.show_on_map_view);
|
||||
((ImageView) view.findViewById(R.id.show_on_map_icon))
|
||||
.setImageDrawable(ic.getIcon(R.drawable.ic_map));
|
||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_map));
|
||||
final SwitchCompat checkbox = (SwitchCompat) view.findViewById(R.id.show_on_map_switch);
|
||||
checkbox.setChecked(group.visible);
|
||||
showOnMapView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//todo
|
||||
boolean visible = !group.visible;
|
||||
checkbox.setChecked(visible);
|
||||
getMyApplication().getFavorites()
|
||||
.editFavouriteGroup(group, group.name, group.color, visible);
|
||||
updateParentFragment();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
|
||||
View addToMarkersView = view.findViewById(R.id.add_to_markers_view);
|
||||
((ImageView) view.findViewById(R.id.add_to_markers_icon))
|
||||
.setImageDrawable(ic.getIcon(R.drawable.ic_action_flag_dark));
|
||||
addToMarkersView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//todo
|
||||
}
|
||||
});
|
||||
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0) {
|
||||
((ImageView) view.findViewById(R.id.add_to_markers_icon))
|
||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_flag_dark));
|
||||
addToMarkersView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
|
||||
List<LatLon> points = new ArrayList<>(group.points.size());
|
||||
List<PointDescription> names = new ArrayList<>(group.points.size());
|
||||
for (FavouritePoint fp : group.points) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
|
||||
}
|
||||
markersHelper.addMapMarkers(points, names);
|
||||
dismiss();
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
addToMarkersView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
View shareView = view.findViewById(R.id.share_view);
|
||||
((ImageView) view.findViewById(R.id.share_icon))
|
||||
.setImageDrawable(ic.getIcon(R.drawable.ic_action_gshare_dark));
|
||||
shareView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
//todo
|
||||
}
|
||||
});
|
||||
if (group.points.size() > 0) {
|
||||
((ImageView) view.findViewById(R.id.share_icon))
|
||||
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_gshare_dark));
|
||||
shareView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
|
||||
if (fragment != null) {
|
||||
fragment.shareFavorites(group);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
shareView.setVisibility(View.GONE);
|
||||
}
|
||||
if (group.points.size() == 0) {
|
||||
view.findViewById(R.id.divider).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -185,6 +230,21 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private FavoritesTreeFragment getFavoritesTreeFragment() {
|
||||
Fragment fragment = getParentFragment();
|
||||
if (fragment instanceof FavoritesTreeFragment) {
|
||||
return (FavoritesTreeFragment) fragment;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void updateParentFragment() {
|
||||
FavoritesTreeFragment fragment = getFavoritesTreeFragment();
|
||||
if (fragment != null) {
|
||||
fragment.reloadData();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateColorView(View colorView) {
|
||||
ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage);
|
||||
int color = group.color == 0 ? getResources().getColor(R.color.color_favorite) : group.color;
|
||||
|
|
|
@ -24,12 +24,10 @@ import android.view.MenuItem;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ExpandableListView;
|
||||
import android.widget.Filter;
|
||||
import android.widget.Filterable;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
@ -38,7 +36,6 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -48,7 +45,6 @@ import net.osmand.plus.TargetPointsHelper;
|
|||
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -66,8 +62,6 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import gnu.trove.list.array.TIntArrayList;
|
||||
|
||||
|
||||
public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||
|
||||
|
@ -187,6 +181,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
initListExpandedState();
|
||||
}
|
||||
|
||||
public void reloadData() {
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
private void updateSelectionMode(ActionMode m) {
|
||||
if (favoritesSelected.size() > 0) {
|
||||
m.setTitle(favoritesSelected.size() + " " + getMyApplication().getString(R.string.shared_string_selected_lowercase));
|
||||
|
@ -440,45 +439,6 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
((FavoritesActivity) getActivity()).updateListViewFooter(footerView);
|
||||
}
|
||||
|
||||
protected void openChangeGroupDialog(final FavoriteGroup group) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
View view = getActivity().getLayoutInflater().inflate(R.layout.fav_group_edit, null);
|
||||
|
||||
final EditText nameEditText = (EditText) view.findViewById(R.id.nameEditText);
|
||||
nameEditText.setText(group.name);
|
||||
|
||||
final CheckBox checkBox = (CheckBox) view.findViewById(R.id.Visibility);
|
||||
checkBox.setChecked(group.visible);
|
||||
|
||||
final Spinner colorSpinner = (Spinner) view.findViewById(R.id.ColorSpinner);
|
||||
final TIntArrayList list = new TIntArrayList();
|
||||
final int intColor = group.color == 0 ? getResources().getColor(R.color.color_favorite) : group.color;
|
||||
ColorDialogs.setupColorSpinner(getActivity(), intColor, colorSpinner, list);
|
||||
|
||||
builder.setTitle(R.string.edit_group);
|
||||
builder.setView(view);
|
||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
int clr = list.get(colorSpinner.getSelectedItemPosition());
|
||||
String name = nameEditText.getText().toString();
|
||||
boolean nameChanged = !Algorithms.objectEquals(group.name, name);
|
||||
if (clr != intColor || group.visible != checkBox.isChecked() || nameChanged) {
|
||||
getMyApplication().getFavorites().editFavouriteGroup(group, name, clr,
|
||||
checkBox.isChecked());
|
||||
if (nameChanged) {
|
||||
favouritesAdapter.synchronizeGroups();
|
||||
}
|
||||
favouritesAdapter.notifyDataSetInvalidated();
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void deleteFavoritesAction() {
|
||||
if (groupsToDelete.size() + favoritesSelected.size() > 0) {
|
||||
|
||||
|
@ -498,11 +458,10 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private StringBuilder generateHtmlPrint() {
|
||||
private StringBuilder generateHtmlPrint(List<FavoriteGroup> groups) {
|
||||
StringBuilder html = new StringBuilder();
|
||||
html.append("<h1>My Favorites</h1>");
|
||||
List<FavoriteGroup> groups = getMyApplication().getFavorites().getFavoriteGroups();
|
||||
for(FavoriteGroup group : groups) {
|
||||
for (FavoriteGroup group : groups) {
|
||||
html.append("<h3>"+group.name+"</h3>");
|
||||
for(FavouritePoint fp : group.points) {
|
||||
String url = "geo:"+((float)fp.getLatitude())+","+((float)fp.getLongitude())+"?m="+fp.getName();
|
||||
|
@ -523,48 +482,70 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
if (favouritesAdapter.isEmpty()) {
|
||||
Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show();
|
||||
} else {
|
||||
final AsyncTask<Void, Void, GPXFile> exportTask = new AsyncTask<Void, Void, GPXFile>() {
|
||||
@Override
|
||||
protected GPXFile doInBackground(Void... params) {
|
||||
return helper.asGpxFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
showProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile gpxFile) {
|
||||
hideProgressBar();
|
||||
File dir = new File(getActivity().getCacheDir(), "share");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
File src = helper.getExternalFile();
|
||||
File dst = new File(dir, src.getName());
|
||||
try {
|
||||
Algorithms.fileCopy(src, dst);
|
||||
final Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint().toString()));
|
||||
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM,
|
||||
FileProvider.getUriForFile(getActivity(),
|
||||
getActivity().getPackageName() + ".fileprovider", dst));
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
} catch (IOException e) {
|
||||
//Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exportTask.execute();
|
||||
shareFavorites(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void shareFavorites(final FavoriteGroup group) {
|
||||
final AsyncTask<Void, Void, Void> exportTask = new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
File src = null;
|
||||
File dst = null;
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
if (group != null) {
|
||||
helper.saveFile(group.points, dst);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
showProgressBar();
|
||||
File dir = new File(getActivity().getCacheDir(), "share");
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
if (group == null) {
|
||||
src = helper.getExternalFile();
|
||||
}
|
||||
dst = new File(dir, src != null ? src.getName() : FavouritesDbHelper.FILE_TO_SAVE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void res) {
|
||||
hideProgressBar();
|
||||
try {
|
||||
if (src != null && dst != null) {
|
||||
Algorithms.fileCopy(src, dst);
|
||||
}
|
||||
final Intent sendIntent = new Intent();
|
||||
sendIntent.setAction(Intent.ACTION_SEND);
|
||||
List<FavoriteGroup> groups;
|
||||
if (group != null) {
|
||||
groups = new ArrayList<>();
|
||||
groups.add(group);
|
||||
} else {
|
||||
groups = getMyApplication().getFavorites().getFavoriteGroups();
|
||||
}
|
||||
sendIntent.putExtra(Intent.EXTRA_TEXT, Html.fromHtml(generateHtmlPrint(groups).toString()));
|
||||
sendIntent.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.share_fav_subject));
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM,
|
||||
FileProvider.getUriForFile(getActivity(),
|
||||
getActivity().getPackageName() + ".fileprovider", dst));
|
||||
sendIntent.setType("text/plain");
|
||||
startActivity(sendIntent);
|
||||
} catch (IOException e) {
|
||||
//Toast.makeText(getActivity(), "Error sharing favorites: " + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
exportTask.execute();
|
||||
}
|
||||
|
||||
protected void export() {
|
||||
final File tosave = getMyApplication().getAppPath(FavouritesDbHelper.FILE_TO_SAVE);
|
||||
if (favouritesAdapter.isEmpty()) {
|
||||
|
@ -799,7 +780,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
ch.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
openChangeGroupDialog(model);
|
||||
EditFavoriteGroupDialogFragment.showInstance(getChildFragmentManager(), model.name);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue