SUpport editing favorite
This commit is contained in:
parent
2c01b6fe8f
commit
cf2eba88a8
4 changed files with 43 additions and 13 deletions
|
@ -37,7 +37,6 @@
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:completionThreshold="1"
|
android:completionThreshold="1"
|
||||||
android:inputType="textCapWords"
|
|
||||||
android:selectAllOnFocus="true"/>
|
android:selectAllOnFocus="true"/>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -50,8 +49,9 @@
|
||||||
android:id="@+id/descr"
|
android:id="@+id/descr"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:completionThreshold="1"
|
android:inputType="textMultiLine"
|
||||||
android:inputType="textCapWords"
|
android:minLines="2"
|
||||||
|
android:scrollbars="vertical"
|
||||||
android:selectAllOnFocus="true"/>
|
android:selectAllOnFocus="true"/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
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="agps_info">A-GPS info</string>
|
<string name="agps_info">A-GPS info</string>
|
||||||
|
<string name="shared_string_show_description">Show description</string>
|
||||||
<string name="shared_string_message">Message</string>
|
<string name="shared_string_message">Message</string>
|
||||||
<string name="agps_data_last_downloaded">A-GPS data last downloaded: %1$s</string>
|
<string name="agps_data_last_downloaded">A-GPS data last downloaded: %1$s</string>
|
||||||
<string name="confirm_usage_speed_cameras">In many countries (Germany, France, Italy, and others) the use of speed camera warnings is not permitted by law. OsmAnd does assume any liability if you violate the law. Please click yes only if you are eligible to use this feature.</string>
|
<string name="confirm_usage_speed_cameras">In many countries (Germany, France, Italy, and others) the use of speed camera warnings is not permitted by law. OsmAnd does assume any liability if you violate the law. Please click yes only if you are eligible to use this feature.</string>
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.activities;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
@ -35,7 +36,6 @@ import android.widget.ImageView;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -47,6 +47,7 @@ import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.IconsCache;
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandSettings;
|
import net.osmand.plus.OsmandSettings;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TargetPointsHelper;
|
import net.osmand.plus.TargetPointsHelper;
|
||||||
|
@ -199,7 +200,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
editPoint(point);
|
editPoint(getActivity(), point, new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
favouritesAdapter.synchronizeGroups();
|
||||||
|
}
|
||||||
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -220,11 +225,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean editPoint(final FavouritePoint point) {
|
public static boolean editPoint(Context ctx, final FavouritePoint point, final Runnable callback) {
|
||||||
Builder builder = new AlertDialog.Builder(getActivity());
|
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
|
||||||
|
Builder builder = new AlertDialog.Builder(ctx);
|
||||||
builder.setTitle(R.string.favourites_context_menu_edit);
|
builder.setTitle(R.string.favourites_context_menu_edit);
|
||||||
final View v = getActivity().getLayoutInflater().inflate(R.layout.favorite_edit_dialog,
|
final View v = LayoutInflater.from(ctx).inflate(R.layout.favorite_edit_dialog,
|
||||||
getExpandableListView(), false);
|
null, false);
|
||||||
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
|
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
|
||||||
final EditText editText = (EditText) v.findViewById(R.id.Name);
|
final EditText editText = (EditText) v.findViewById(R.id.Name);
|
||||||
final EditText editDescr = (EditText) v.findViewById(R.id.descr);
|
final EditText editDescr = (EditText) v.findViewById(R.id.descr);
|
||||||
|
@ -233,20 +239,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
||||||
editDescr.setText(point.getDescription());
|
editDescr.setText(point.getDescription());
|
||||||
cat.setText(point.getCategory());
|
cat.setText(point.getCategory());
|
||||||
cat.setThreshold(1);
|
cat.setThreshold(1);
|
||||||
|
final FavouritesDbHelper helper = app.getFavorites();
|
||||||
List<FavoriteGroup> gs = helper.getFavoriteGroups();
|
List<FavoriteGroup> gs = helper.getFavoriteGroups();
|
||||||
String[] list = new String[gs.size()];
|
String[] list = new String[gs.size()];
|
||||||
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>(getActivity(), R.layout.list_textview, list));
|
cat.setAdapter(new ArrayAdapter<String>(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
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
boolean edited = helper.editFavouriteName(point, editText.getText().toString().trim(), cat.getText()
|
boolean edited = helper.editFavouriteName(point, editText.getText().toString().trim(), cat.getText()
|
||||||
.toString(), editDescr.getText().toString());
|
.toString(), editDescr.getText().toString());
|
||||||
if (edited) {
|
if (edited && callback != null) {
|
||||||
favouritesAdapter.synchronizeGroups();
|
callback.run();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.LocationPoint;
|
import net.osmand.data.LocationPoint;
|
||||||
|
@ -13,9 +14,12 @@ import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.activities.FavoritesTreeFragment;
|
||||||
import net.osmand.plus.base.FavoriteImageDrawable;
|
import net.osmand.plus.base.FavoriteImageDrawable;
|
||||||
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.app.AlertDialog.Builder;
|
import android.app.AlertDialog.Builder;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
@ -204,7 +208,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
|
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<?> adapter, int itemId, int pos, boolean isChecked) {
|
||||||
if (itemId == R.string.favourites_context_menu_delete) {
|
if (itemId == R.string.favourites_context_menu_edit) {
|
||||||
|
FavoritesTreeFragment.editPoint(view.getContext(), a, null);
|
||||||
|
} else if (itemId == R.string.shared_string_show_description) {
|
||||||
|
showDescriptionDialog(a);
|
||||||
|
} else if (itemId == R.string.favourites_context_menu_delete) {
|
||||||
final Resources resources = view.getContext().getResources();
|
final Resources resources = view.getContext().getResources();
|
||||||
Builder builder = new AlertDialog.Builder(view.getContext());
|
Builder builder = new AlertDialog.Builder(view.getContext());
|
||||||
builder.setMessage(resources.getString(R.string.favourites_remove_dialog_msg, a.getName()));
|
builder.setMessage(resources.getString(R.string.favourites_remove_dialog_msg, a.getName()));
|
||||||
|
@ -221,12 +229,25 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (!Algorithms.isEmpty(a.getDescription())) {
|
||||||
|
adapter.item(R.string.shared_string_show_description).iconColor(R.drawable.ic_action_note_dark)
|
||||||
|
.listen(listener).reg();
|
||||||
|
}
|
||||||
|
adapter.item(R.string.favourites_context_menu_edit).iconColor(R.drawable.ic_action_edit_dark)
|
||||||
|
.listen(listener).reg();
|
||||||
adapter.item(R.string.favourites_context_menu_delete)
|
adapter.item(R.string.favourites_context_menu_delete)
|
||||||
.iconColor(R.drawable.ic_action_delete_dark).listen(listener)
|
.iconColor(R.drawable.ic_action_delete_dark).listen(listener)
|
||||||
.reg();
|
.reg();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void showDescriptionDialog(FavouritePoint a) {
|
||||||
|
Builder bs = new AlertDialog.Builder(view.getContext());
|
||||||
|
bs.setTitle(a.getName(view.getContext()));
|
||||||
|
bs.setMessage(a.getDescription());
|
||||||
|
bs.show();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LatLon getTextLocation(LocationPoint o) {
|
public LatLon getTextLocation(LocationPoint o) {
|
||||||
return new LatLon(o.getLatitude(), o.getLongitude());
|
return new LatLon(o.getLatitude(), o.getLongitude());
|
||||||
|
|
Loading…
Reference in a new issue