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;
|
||||
}
|
||||
|
||||
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() {
|
||||
@Override
|
||||
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 MapMarkersGroup group;
|
||||
private boolean loadGpx;
|
||||
|
||||
SyncGroupTask(MapMarkersGroup group) {
|
||||
SyncGroupTask(MapMarkersGroup group, boolean loadGpx) {
|
||||
this.group = group;
|
||||
this.loadGpx = loadGpx;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1094,10 +1100,15 @@ public class MapMarkersHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(group.getId());
|
||||
String gpxPath = group.getId();
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
|
||||
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
||||
group.visible = gpx != null;
|
||||
if (!group.isVisible() || group.isDisabled()) {
|
||||
if (gpx == null && loadGpx) {
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
@ -1144,6 +1155,7 @@ public class MapMarkersHelper {
|
|||
private long creationDate;
|
||||
private boolean disabled;
|
||||
private boolean visible = true;
|
||||
private boolean visibleUntilRestart;
|
||||
private List<MapMarker> markers = new ArrayList<>();
|
||||
// TODO should be removed from this class:
|
||||
private GroupHeader header;
|
||||
|
@ -1187,6 +1199,10 @@ public class MapMarkersHelper {
|
|||
return visible;
|
||||
}
|
||||
|
||||
public void setVisibleUntilRestart(boolean visibleUntilRestart) {
|
||||
this.visibleUntilRestart = visibleUntilRestart;
|
||||
}
|
||||
|
||||
public List<MapMarker> getMarkers() {
|
||||
return markers;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import android.view.View;
|
|||
import android.view.ViewGroup;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -393,27 +392,40 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
|
||||
final MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
|
||||
final GPXFile[] gpxFile = new GPXFile[1];
|
||||
boolean disabled = !enabled;
|
||||
if (disabled && group.getType() == MapMarkersGroup.GPX_TYPE) {
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.getId());
|
||||
if (selectedGpxFile != null) {
|
||||
gpxFile[0] = selectedGpxFile.getGpxFile();
|
||||
switchGpxVisibility(gpxFile[0], false);
|
||||
boolean synced = false;
|
||||
|
||||
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) {
|
||||
gpxFile[0] = selectedGpxFile.getGpxFile();
|
||||
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) {
|
||||
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() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (gpxFile[0] != null) {
|
||||
if (group.getType() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
|
||||
switchGpxVisibility(gpxFile[0], true);
|
||||
}
|
||||
app.getMapMarkersHelper().updateGroupDisabled(group, false);
|
||||
app.getMapMarkersHelper().syncWithMarkers(group);
|
||||
mapMarkersHelper.updateGroupDisabled(group, false);
|
||||
mapMarkersHelper.syncWithMarkers(group);
|
||||
}
|
||||
});
|
||||
AndroidUtils.setSnackbarTextColor(snackbar, R.color.color_dialog_buttons_dark);
|
||||
|
|
Loading…
Reference in a new issue