Add to track

This commit is contained in:
Dima-1 2020-08-28 09:57:33 +03:00
parent 4f4b94e9f4
commit 189bb0ba4b
2 changed files with 47 additions and 14 deletions

View file

@ -865,7 +865,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
@Override @Override
public void selectFileOnCLick(String gpxFileName) { public void selectFileOnCLick(String gpxFileName) {
if (mapActivity != null) { if (mapActivity != null) {
GPXFile gpxFile = getGpxFile(gpxFileName); GPXFile gpxFile;
if (gpxFileName == null) {
gpxFile = mapActivity.getMyApplication().getSavingTrackHelper().getCurrentGpx();
} else {
gpxFile = getGpxFile(gpxFileName);
}
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper() SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper()
.getSelectedFileByPath(gpxFile.path); .getSelectedFileByPath(gpxFile.path);
boolean showOnMap = selectedGpxFile != null; boolean showOnMap = selectedGpxFile != null;
@ -1563,7 +1568,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
gpx.addRoutePoints(points); gpx.addRoutePoints(points);
} }
} }
Exception res = GPXUtilities.writeGpxFile(toSave, gpx); Exception res = null;
if (!gpx.showCurrentTrack) {
res = GPXUtilities.writeGpxFile(toSave, gpx);
}
savedGpxFile = gpx; savedGpxFile = gpx;
if (showOnMap) { if (showOnMap) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, true, false); SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, true, false);
@ -1633,9 +1641,11 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
} }
dismiss(mapActivity); dismiss(mapActivity);
} else { } else {
Toast.makeText(mapActivity, if (!savedGpxFile.showCurrentTrack) {
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), Toast.makeText(mapActivity,
Toast.LENGTH_LONG).show(); MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()),
Toast.LENGTH_LONG).show();
}
} }
} }
} else { } else {

View file

@ -63,6 +63,7 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment {
private SelectFileListener listener; private SelectFileListener listener;
private Map<String, List<GPXInfo>> gpxInfoMap; private Map<String, List<GPXInfo>> gpxInfoMap;
private Mode fragmentMode; private Mode fragmentMode;
private String selectedFolder;
public void setFragmentMode(Mode fragmentMode) { public void setFragmentMode(Mode fragmentMode) {
this.fragmentMode = fragmentMode; this.fragmentMode = fragmentMode;
@ -90,13 +91,19 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment {
final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); final File gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
collectDirs(gpxDir, dirs); collectDirs(gpxDir, dirs);
List<String> dirItems = new ArrayList<>(); List<String> dirItems = new ArrayList<>();
String allFilesFolder = context.getString(R.string.shared_string_all);
if (savedInstanceState == null) {
selectedFolder = allFilesFolder;
}
dirItems.add(allFilesFolder);
for (File dir : dirs) { for (File dir : dirs) {
dirItems.add(dir.getName()); dirItems.add(dir.getName());
} }
String allFilesFolder = context.getString(R.string.shared_string_all);
dirItems.add(0, allFilesFolder);
final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(gpxDir, null, false); final List<GPXInfo> allGpxList = getSortedGPXFilesInfo(gpxDir, null, false);
if (isShowCurrentGpx()) {
allGpxList.add(0, new GPXInfo(getString(R.string.shared_string_currently_recording_track), 0, 0));
}
gpxInfoMap = new HashMap<>(); gpxInfoMap = new HashMap<>();
gpxInfoMap.put(allFilesFolder, allGpxList); gpxInfoMap.put(allFilesFolder, allGpxList);
for (GPXInfo gpxInfo : allGpxList) { for (GPXInfo gpxInfo : allGpxList) {
@ -108,12 +115,18 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment {
} }
gpxList.add(gpxInfo); gpxList.add(gpxInfo);
} }
adapter = new GpxTrackAdapter(requireContext(), allGpxList, false);
adapter = new GpxTrackAdapter(requireContext(), allGpxList, isShowCurrentGpx());
adapter.setAdapterListener(new OnItemClickListener() { adapter.setAdapterListener(new OnItemClickListener() {
@Override @Override
public void onItemClick(int position) { public void onItemClick(int position) {
if (position != RecyclerView.NO_POSITION && position < allGpxList.size()) { if (position != RecyclerView.NO_POSITION && position < allGpxList.size()) {
String fileName = allGpxList.get(position).getFileName(); String fileName;
if (isShowCurrentGpx() && position == 0) {
fileName = null;
} else {
fileName = allGpxList.get(position).getFileName();
}
if (listener != null) { if (listener != null) {
listener.selectFileOnCLick(fileName); listener.selectFileOnCLick(fileName);
} }
@ -128,18 +141,28 @@ public class SelectFileBottomSheet extends MenuBottomSheetDialogFragment {
RecyclerView.HORIZONTAL, false)); RecyclerView.HORIZONTAL, false));
final HorizontalSelectionAdapter folderAdapter = new HorizontalSelectionAdapter(app, nightMode); final HorizontalSelectionAdapter folderAdapter = new HorizontalSelectionAdapter(app, nightMode);
folderAdapter.setItems(dirItems); folderAdapter.setItems(dirItems);
folderAdapter.setSelectedItem(allFilesFolder); folderAdapter.setSelectedItem(selectedFolder);
foldersRecyclerView.setAdapter(folderAdapter); foldersRecyclerView.setAdapter(folderAdapter);
folderAdapter.setListener(new HorizontalSelectionAdapterListener() { folderAdapter.setListener(new HorizontalSelectionAdapterListener() {
@Override @Override
public void onItemSelected(String item) { public void onItemSelected(String item) {
List<GPXInfo> gpxInfoList = gpxInfoMap.get(item); selectedFolder = item;
adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList<GPXInfo>()); updateFileList(item, folderAdapter);
adapter.notifyDataSetChanged();
folderAdapter.notifyDataSetChanged();
} }
}); });
items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create()); items.add(new BaseBottomSheetItem.Builder().setCustomView(mainView).create());
updateFileList(selectedFolder, folderAdapter);
}
private void updateFileList(String folderName, HorizontalSelectionAdapter folderAdapter) {
List<GPXInfo> gpxInfoList = gpxInfoMap.get(folderName);
adapter.setGpxInfoList(gpxInfoList != null ? gpxInfoList : new ArrayList<GPXInfo>());
adapter.notifyDataSetChanged();
folderAdapter.notifyDataSetChanged();
}
private boolean isShowCurrentGpx() {
return fragmentMode == Mode.ADD_TO_TRACK;
} }
private String getFolderName(GPXInfo gpxInfo) { private String getFolderName(GPXInfo gpxInfo) {