Never cache activities they could be not active
This commit is contained in:
parent
3366d9e2e7
commit
d4c5e748e3
8 changed files with 60 additions and 45 deletions
|
@ -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;
|
||||
|
|
|
@ -152,4 +152,10 @@ public class OsmAndAppCustomization {
|
|||
return false;
|
||||
}
|
||||
|
||||
public <T> void resumeActivity(Class<T> class1, T d) {
|
||||
}
|
||||
|
||||
public <T> void pauseActivity(Class<T> class1) {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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<Class<Object>, Object> activities = new HashMap<Class<Object>, 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 <T> void pauseActivity(Class<T> class1) {
|
||||
super.pauseActivity(class1);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> void resumeActivity(Class<T> class1, T d) {
|
||||
activities.put((Class<Object>) class1, d);
|
||||
}
|
||||
|
||||
public void runStage(Activity a, TourInformation tour, StageInformation stage, boolean startOver) {
|
||||
WptPt point = null;
|
||||
GPXFile gpx = null;
|
||||
|
|
Loading…
Reference in a new issue