diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 65f4a51cd9..b3e8d39e3c 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -16,6 +16,7 @@ import java.util.regex.Pattern; import android.app.AlertDialog; import android.content.ActivityNotFoundException; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; @@ -151,9 +152,6 @@ public class FavouritesDbHelper { } FavoriteGroup group = getOrCreateGroup(p, 0); - //making sure that dublicated names will not occur in favorites - checkDublicates(p); - if (!p.getName().equals("")) { p.setVisible(group.visible); p.setColor(group.color); @@ -167,45 +165,45 @@ public class FavouritesDbHelper { return true; } - private void checkDublicates(FavouritePoint p){ - boolean fl = true; + public static AlertDialog.Builder checkDublicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) { boolean emoticons = false; String index = ""; int number = 0; String name = checkEmoticons(p.getName()); String category = checkEmoticons(p.getCategory()); p.setCategory(category); - if (name.length() != p.getName().length()){ + if (name.length() != p.getName().length()) { emoticons = true; } - while (fl){ + boolean fl = true; + while (fl) { fl = false; - for (FavouritePoint fp : cachedFavoritePoints){ - if (fp.getName().equals(name)){ + for (FavouritePoint fp : fdb.getFavouritePoints()) { + if (fp.getName().equals(name)) { number++; index = " (" + number + ")"; name = p.getName() + index; - fl=true; + fl = true; break; } } } - if ((index.length() > 0 || emoticons)&& - context.getMapActivity() != null){ - AlertDialog.Builder builder = new AlertDialog.Builder(context.getMapActivity()); + if ((index.length() > 0 || emoticons) ) { + AlertDialog.Builder builder = new AlertDialog.Builder(uiContext); builder.setTitle(R.string.fav_point_dublicate); - if (emoticons){ - builder.setMessage(context.getString(R.string.fav_point_emoticons_message, name)); + if (emoticons) { + builder.setMessage(uiContext.getString(R.string.fav_point_emoticons_message, name)); } else { - builder.setMessage(context.getString(R.string.fav_point_dublicate_message, name)); + builder.setMessage(uiContext.getString(R.string.fav_point_dublicate_message, name)); } builder.setPositiveButton(R.string.default_buttons_ok, null); p.setName(name); - builder.show(); + return builder; } + return null; } - public String checkEmoticons(String name){ + public static String checkEmoticons(String name){ char[] chars = name.toCharArray(); int index; char ch1; diff --git a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java index ac9c2ce641..3629bd4d31 100644 --- a/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java +++ b/OsmAnd/src/net/osmand/plus/OsmAndAppCustomization.java @@ -152,4 +152,10 @@ public class OsmAndAppCustomization { return false; } + public void resumeActivity(Class class1, T d) { + } + + public void pauseActivity(Class class1) { + } + } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 3968ca0eca..ac3f9b5fe0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -117,9 +117,6 @@ public class OsmandApplication extends Application { SQLiteAPI sqliteAPI; BRouterServiceConnection bRouterServiceConnection; - - MapActivity mapActivity; - DownloadActivity downloadActivity; // Typeface @@ -915,19 +912,5 @@ public class OsmandApplication extends Application { } } - public MapActivity getMapActivity() { - return mapActivity; - } - public void setMapActivity(MapActivity mapActivity) { - this.mapActivity = mapActivity; - } - - public void setDownloadActivity(DownloadActivity downloadActivity) { - this.downloadActivity = downloadActivity; - } - - public DownloadActivity getDownloadActivity() { - return downloadActivity; - } } diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9b30725a63..1d24a5f819 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -369,7 +369,6 @@ public class MapActivity extends AccessibleActivity { } settings.MAP_ACTIVITY_ENABLED.set(true); - app.setMapActivity(this); checkExternalStorage(); showAndHideMapPosition(); @@ -443,6 +442,7 @@ public class MapActivity extends AccessibleActivity { if(atlasMapRendererView != null) { atlasMapRendererView.handleOnResume(); } + getMyApplication().getAppCustomization().resumeActivity(MapActivity.class, this); } @@ -661,7 +661,7 @@ public class MapActivity extends AccessibleActivity { settings.setLastKnownMapZoom(mapView.getZoom()); settings.MAP_ACTIVITY_ENABLED.set(false); - app.setMapActivity(null); + getMyApplication().getAppCustomization().pauseActivity(MapActivity.class); app.getResourceManager().interruptRendering(); app.getResourceManager().setBusyIndicator(null); OsmandPlugin.onMapActivityPause(this); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java index e80bf16205..f125106510 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/FavoriteDialogs.java @@ -12,17 +12,17 @@ import net.osmand.AndroidUtils; import net.osmand.access.AccessibleToast; import net.osmand.data.FavouritePoint; import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.util.MapUtils; import android.app.Activity; import android.app.AlertDialog; -import android.app.Dialog; import android.app.AlertDialog.Builder; +import android.app.Dialog; import android.content.DialogInterface; import android.content.res.Resources; import android.os.Build; @@ -202,13 +202,27 @@ public class FavoriteDialogs { builder.setPositiveButton(R.string.default_buttons_add, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE); + final FavouritePoint point = (FavouritePoint) args.getSerializable(KEY_FAVORITE); OsmandApplication app = (OsmandApplication) activity.getApplication(); String categoryStr = cat.getText().toString().trim(); final FavouritesDbHelper helper = app.getFavorites(); app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(categoryStr); point.setName(editText.getText().toString().trim()); point.setCategory(categoryStr); + Builder bld = FavouritesDbHelper.checkDublicates(point, helper, activity); + if(bld != null) { + bld.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + addFavorite(activity, point, helper); + } + }); + } else { + addFavorite(activity, point, helper); + } + } + + protected void addFavorite(final Activity activity, FavouritePoint point, final FavouritesDbHelper helper) { boolean added = helper.addFavourite(point); if (added) { AccessibleToast.makeText(activity, MessageFormat.format( diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java index aca427c9e1..fb5cf31a82 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivity.java @@ -171,7 +171,7 @@ public class DownloadActivity extends BaseDownloadActivity { @Override protected void onResume() { super.onResume(); - getMyApplication().setDownloadActivity(this); + getMyApplication().getAppCustomization().resumeActivity(DownloadActivity.class, this); } @@ -208,7 +208,7 @@ public class DownloadActivity extends BaseDownloadActivity { @Override public void onPause() { super.onPause(); - (getMyApplication()).setDownloadActivity(null); + getMyApplication().getAppCustomization().pauseActivity(DownloadActivity.class); } @Override diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java index 91d08cd075..07f9efdaf7 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxImportHelper.java @@ -65,7 +65,8 @@ public class GpxImportHelper { if (fileName != null && fileName.endsWith(KML_SUFFIX)) { handleKmlImport(intentUri, fileName, saveFile); - } else if (fileName != null && fileName.endsWith("favourites.gpx")) { + } else if (fileName != null && (fileName.contains("favourite")|| + fileName.contains("favorite"))) { handleFavouritesImport(intentUri, fileName, saveFile); } else { handleGpxImport(intentUri, fileName, saveFile); diff --git a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java index 65d60e2284..ebf6e7fb03 100644 --- a/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java +++ b/OsmAnd/src/net/osmand/plus/sherpafy/SherpafyCustomization.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -82,6 +83,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { public static final String TOUR_SERVER = "download.osmand.net"; private static final String SAVE_GPX_FOLDER = "save_gpx_folder"; private Object originalGlobal; + private Map, Object> activities = new HashMap, Object>(); @Override public void setup(OsmandApplication app) { @@ -205,7 +207,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } this.tourPresent = tourPresent; if(!suggestToDownloadMap.isEmpty()) { - final DownloadActivity da = app.getDownloadActivity(); + final DownloadActivity da = (DownloadActivity) activities.get(DownloadActivity.class); if (da != null) { app.runInUIThread(new Runnable() { @@ -662,7 +664,7 @@ public class SherpafyCustomization extends OsmAndAppCustomization { } public boolean onDestinationReached() { - final MapActivity map = app.getMapActivity(); + final MapActivity map = (MapActivity) activities.get(MapActivity.class); if(map != null && getSelectedStage() != null) { app.runInUIThread(new Runnable() { @@ -675,6 +677,17 @@ public class SherpafyCustomization extends OsmAndAppCustomization { return true; } + @Override + public void pauseActivity(Class class1) { + super.pauseActivity(class1); + } + + @Override + @SuppressWarnings("unchecked") + public void resumeActivity(Class class1, T d) { + activities.put((Class) class1, d); + } + public void runStage(Activity a, TourInformation tour, StageInformation stage, boolean startOver) { WptPt point = null; GPXFile gpx = null;