From b5bab4e9138dca9269338352f6a3e651fb99be4a Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Mon, 7 Sep 2015 15:26:19 +0300 Subject: [PATCH] Fix for issue #1586 --- .../net/osmand/plus/FavouritesDbHelper.java | 28 ++--- .../activities/FavoritesTreeFragment.java | 101 +++++++++++------- .../osmand/plus/dialogs/FavoriteDialogs.java | 2 +- 3 files changed, 76 insertions(+), 55 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index b93c8367aa..e5f941f237 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -1,5 +1,18 @@ package net.osmand.plus; +import android.app.AlertDialog; +import android.content.Context; + +import net.osmand.PlatformUtil; +import net.osmand.data.FavouritePoint; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; +import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; +import net.osmand.util.Algorithms; + +import org.apache.tools.bzip2.CBZip2OutputStream; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -12,19 +25,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import net.osmand.PlatformUtil; -import net.osmand.data.FavouritePoint; -import net.osmand.plus.GPXUtilities.GPXFile; -import net.osmand.plus.GPXUtilities.WptPt; -import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; -import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; -import net.osmand.util.Algorithms; - -import org.apache.tools.bzip2.CBZip2OutputStream; - -import android.app.AlertDialog; -import android.content.Context; - public class FavouritesDbHelper { public interface FavoritesUpdatedListener { @@ -173,7 +173,7 @@ public class FavouritesDbHelper { return true; } - public static AlertDialog.Builder checkDublicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) { + public static AlertDialog.Builder checkDuplicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) { boolean emoticons = false; String index = ""; int number = 0; diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 28e8bbbcfc..490aaf1ff8 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -1,37 +1,5 @@ package net.osmand.plus.activities; -import gnu.trove.list.array.TIntArrayList; - -import java.io.File; -import java.text.MessageFormat; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.osmand.access.AccessibleToast; -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.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; -import net.osmand.plus.base.FavoriteImageDrawable; -import net.osmand.plus.dialogs.DirectionsDialogs; -import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.helpers.ColorDialogs; -import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.util.MapUtils; import android.app.Activity; import android.app.AlertDialog; import android.app.AlertDialog.Builder; @@ -69,6 +37,39 @@ 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; +import net.osmand.data.PointDescription; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; +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; +import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.dialogs.DirectionsDialogs; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.helpers.ColorDialogs; +import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.util.MapUtils; + +import java.io.File; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import gnu.trove.list.array.TIntArrayList; + public class FavoritesTreeFragment extends OsmandExpandableListFragment { @@ -187,9 +188,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { return true; } - public static boolean editPoint(Context ctx, final FavouritePoint point, final Runnable callback) { + public static boolean editPoint(final Context ctx, final FavouritePoint point, final Runnable callback) { OsmandApplication app = (OsmandApplication) ctx.getApplicationContext(); - Builder builder = new AlertDialog.Builder(ctx); + final Builder builder = new AlertDialog.Builder(ctx); builder.setTitle(R.string.favourites_context_menu_edit); final View v = LayoutInflater.from(ctx).inflate(R.layout.favorite_edit_dialog, null, false); @@ -212,13 +213,33 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment { 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 && callback != null) { - callback.run(); - - } + final String newName = editText.getText().toString().trim(); + point.setName(newName); + point.setCategory(cat.getText().toString()); + point.setDescription(editDescr.getText().toString()); + AlertDialog.Builder builder1 = helper.checkDuplicates(point, helper, ctx); + if (builder1 != null) { + builder1.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + boolean edited = helper.editFavouriteName(point, + point.getName(), cat.getText().toString(), + editDescr.getText().toString()); + if (edited && callback != null) { + callback.run(); + } + } + }); + builder1.create().show(); + } else { + boolean edited = helper.editFavouriteName(point, + newName, cat.getText().toString(), + editDescr.getText().toString()); + if (edited && callback != null) { + callback.run(); + } + } } }); builder.create().show(); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java index a593fa55ed..d976fd6a40 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java @@ -135,7 +135,7 @@ public class FavoriteDialogs { point.setName(editText.getText().toString().trim()); point.setDescription(description.getText().toString().trim()); point.setCategory(categoryStr); - Builder bld = FavouritesDbHelper.checkDublicates(point, helper, activity); + Builder bld = FavouritesDbHelper.checkDuplicates(point, helper, activity); if(bld != null) { bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override