Change sync method
This commit is contained in:
parent
e97c85cf95
commit
8ef2ce4f8d
10 changed files with 35 additions and 38 deletions
|
@ -522,7 +522,7 @@ public class AppInitializer implements IProgress {
|
|||
notifyEvent(InitEvents.LOAD_GPX_TRACKS);
|
||||
saveGPXTracks();
|
||||
notifyEvent(InitEvents.SAVE_GPX_TRACKS);
|
||||
app.mapMarkersHelper.syncAllGroups();
|
||||
app.mapMarkersHelper.syncAllGroupsAsync();
|
||||
// restore backuped favorites to normal file
|
||||
restoreBackupForFavoritesFiles();
|
||||
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
||||
|
|
|
@ -148,7 +148,7 @@ public class FavouritesDbHelper {
|
|||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
for (FavoriteGroup gr : groupsToSync) {
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
}
|
||||
}
|
||||
if (groupsToDelete != null) {
|
||||
|
@ -171,7 +171,7 @@ public class FavouritesDbHelper {
|
|||
FavoriteGroup group = flatGroups.get(p.getCategory());
|
||||
if (group != null) {
|
||||
group.points.remove(p);
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE));
|
||||
}
|
||||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
|
@ -201,7 +201,7 @@ public class FavouritesDbHelper {
|
|||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -296,7 +296,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(category, category, MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -304,7 +304,7 @@ public class FavouritesDbHelper {
|
|||
p.setLatitude(lat);
|
||||
p.setLongitude(lon);
|
||||
saveCurrentPointsIntoFile();
|
||||
context.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
context.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(p.getCategory(), p.getCategory(), MarkersSyncGroup.FAVORITES_TYPE, p.getColor()));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -621,7 +621,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setColor(color);
|
||||
}
|
||||
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
|
||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, color));
|
||||
}
|
||||
if (group.visible != visible) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
|
@ -629,7 +629,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setVisible(visible);
|
||||
}
|
||||
markersHelper.syncGroup(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
markersHelper.syncGroupAsync(new MarkersSyncGroup(gr.name, gr.name, MarkersSyncGroup.FAVORITES_TYPE, group.color));
|
||||
}
|
||||
if (!group.name.equals(newName)) {
|
||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||
|
@ -651,7 +651,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
MarkersSyncGroup syncGroup = new MarkersSyncGroup(renamedGroup.name, renamedGroup.name, MarkersSyncGroup.FAVORITES_TYPE, group.color);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
markersHelper.syncGroupAsync(syncGroup);
|
||||
}
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
|
|
|
@ -538,7 +538,7 @@ public class GpxSelectionHelper {
|
|||
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true);
|
||||
}
|
||||
}
|
||||
mapMarkersHelper.syncGroup(syncGroup, enabled);
|
||||
mapMarkersHelper.syncGroupAsync(syncGroup, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -452,28 +452,33 @@ public class MapMarkersHelper {
|
|||
return markersDbHelper.isGroupDisabled(id);
|
||||
}
|
||||
|
||||
public void syncAllGroups() {
|
||||
public void syncAllGroupsAsync() {
|
||||
List<MarkersSyncGroup> groups = markersDbHelper.getAllGroups();
|
||||
for (MarkersSyncGroup gr : groups) {
|
||||
syncGroup(gr);
|
||||
syncGroupAsync(gr);
|
||||
}
|
||||
}
|
||||
|
||||
public void syncGroup(MarkersSyncGroup group) {
|
||||
syncGroup(group, true, null);
|
||||
public void syncGroupAsync(MarkersSyncGroup group) {
|
||||
syncGroupAsync(group, true, null);
|
||||
}
|
||||
|
||||
public void syncGroup(MarkersSyncGroup group, boolean enabled) {
|
||||
syncGroup(group, enabled, null);
|
||||
public void syncGroupAsync(MarkersSyncGroup group, boolean enabled) {
|
||||
syncGroupAsync(group, enabled, null);
|
||||
}
|
||||
|
||||
public void syncGroup(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) {
|
||||
syncGroup(group, true, groupSyncedListener);
|
||||
public void syncGroupAsync(MarkersSyncGroup group, OnGroupSyncedListener groupSyncedListener) {
|
||||
syncGroupAsync(group, true, groupSyncedListener);
|
||||
}
|
||||
|
||||
private void syncGroup(MarkersSyncGroup group, boolean enabled, OnGroupSyncedListener groupSyncedListener) {
|
||||
SyncGroupTask syncGroupTask = new SyncGroupTask(group, enabled, groupSyncedListener);
|
||||
syncGroupTask.executeOnExecutor(executorService);
|
||||
private void syncGroupAsync(final MarkersSyncGroup group, final boolean enabled, final OnGroupSyncedListener groupSyncedListener) {
|
||||
ctx.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SyncGroupTask syncGroupTask = new SyncGroupTask(group, enabled, groupSyncedListener);
|
||||
syncGroupTask.executeOnExecutor(executorService);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
||||
|
@ -491,7 +496,6 @@ public class MapMarkersHelper {
|
|||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
runGroupSynchronization();
|
||||
onGroupSynced();
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -551,7 +555,8 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void onGroupSynced() {
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if (listener != null) {
|
||||
ctx.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
|
|
|
@ -23,9 +23,6 @@ import android.widget.ImageView;
|
|||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
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.IconsCache;
|
||||
|
@ -37,9 +34,6 @@ import net.osmand.plus.base.BottomSheetDialogFragment;
|
|||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
public static final String TAG = "EditFavoriteGroupDialogFragment";
|
||||
|
@ -188,7 +182,7 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
markersHelper.syncGroupAsync(syncGroup);
|
||||
dismiss();
|
||||
MapActivity.launchMapActivityMoveToTop(getActivity());
|
||||
}
|
||||
|
|
|
@ -412,7 +412,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
|
|||
new MarkersSyncGroup(favGr.name, favGr.name, MarkersSyncGroup.FAVORITES_TYPE, favGr.color);
|
||||
if (entry.getValue().size() == favGr.points.size()) {
|
||||
markersHelper.addMarkersSyncGroup(syncGr);
|
||||
markersHelper.syncGroup(syncGr);
|
||||
markersHelper.syncGroupAsync(syncGr);
|
||||
} else {
|
||||
for (FavouritePoint fp : entry.getValue()) {
|
||||
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
|
||||
|
|
|
@ -180,7 +180,7 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
getMyApplication().getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
getMyApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
@ -10,7 +9,6 @@ import android.view.ContextThemeWrapper;
|
|||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
|
@ -65,7 +63,7 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
|
||||
MarkersSyncGroup group = createMapMarkersSyncGroup(position);
|
||||
mapMarkersHelper.addMarkersSyncGroup(group);
|
||||
mapMarkersHelper.syncGroup(group, new MapMarkersHelper.OnGroupSyncedListener() {
|
||||
mapMarkersHelper.syncGroupAsync(group, new MapMarkersHelper.OnGroupSyncedListener() {
|
||||
@Override
|
||||
public void onSyncDone() {
|
||||
if (listener != null) {
|
||||
|
|
|
@ -580,7 +580,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
app.getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
}
|
||||
}
|
||||
|
@ -635,7 +635,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
|
|||
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
markersHelper.addMarkersSyncGroup(syncGroup);
|
||||
markersHelper.syncGroup(syncGroup);
|
||||
markersHelper.syncGroupAsync(syncGroup);
|
||||
GPXFile gpxFile = getTrackActivity().getGpx();
|
||||
if (gpxFile != null) {
|
||||
app.getSelectedGpxHelper().selectGpxFile(gpxFile, true, false);
|
||||
|
|
|
@ -655,7 +655,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
File gpx = new File(gpxFile.path);
|
||||
if (gpx.exists()) {
|
||||
view.getApplication().getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
view.getApplication().getMapMarkersHelper().syncGroupAsync(new MarkersSyncGroup(gpx.getAbsolutePath(),
|
||||
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue