Select gpx file on creating group
This commit is contained in:
parent
00f2f4b143
commit
5818d2369a
2 changed files with 51 additions and 7 deletions
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
|
@ -8,6 +9,7 @@ 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;
|
||||
|
@ -23,6 +25,7 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
protected View mainView;
|
||||
protected GroupsAdapter adapter;
|
||||
protected MapMarkersHelper mapMarkersHelper;
|
||||
private CreateGpxGroupTask createGpxGroupTask;
|
||||
|
||||
public void setListener(AddGroupListener listener) {
|
||||
this.listener = listener;
|
||||
|
@ -50,13 +53,8 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
if (position == RecyclerView.NO_POSITION) {
|
||||
return;
|
||||
}
|
||||
MarkersSyncGroup group = createMapMarkersSyncGroup(position);
|
||||
mapMarkersHelper.addMarkersSyncGroup(group);
|
||||
mapMarkersHelper.syncGroup(group);
|
||||
if (listener != null) {
|
||||
listener.onGroupAdded();
|
||||
}
|
||||
dismiss();
|
||||
createGpxGroupTask = new CreateGpxGroupTask();
|
||||
createGpxGroupTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, position);
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
@ -73,6 +71,15 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
if (createGpxGroupTask != null) {
|
||||
createGpxGroupTask.cancel(true);
|
||||
createGpxGroupTask = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void createAdapter();
|
||||
|
||||
protected abstract MarkersSyncGroup createMapMarkersSyncGroup(int position);
|
||||
|
@ -80,4 +87,32 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
|
|||
public interface AddGroupListener {
|
||||
void onGroupAdded();
|
||||
}
|
||||
|
||||
public class CreateGpxGroupTask extends AsyncTask<Integer, Void, MarkersSyncGroup> {
|
||||
|
||||
private ProgressBar progressBar = (ProgressBar) mainView.findViewById(R.id.progress_bar);;
|
||||
private RecyclerView recyclerView = (RecyclerView) mainView.findViewById(R.id.groups_recycler_view);
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
progressBar.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MarkersSyncGroup doInBackground(Integer... integers) {
|
||||
return createMapMarkersSyncGroup(integers[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(MarkersSyncGroup group) {
|
||||
createGpxGroupTask = null;
|
||||
mapMarkersHelper.addMarkersSyncGroup(group);
|
||||
mapMarkersHelper.syncGroup(group);
|
||||
if (listener != null) {
|
||||
listener.onGroupAdded();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,8 @@ import net.osmand.plus.GPXDatabase.GpxDataItem;
|
|||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.MapMarkersHelper.MarkersSyncGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -30,10 +32,12 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
|
||||
private ProcessGpxTask asyncProcessor;
|
||||
private List<GpxDataItem> gpxList = new ArrayList<>();
|
||||
private GpxSelectionHelper gpxSelectionHelper;
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
gpxSelectionHelper = getMyApplication().getSelectedGpxHelper();
|
||||
asyncProcessor = new ProcessGpxTask();
|
||||
asyncProcessor.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
@ -47,6 +51,11 @@ public class AddTracksGroupBottomSheetDialogFragment extends AddGroupBottomSheet
|
|||
public MarkersSyncGroup createMapMarkersSyncGroup(int position) {
|
||||
GpxDataItem gpxDataItem = gpxList.get(position - 1);
|
||||
File gpx = gpxDataItem.getFile();
|
||||
SelectedGpxFile selectedGpxFile = gpxSelectionHelper.getSelectedFileByPath(gpx.getAbsolutePath());
|
||||
if (selectedGpxFile == null) {
|
||||
GPXFile res = GPXUtilities.loadGPXFile(getContext(), gpx);
|
||||
gpxSelectionHelper.selectGpxFile(res, true, false);
|
||||
}
|
||||
return new MarkersSyncGroup(gpx.getAbsolutePath(), AndroidUtils.trimExtension(gpx.getName()), MarkersSyncGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue