use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class DashTrackFragment method setupGpxFiles.
private void setupGpxFiles() {
View mainView = getView();
final File dir = getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
final OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
final List<String> list = new ArrayList<String>();
for (SelectedGpxFile sg : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
if (!sg.isShowCurrentTrack()) {
GPXFile gpxFile = sg.getGpxFile();
if (gpxFile != null) {
list.add(gpxFile.path);
}
}
}
// 10 is the maximum length of the list. The actual length is determined later by
// DashboardOnMap.handleNumberOfRows()
int totalCount = 10;
if (app.getSettings().SAVE_GLOBAL_TRACK_TO_GPX.get()) {
totalCount--;
}
if (list.size() < totalCount) {
final List<GPXInfo> res = GpxUiHelper.getSortedGPXFilesInfoByDate(dir, true);
for (GPXInfo r : res) {
String name = r.getFileName();
if (!list.contains(name)) {
list.add(name);
if (list.size() >= totalCount) {
break;
}
}
}
}
if (list.size() == 0 && !OsmandPlugin.isActive(OsmandMonitoringPlugin.class)) {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.GONE);
return;
} else {
(mainView.findViewById(R.id.main_fav)).setVisibility(View.VISIBLE);
DashboardOnMap.handleNumberOfRows(list, getMyApplication().getSettings(), ROW_NUMBER_TAG);
}
LinearLayout tracks = (LinearLayout) mainView.findViewById(R.id.items);
tracks.removeAllViews();
LayoutInflater inflater = getActivity().getLayoutInflater();
if (OsmandPlugin.isActive(OsmandMonitoringPlugin.class)) {
View view = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
createCurrentTrackView(view);
((TextView) view.findViewById(R.id.name)).setText(R.string.shared_string_currently_recording_track);
updateCurrentTrack(view, getActivity(), app);
view.setOnClickListener(v -> openGpxContextMenu(null));
view.findViewById(R.id.divider_dash).setVisibility(View.VISIBLE);
tracks.addView(view);
startHandler(view);
}
for (String filename : list) {
File file = new File(filename);
AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
info.subfolder = "";
info.file = file;
View itemView = inflater.inflate(R.layout.dash_gpx_track_item, null, false);
AvailableGPXFragment.updateGpxInfoView(itemView, info, app, true, null);
itemView.setOnClickListener(v -> openGpxContextMenu(file));
ImageButton showOnMap = itemView.findViewById(R.id.show_on_map);
showOnMap.setVisibility(View.VISIBLE);
showOnMap.setContentDescription(getString(R.string.shared_string_show_on_map));
updateShowOnMap(app, file, itemView, showOnMap);
tracks.addView(itemView);
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class DashTrackFragment method updateShowOnMap.
private void updateShowOnMap(final OsmandApplication app, final File f, final View pView, final ImageButton showOnMap) {
final GpxSelectionHelper selectedGpxHelper = app.getSelectedGpxHelper();
final SelectedGpxFile selected = selectedGpxHelper.getSelectedFileByPath(f.getAbsolutePath());
if (selected != null) {
showOnMap.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_show_on_map, R.color.color_distance));
showOnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
selectedGpxHelper.selectGpxFile(selected.getGpxFile(), false, false);
AvailableGPXFragment.GpxInfo info = new AvailableGPXFragment.GpxInfo();
info.subfolder = "";
info.file = f;
AvailableGPXFragment.updateGpxInfoView(pView, info, app, true, null);
updateShowOnMap(app, f, v, showOnMap);
}
});
} else {
showOnMap.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_show_on_map));
showOnMap.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Runnable run = new Runnable() {
@Override
public void run() {
showOnMap(GPXUtilities.loadGPXFile(f));
}
};
run.run();
}
});
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class TrackAppearanceFragment method saveCustomColorsToTracks.
private void saveCustomColorsToTracks(int prevColor, int newColor) {
List<GpxDataItem> gpxDataItems = gpxDbHelper.getItems();
for (GpxDataItem dataItem : gpxDataItems) {
if (prevColor == dataItem.getColor()) {
gpxDbHelper.updateColor(dataItem, newColor);
}
}
List<SelectedGpxFile> files = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selectedGpxFile : files) {
if (prevColor == selectedGpxFile.getGpxFile().getColor(0)) {
selectedGpxFile.getGpxFile().setColor(newColor);
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class TrackDisplayHelper method updateDisplayGroups.
public void updateDisplayGroups() {
modifiedTime = gpxFile.modifiedTime;
GpxSelectionHelper selectedGpxHelper = app.getSelectedGpxHelper();
displayGroups = filteredGpxFile != null ? selectedGpxHelper.collectDisplayGroups(filteredGpxFile) : selectedGpxHelper.collectDisplayGroups(gpxFile);
originalGroups.clear();
for (GpxDisplayGroup g : displayGroups) {
originalGroups.add(g.cloneInstance());
}
if (file != null) {
SelectedGpxFile sf = selectedGpxHelper.getSelectedFileByPath(gpxFile.path);
if (sf != null && file != null && sf.getDisplayGroups(app) != null) {
displayGroups = sf.getDisplayGroups(app);
}
}
}
use of net.osmand.plus.track.helpers.GpxSelectionHelper.SelectedGpxFile in project Osmand by osmandapp.
the class TrackDisplayHelper method setJoinSegments.
public boolean setJoinSegments(boolean joinSegments) {
if (gpxDataItem != null) {
boolean updated = app.getGpxDbHelper().updateJoinSegments(gpxDataItem, joinSegments);
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
if (updated && selectedGpxFile != null) {
selectedGpxFile.setJoinSegments(joinSegments);
}
return updated;
}
return false;
}
Aggregations