Issue #6515 - QuickAction Show/hide selected gpx tracks - done
This commit is contained in:
parent
92b3e2142e
commit
5660f6fc33
6 changed files with 129 additions and 11 deletions
|
@ -10,11 +10,15 @@
|
|||
- For wording and consistency, please note https://osmand.net/help-online?id=technical-articles#Creating_a_Consistent_User_Experience
|
||||
Thx - Hardy
|
||||
-->
|
||||
<string name="quick_action_show_hide_gpx_tracks">Show/Hide GPX Tracks</string>
|
||||
<string name="quick_action_show_hide_gpx_tracks_descr">Tapping this action button shows or hides selected GPX tracks on map</string>
|
||||
<string name="quick_action_gpx_tracks_hide">Hide GPX Tracks</string>
|
||||
<string name="quick_action_gpx_tracks_show">Show GPX Tracks</string>
|
||||
<string name="add_destination_query">Please add Destination first</string>
|
||||
<string name="previous_route">Previous route</string>
|
||||
<string name="add_home">Add home</string>
|
||||
<string name="add_work">Add work</string>
|
||||
<string name="work_button">Work</string>
|
||||
<string name="add_home">Add home</string>
|
||||
<string name="add_work">Add work</string>
|
||||
<string name="work_button">Work</string>
|
||||
<string name="cubic_m">m³</string>
|
||||
<string name="metric_ton">t</string>
|
||||
<string name="shared_string_capacity">Сapacity</string>
|
||||
|
|
|
@ -59,6 +59,7 @@ public class GpxSelectionHelper {
|
|||
|
||||
public void restoreSelectedGpxFiles() {
|
||||
if (!selectedGpxFilesBackUp.isEmpty()) {
|
||||
selectedGPXFiles.clear();
|
||||
selectedGPXFiles.addAll(selectedGpxFilesBackUp);
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +72,6 @@ public class GpxSelectionHelper {
|
|||
return !selectedGPXFiles.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
@NonNull
|
||||
public List<SelectedGpxFile> getSelectedGPXFiles() {
|
||||
return selectedGPXFiles;
|
||||
|
|
|
@ -930,6 +930,12 @@ public class GpxUiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void loadFileInDifferentThread(final Activity activity,
|
||||
final CallbackWithObject<GPXFile[]> callbackWithObject, final File dir,
|
||||
final String... filename) {
|
||||
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, null, filename);
|
||||
}
|
||||
|
||||
private static void loadGPXFileInDifferentThread(final Activity activity, final CallbackWithObject<GPXFile[]> callbackWithObject,
|
||||
final File dir, final GPXFile currentFile, final String... filename) {
|
||||
final ProgressDialog dlg = ProgressDialog.show(activity, activity.getString(R.string.loading_smth, ""),
|
||||
|
|
|
@ -33,6 +33,7 @@ import net.osmand.plus.quickaction.actions.NavStartStopAction;
|
|||
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
||||
import net.osmand.plus.quickaction.actions.NewAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||
|
@ -102,6 +103,9 @@ public class QuickActionFactory {
|
|||
if (!favorites.hasInstanceInList(active)) {
|
||||
quickActions.add(favorites);
|
||||
}
|
||||
|
||||
quickActions.add(new ShowHideGpxTracksAction());
|
||||
|
||||
quickActions.add(new ShowHidePoiAction());
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
|
||||
|
@ -239,6 +243,9 @@ public class QuickActionFactory {
|
|||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction();
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return new ShowHideGpxTracksAction();
|
||||
|
||||
default:
|
||||
return new QuickAction();
|
||||
}
|
||||
|
@ -323,6 +330,9 @@ public class QuickActionFactory {
|
|||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction(quickAction);
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return new ShowHideGpxTracksAction(quickAction);
|
||||
|
||||
default:
|
||||
return quickAction;
|
||||
}
|
||||
|
@ -407,6 +417,9 @@ public class QuickActionFactory {
|
|||
case DayNightModeAction.TYPE:
|
||||
return R.drawable.ic_action_map_day;
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return R.drawable.ic_gpx_track;
|
||||
|
||||
default:
|
||||
return R.drawable.ic_action_plus;
|
||||
}
|
||||
|
@ -491,6 +504,9 @@ public class QuickActionFactory {
|
|||
case NavResumePauseAction.TYPE:
|
||||
return R.string.quick_action_resume_pause_navigation;
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return R.string.quick_action_show_hide_gpx_tracks;
|
||||
|
||||
default:
|
||||
return R.string.quick_action_new_action;
|
||||
}
|
||||
|
@ -517,6 +533,7 @@ public class QuickActionFactory {
|
|||
case NavStartStopAction.TYPE:
|
||||
case NavResumePauseAction.TYPE:
|
||||
case DayNightModeAction.TYPE:
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
|
||||
public class ShowHideGPXTracksAction extends QuickAction {
|
||||
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
package net.osmand.plus.quickaction.actions;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.quickaction.QuickAction;
|
||||
|
||||
public class ShowHideGpxTracksAction extends QuickAction {
|
||||
|
||||
public static final int TYPE = 28;
|
||||
|
||||
public ShowHideGpxTracksAction() {
|
||||
super(TYPE);
|
||||
}
|
||||
|
||||
public ShowHideGpxTracksAction(QuickAction quickAction) {
|
||||
super(quickAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final MapActivity activity) {
|
||||
final GpxSelectionHelper selectedGpxHelper = activity.getMyApplication()
|
||||
.getSelectedGpxHelper();
|
||||
if (selectedGpxHelper.isShowingAnyGpxFiles()) {
|
||||
selectedGpxHelper.clearAllGpxFileToShow();
|
||||
} else {
|
||||
selectedGpxHelper.restoreSelectedGpxFiles();
|
||||
|
||||
final OsmandSettings setting = activity.getMyApplication().getSettings();
|
||||
final File dir = activity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR);
|
||||
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
|
||||
@Override
|
||||
public boolean processResult(GPXFile[] result) {
|
||||
for (GPXFile g : result) {
|
||||
if (g.showCurrentTrack) {
|
||||
if (!setting.SAVE_TRACK_TO_GPX.get()
|
||||
&& !setting.SAVE_GLOBAL_TRACK_TO_GPX.get()) {
|
||||
Toast.makeText(activity,
|
||||
R.string.gpx_monitoring_disabled_warn, Toast.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
selectedGpxHelper.restoreSelectedGpxFiles();
|
||||
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = selectedGpxHelper
|
||||
.getSelectedGPXFiles();
|
||||
List<String> files = new ArrayList<>();
|
||||
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
|
||||
files.add(file.getGpxFile().path);
|
||||
}
|
||||
|
||||
GpxUiHelper.loadFileInDifferentThread(activity, callbackWithObject, dir,
|
||||
files.toArray(new String[files.size()]));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawUI(ViewGroup parent, MapActivity activity) {
|
||||
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.quick_action_with_text, parent, false);
|
||||
|
||||
((TextView) view.findViewById(R.id.text))
|
||||
.setText(R.string.quick_action_show_hide_gpx_tracks_descr);
|
||||
|
||||
parent.addView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionText(OsmandApplication application) {
|
||||
return application.getSelectedGpxHelper().isShowingAnyGpxFiles()
|
||||
? application.getString(R.string.quick_action_gpx_tracks_hide)
|
||||
: application.getString(R.string.quick_action_gpx_tracks_show);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActionWithSlash(OsmandApplication application) {
|
||||
return application.getSelectedGpxHelper().isShowingAnyGpxFiles();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue