Fix creating group when selecting gpx

This commit is contained in:
PavelRatushny 2017-11-13 18:06:13 +02:00
parent f4023816c6
commit 7ce58add2d
4 changed files with 42 additions and 19 deletions

View file

@ -519,7 +519,6 @@ public class AppInitializer implements IProgress {
indexRegionsBoundaries(warnings);
notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES);
app.selectedGpxHelper.loadGPXTracks(this);
app.mapMarkersHelper.loadMapMarkersFromSelectedGpx();
notifyEvent(InitEvents.LOAD_GPX_TRACKS);
saveGPXTracks();
notifyEvent(InitEvents.SAVE_GPX_TRACKS);

View file

@ -482,7 +482,7 @@ public class GpxSelectionHelper {
selectedGPXFiles.remove(sf);
}
}
syncGpx(gpx);
syncGpx(gpx, true);
return sf;
}
@ -514,10 +514,25 @@ public class GpxSelectionHelper {
}
private void syncGpx(GPXFile gpxFile) {
syncGpx(gpxFile, false);
}
private void syncGpx(GPXFile gpxFile, boolean createOrDeleteGroup) {
File gpx = new File(gpxFile.path);
if (gpx.exists()) {
app.getMapMarkersHelper().syncGroup(new MarkersSyncGroup(gpx.getAbsolutePath(),
AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE));
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
boolean enabled = true;
if (createOrDeleteGroup) {
boolean show = getSelectedFileByPath(gpx.getAbsolutePath()) != null;
enabled = mapMarkersHelper.isGroupSynced(gpx.getAbsolutePath());
if (show && !enabled) {
mapMarkersHelper.addMarkersSyncGroup(syncGroup);
} else if (!show && mapMarkersHelper.isGroupDisabled(gpx.getAbsolutePath())) {
mapMarkersHelper.removeMarkersSyncGroup(gpx.getAbsolutePath(), true);
}
}
mapMarkersHelper.syncGroup(syncGroup, enabled);
}
}

View file

@ -390,6 +390,10 @@ public class MapMarkersHelper {
return markersDbHelper.getGroup(id) != null;
}
public boolean isGroupDisabled(String id) {
return markersDbHelper.isGroupDisabled(id);
}
public void syncAllGroups() {
List<MarkersSyncGroup> groups = markersDbHelper.getAllGroups();
for (MarkersSyncGroup gr : groups) {
@ -721,7 +725,7 @@ public class MapMarkersHelper {
if (removeActiveMarkers) {
removeActiveMarkersFromSyncGroup(id);
}
MapMarkersGroup group = getMapMarkerGroupByName(id);
MapMarkersGroup group = getMapMarkerGroupByKey(id);
if (group != null) {
mapMarkersGroups.remove(group);
}
@ -1164,19 +1168,6 @@ public class MapMarkersHelper {
}
}
public void loadMapMarkersFromSelectedGpx() {
List<SelectedGpxFile> selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) {
GPXFile gpx = selectedGpxFile.getGpxFile();
if (gpx.getPoints().size() > 0) {
File gpxFile = new File(gpx.path);
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(gpxFile.getAbsolutePath(), AndroidUtils.trimExtension(gpxFile.getName()), MarkersSyncGroup.GPX_TYPE);
addMarkersSyncGroup(syncGroup);
syncGroup(syncGroup, false);
}
}
}
private void sortGroups() {
if (mapMarkersGroups.size() > 0) {
MapMarkersGroup noGroup = null;

View file

@ -87,7 +87,8 @@ public class MapMarkersDbHelper {
private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " +
GROUPS_COL_NAME + ", " +
GROUPS_COL_TYPE +
GROUPS_COL_TYPE + ", " +
GROUPS_COL_DISABLED +
" FROM " + GROUPS_TABLE_NAME;
public static final String TAIL_NEXT_VALUE = "tail_next";
@ -275,6 +276,23 @@ public class MapMarkersDbHelper {
}
}
public boolean isGroupDisabled(String id) {
boolean disabled = false;
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT + " WHERE " + GROUPS_COL_ID + " = ?", new String[]{id});
if (query.moveToFirst()) {
disabled = query.getInt(3) == 1;
}
query.close();
} finally {
db.close();
}
}
return disabled;
}
public void removeDisabledGroups() {
SQLiteConnection db = openConnection(false);
if (db != null) {