Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
992c9cdc75
2 changed files with 46 additions and 18 deletions
|
@ -282,11 +282,15 @@ public class MapMarkersHelper {
|
||||||
return getMapMarkerGroupById(id) != null;
|
return getMapMarkerGroupById(id) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void runSynchronization(@NonNull final MapMarkersGroup group) {
|
public void runSynchronization(@NonNull MapMarkersGroup group) {
|
||||||
|
runSynchronization(group, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void runSynchronization(@NonNull final MapMarkersGroup group, final boolean loadGpx) {
|
||||||
ctx.runInUIThread(new Runnable() {
|
ctx.runInUIThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
new SyncGroupTask(group).executeOnExecutor(executorService);
|
new SyncGroupTask(group, loadGpx).executeOnExecutor(executorService);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1038,9 +1042,11 @@ public class MapMarkersHelper {
|
||||||
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
||||||
|
|
||||||
private MapMarkersGroup group;
|
private MapMarkersGroup group;
|
||||||
|
private boolean loadGpx;
|
||||||
|
|
||||||
SyncGroupTask(MapMarkersGroup group) {
|
SyncGroupTask(MapMarkersGroup group, boolean loadGpx) {
|
||||||
this.group = group;
|
this.group = group;
|
||||||
|
this.loadGpx = loadGpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1094,10 +1100,15 @@ public class MapMarkersHelper {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
|
String gpxPath = group.getId();
|
||||||
|
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
|
||||||
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
||||||
group.visible = gpx != null;
|
if (gpx == null && loadGpx) {
|
||||||
if (!group.isVisible() || group.isDisabled()) {
|
gpx = GPXUtilities.loadGPXFile(ctx, new File(gpxPath));
|
||||||
|
gpxHelper.selectGpxFile(gpx, true, false, false);
|
||||||
|
}
|
||||||
|
group.visible = gpx != null || group.visibleUntilRestart;
|
||||||
|
if (gpx == null || group.isDisabled()) {
|
||||||
removeGroupActiveMarkers(group, true);
|
removeGroupActiveMarkers(group, true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1144,6 +1155,7 @@ public class MapMarkersHelper {
|
||||||
private long creationDate;
|
private long creationDate;
|
||||||
private boolean disabled;
|
private boolean disabled;
|
||||||
private boolean visible = true;
|
private boolean visible = true;
|
||||||
|
private boolean visibleUntilRestart;
|
||||||
private List<MapMarker> markers = new ArrayList<>();
|
private List<MapMarker> markers = new ArrayList<>();
|
||||||
// TODO should be removed from this class:
|
// TODO should be removed from this class:
|
||||||
private GroupHeader header;
|
private GroupHeader header;
|
||||||
|
@ -1187,6 +1199,10 @@ public class MapMarkersHelper {
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setVisibleUntilRestart(boolean visibleUntilRestart) {
|
||||||
|
this.visibleUntilRestart = visibleUntilRestart;
|
||||||
|
}
|
||||||
|
|
||||||
public List<MapMarker> getMarkers() {
|
public List<MapMarker> getMarkers() {
|
||||||
return markers;
|
return markers;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -393,27 +392,40 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
||||||
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||||
|
final MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
||||||
final GPXFile[] gpxFile = new GPXFile[1];
|
final GPXFile[] gpxFile = new GPXFile[1];
|
||||||
boolean disabled = !enabled;
|
boolean disabled = !enabled;
|
||||||
if (disabled && group.getType() == MapMarkersGroup.GPX_TYPE) {
|
boolean synced = false;
|
||||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getId());
|
|
||||||
|
mapMarkersHelper.updateGroupDisabled(group, disabled);
|
||||||
|
if (group.getType() == MapMarkersGroup.GPX_TYPE) {
|
||||||
|
group.setVisibleUntilRestart(disabled);
|
||||||
|
String gpxPath = group.getId();
|
||||||
|
if (disabled) {
|
||||||
|
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
|
||||||
if (selectedGpxFile != null) {
|
if (selectedGpxFile != null) {
|
||||||
gpxFile[0] = selectedGpxFile.getGpxFile();
|
gpxFile[0] = selectedGpxFile.getGpxFile();
|
||||||
switchGpxVisibility(gpxFile[0], false);
|
switchGpxVisibility(gpxFile[0], false);
|
||||||
}
|
}
|
||||||
|
} else if (mapMarkersHelper.isGroupSynced(group.getId())) {
|
||||||
|
mapMarkersHelper.runSynchronization(group, true);
|
||||||
|
synced = true;
|
||||||
}
|
}
|
||||||
app.getMapMarkersHelper().updateGroupDisabled(group, disabled);
|
}
|
||||||
app.getMapMarkersHelper().syncWithMarkers(group);
|
if (!synced) {
|
||||||
|
mapMarkersHelper.syncWithMarkers(group);
|
||||||
|
}
|
||||||
|
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_deleted), Snackbar.LENGTH_LONG)
|
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG)
|
||||||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
if (gpxFile[0] != null) {
|
if (group.getType() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
|
||||||
switchGpxVisibility(gpxFile[0], true);
|
switchGpxVisibility(gpxFile[0], true);
|
||||||
}
|
}
|
||||||
app.getMapMarkersHelper().updateGroupDisabled(group, false);
|
mapMarkersHelper.updateGroupDisabled(group, false);
|
||||||
app.getMapMarkersHelper().syncWithMarkers(group);
|
mapMarkersHelper.syncWithMarkers(group);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
|
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
|
||||||
|
|
Loading…
Reference in a new issue