SUpport editing favorite

This commit is contained in:
Victor Shcherb 2015-04-02 00:11:47 +02:00
parent 2c01b6fe8f
commit cf2eba88a8
4 changed files with 43 additions and 13 deletions

View file

@ -37,7 +37,6 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:inputType="textCapWords"
android:selectAllOnFocus="true"/>
<TextView
@ -50,8 +49,9 @@
android:id="@+id/descr"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:completionThreshold="1"
android:inputType="textCapWords"
android:inputType="textMultiLine"
android:minLines="2"
android:scrollbars="vertical"
android:selectAllOnFocus="true"/>
</LinearLayout>

View file

@ -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
-->
<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="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>

View file

@ -3,6 +3,7 @@ package net.osmand.plus.activities;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
@ -35,7 +36,6 @@ import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
@ -47,6 +47,7 @@ import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@ -199,7 +200,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
editPoint(point);
editPoint(getActivity(), point, new Runnable() {
public void run() {
favouritesAdapter.synchronizeGroups();
}
});
return true;
}
});
@ -220,11 +225,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
return true;
}
private boolean editPoint(final FavouritePoint point) {
Builder builder = new AlertDialog.Builder(getActivity());
public static boolean editPoint(Context ctx, final FavouritePoint point, final Runnable callback) {
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(R.string.favourites_context_menu_edit);
final View v = getActivity().getLayoutInflater().inflate(R.layout.favorite_edit_dialog,
getExpandableListView(), false);
final View v = LayoutInflater.from(ctx).inflate(R.layout.favorite_edit_dialog,
null, false);
final AutoCompleteTextView cat = (AutoCompleteTextView) v.findViewById(R.id.Category);
final EditText editText = (EditText) v.findViewById(R.id.Name);
final EditText editDescr = (EditText) v.findViewById(R.id.descr);
@ -233,20 +239,22 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
editDescr.setText(point.getDescription());
cat.setText(point.getCategory());
cat.setThreshold(1);
final FavouritesDbHelper helper = app.getFavorites();
List<FavoriteGroup> gs = helper.getFavoriteGroups();
String[] list = new String[gs.size()];
for(int i = 0; i < list.length; i++) {
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.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
boolean edited = helper.editFavouriteName(point, editText.getText().toString().trim(), cat.getText()
.toString(), editDescr.getText().toString());
if (edited) {
favouritesAdapter.synchronizeGroups();
if (edited && callback != null) {
callback.run();
}
}

View file

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List;
import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
@ -13,9 +14,12 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnContextMenuClick;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.activities.FavoritesTreeFragment;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import net.osmand.util.Algorithms;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
@ -204,7 +208,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
OnContextMenuClick listener = new ContextMenuAdapter.OnContextMenuClick() {
@Override
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();
Builder builder = new AlertDialog.Builder(view.getContext());
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;
}
};
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)
.iconColor(R.drawable.ic_action_delete_dark).listen(listener)
.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
public LatLon getTextLocation(LocationPoint o) {
return new LatLon(o.getLatitude(), o.getLongitude());