Merge pull request #6488 from osmandapp/kolomiets_branch
Kolomiets branch
This commit is contained in:
commit
836e95bdab
2 changed files with 54 additions and 31 deletions
|
@ -46,7 +46,7 @@ public class FavouritesDbHelper {
|
||||||
private List<FavoriteGroup> favoriteGroups = new ArrayList<FavouritesDbHelper.FavoriteGroup>();
|
private List<FavoriteGroup> favoriteGroups = new ArrayList<FavouritesDbHelper.FavoriteGroup>();
|
||||||
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<String, FavouritesDbHelper.FavoriteGroup>();
|
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<String, FavouritesDbHelper.FavoriteGroup>();
|
||||||
private final OsmandApplication context;
|
private final OsmandApplication context;
|
||||||
protected static final String HIDDEN = "HIDDEN";
|
protected static final String HIDDEN = "hidden";
|
||||||
private static final String DELIMETER = "__";
|
private static final String DELIMETER = "__";
|
||||||
|
|
||||||
private Set<FavoritesListener> listeners = new HashSet<>();
|
private Set<FavoritesListener> listeners = new HashSet<>();
|
||||||
|
|
|
@ -25,7 +25,11 @@ import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
|
import net.osmand.plus.AppInitializer;
|
||||||
|
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||||
|
import net.osmand.plus.AppInitializer.InitEvents;
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
@ -60,12 +64,13 @@ import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.zip.ZipInputStream;
|
import java.util.zip.ZipInputStream;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Koen Rabaey
|
* @author Koen Rabaey
|
||||||
*/
|
*/
|
||||||
public class ImportHelper {
|
public class ImportHelper {
|
||||||
|
public final static Log log = PlatformUtil.getLog(ImportHelper.class);
|
||||||
public static final String KML_SUFFIX = ".kml";
|
public static final String KML_SUFFIX = ".kml";
|
||||||
public static final String KMZ_SUFFIX = ".kmz";
|
public static final String KMZ_SUFFIX = ".kmz";
|
||||||
public static final String GPX_SUFFIX = ".gpx";
|
public static final String GPX_SUFFIX = ".gpx";
|
||||||
|
@ -248,17 +253,21 @@ public class ImportHelper {
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
|
private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
|
||||||
|
if(!app.isApplicationInitializing()) {
|
||||||
new AsyncTask<Void, Void, GPXFile>() {
|
new AsyncTask<Void, Void, GPXFile>() {
|
||||||
ProgressDialog progress = null;
|
ProgressDialog progress = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
|
progress = ProgressDialog
|
||||||
|
.show(activity, app.getString(R.string.loading_smth, ""),
|
||||||
|
app.getString(R.string.loading_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected GPXFile doInBackground(Void... nothing) {
|
protected GPXFile doInBackground(Void... nothing) {
|
||||||
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(), fileName, forceImportFavourites);
|
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(),
|
||||||
|
fileName, forceImportFavourites);
|
||||||
final FavouritesDbHelper favoritesHelper = app.getFavorites();
|
final FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||||
for (final FavouritePoint favourite : favourites) {
|
for (final FavouritePoint favourite : favourites) {
|
||||||
favoritesHelper.deleteFavourite(favourite, false);
|
favoritesHelper.deleteFavourite(favourite, false);
|
||||||
|
@ -274,13 +283,27 @@ public class ImportHelper {
|
||||||
if (isActivityNotDestroyed(activity)) {
|
if (isActivityNotDestroyed(activity)) {
|
||||||
progress.dismiss();
|
progress.dismiss();
|
||||||
}
|
}
|
||||||
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
|
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
|
||||||
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
|
.show();
|
||||||
|
final Intent newIntent = new Intent(activity,
|
||||||
|
app.getAppCustomization().getFavoritesActivity());
|
||||||
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
|
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
|
||||||
activity.startActivity(newIntent);
|
activity.startActivity(newIntent);
|
||||||
}
|
}
|
||||||
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
} else {
|
||||||
|
app.getAppInitializer().addListener(new AppInitializeListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onProgress(AppInitializer init, InitEvents event) {}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFinish(AppInitializer init) {
|
||||||
|
importFavoritesImpl(gpxFile, fileName, forceImportFavourites);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
|
|
Loading…
Reference in a new issue