Merge pull request #6488 from osmandapp/kolomiets_branch

Kolomiets branch
This commit is contained in:
Alexey 2019-02-01 12:43:07 +03:00 committed by GitHub
commit 836e95bdab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 31 deletions

View file

@ -46,7 +46,7 @@ public class FavouritesDbHelper {
private List<FavoriteGroup> favoriteGroups = new ArrayList<FavouritesDbHelper.FavoriteGroup>();
private Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<String, FavouritesDbHelper.FavoriteGroup>();
private final OsmandApplication context;
protected static final String HIDDEN = "HIDDEN";
protected static final String HIDDEN = "hidden";
private static final String DELIMETER = "__";
private Set<FavoritesListener> listeners = new HashSet<>();

View file

@ -25,7 +25,11 @@ import android.widget.Toast;
import net.osmand.IProgress;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
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.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
@ -60,12 +64,13 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.zip.ZipInputStream;
import org.apache.commons.logging.Log;
/**
* @author Koen Rabaey
*/
public class ImportHelper {
public final static Log log = PlatformUtil.getLog(ImportHelper.class);
public static final String KML_SUFFIX = ".kml";
public static final String KMZ_SUFFIX = ".kmz";
public static final String GPX_SUFFIX = ".gpx";
@ -248,39 +253,57 @@ public class ImportHelper {
@SuppressLint("StaticFieldLeak")
private void importFavoritesImpl(final GPXFile gpxFile, final String fileName, final boolean forceImportFavourites) {
new AsyncTask<Void, Void, GPXFile>() {
ProgressDialog progress = null;
if(!app.isApplicationInitializing()) {
new AsyncTask<Void, Void, GPXFile>() {
ProgressDialog progress = null;
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
}
@Override
protected GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(), fileName, forceImportFavourites);
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false);
@Override
protected void onPreExecute() {
progress = ProgressDialog
.show(activity, app.getString(R.string.loading_smth, ""),
app.getString(R.string.loading_data));
}
favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile();
return null;
}
@Override
protected void onPostExecute(GPXFile result) {
if (isActivityNotDestroyed(activity)) {
progress.dismiss();
@Override
protected GPXFile doInBackground(Void... nothing) {
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(),
fileName, forceImportFavourites);
final FavouritesDbHelper favoritesHelper = app.getFavorites();
for (final FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false);
}
favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile();
return null;
}
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG).show();
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
activity.startActivity(newIntent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@Override
protected void onPostExecute(GPXFile result) {
if (isActivityNotDestroyed(activity)) {
progress.dismiss();
}
Toast.makeText(activity, R.string.fav_imported_sucessfully, Toast.LENGTH_LONG)
.show();
final Intent newIntent = new Intent(activity,
app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
activity.startActivity(newIntent);
}
}.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")