diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 69d353ed634..363501d54b3 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -88,6 +88,7 @@ import net.osmand.plus.measurementtool.MeasurementEditingContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; +import net.osmand.plus.plugins.OsmandPlugin; import net.osmand.plus.plugins.PluginsHelper; import net.osmand.plus.plugins.accessibility.MapAccessibilityActions; import net.osmand.plus.render.UpdateVectorRendererAsyncTask; @@ -1537,6 +1538,9 @@ public void newRouteIsCalculated(boolean newRoute, ValueHolder showToas sim.startStopRouteAnimation(this); } } + for (OsmandPlugin plugin: PluginsHelper.getEnabledPlugins()) { + plugin.newRouteIsCalculated(newRoute); + } } private void fitCurrentRouteToMap() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/SearchMyPlacesTracksFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/tracks/SearchMyPlacesTracksFragment.java index 19ddf3ffb10..788a14ed657 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/SearchMyPlacesTracksFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/SearchMyPlacesTracksFragment.java @@ -96,7 +96,7 @@ protected SearchTracksAdapter createAdapter(@NonNull Context context, List> filterSpecificSearchResults = new HashMap<>(); @Nullable private TrackFolder currentFolder; + @Nullable + private List initialSelectedFilters; private OsmandApplication app; + public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List trackItems, @Nullable List initialSelectedFilters) { + this(app, trackItems, null, initialSelectedFilters); + } + public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List trackItems) { - this(app, trackItems, null); + this(app, trackItems, null, null); } - public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List trackItems, @Nullable TrackFolder currentFolder) { + public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List trackItems, @Nullable TrackFolder currentFolder, @Nullable List initialSelectedFilters) { this.app = app; this.trackItems = trackItems; this.currentFolder = currentFolder; + this.initialSelectedFilters = initialSelectedFilters; initFilters(app); } @@ -73,12 +80,10 @@ protected Void doInBackground(Void... voids) { dateFilter.setValueFrom(minDate); dateFilter.setValueTo(now); } - for (TrackFilterType trackFilterType : TrackFilterType.values()) { + for (TrackFilterType trackFilterType : TrackFilterType.getEntries()) { switch (trackFilterType.getFilterType()) { - case RANGE: - updateRangeFilterMaxValue(trackFilterType); - break; - case SINGLE_FIELD_LIST: + case RANGE -> updateRangeFilterMaxValue(trackFilterType); + case SINGLE_FIELD_LIST -> { ListTrackFilter filter = (ListTrackFilter) getFilterByType(trackFilterType); if (filter != null) { SingleFieldTrackFilterParams filterParams = (SingleFieldTrackFilterParams) trackFilterType.getAdditionalData(); @@ -95,9 +100,12 @@ protected Void doInBackground(Void... voids) { } } } - break; - default: - break; + } + default -> { + } + } + if (initialSelectedFilters != null) { + fillFiltersWithValues(initialSelectedFilters); } } return null; @@ -261,11 +269,15 @@ void recreateFilters() { public void initSelectedFilters(@Nullable List selectedFilters) { if (selectedFilters != null) { initFilters(app); - for (BaseTrackFilter filter : getCurrentFilters()) { - for (BaseTrackFilter selectedFilter : selectedFilters) { - if (filter.getTrackFilterType() == selectedFilter.getTrackFilterType()) { - filter.initWithValue(selectedFilter); - } + fillFiltersWithValues(selectedFilters); + } + } + + private void fillFiltersWithValues(@NonNull List selectedFilters) { + for (BaseTrackFilter filter : getCurrentFilters()) { + for (BaseTrackFilter selectedFilter : selectedFilters) { + if (filter.getTrackFilterType() == selectedFilter.getTrackFilterType()) { + filter.initWithValue(selectedFilter); } } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsController.kt b/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsController.kt index 3fff28b137a..6c4040c0c6f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsController.kt +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsController.kt @@ -139,7 +139,7 @@ class SmartFolderOptionsController( private fun showEditFiltersDialog(folder: SmartFolder) { dialogManager.askDismissDialog(PROCESS_ID) - optionsListener?.showEditFiltersDialog(folder) + optionsListener?.showEditFiltersDialog(folder, null) } private fun showExportDialog(folder: SmartFolder) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsListener.java b/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsListener.java index 79873b13864..9835e4f9d74 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsListener.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/controller/SmartFolderOptionsListener.java @@ -1,7 +1,9 @@ package net.osmand.plus.myplaces.tracks.controller; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import net.osmand.plus.myplaces.tracks.DialogClosedListener; import net.osmand.shared.gpx.data.SmartFolder; public interface SmartFolderOptionsListener { @@ -14,6 +16,6 @@ default void showSmartFolderTracksOnMap(@NonNull SmartFolder folder) { default void showExportDialog(@NonNull SmartFolder folder) { } - default void showEditFiltersDialog(@NonNull SmartFolder trackFolder) { + default void showEditFiltersDialog(@NonNull SmartFolder trackFolder, @Nullable DialogClosedListener dialogClosedListener) { } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/BaseTrackFolderFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/BaseTrackFolderFragment.java index b96ac453ba1..86ca7e61dfd 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/BaseTrackFolderFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/BaseTrackFolderFragment.java @@ -34,6 +34,7 @@ import androidx.recyclerview.widget.RecyclerView.ViewHolder; import net.osmand.IndexConstants; +import net.osmand.plus.myplaces.tracks.DialogClosedListener; import net.osmand.plus.shared.SharedUtil; import net.osmand.data.LatLon; import net.osmand.plus.R; @@ -578,13 +579,12 @@ public void showChangeAppearanceDialog(@NonNull TrackFolder folder) { } @Override - public void showEditFiltersDialog(@NonNull SmartFolder folder) { + public void showEditFiltersDialog(@NonNull SmartFolder folder, @Nullable DialogClosedListener dialogClosedListener) { FragmentManager manager = getFragmentManager(); ArrayList trackItems = new ArrayList<>(smartFolderHelper.getAllAvailableTrackItems()); - TracksSearchFilter filter = new TracksSearchFilter(app, trackItems); - filter.initSelectedFilters(folder.getFilters()); + TracksSearchFilter filter = new TracksSearchFilter(app, trackItems, folder.getFilters()); if (manager != null) { - TracksFilterFragment.Companion.showInstance(app, manager, this, filter, null, folder, null); + TracksFilterFragment.Companion.showInstance(app, manager, this, filter, dialogClosedListener, folder, null); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/SmartFolderFragment.kt b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/SmartFolderFragment.kt index 85abcaa70bb..fefe5aa8ae9 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/SmartFolderFragment.kt +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/SmartFolderFragment.kt @@ -4,18 +4,16 @@ import android.view.View import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import net.osmand.plus.R -import net.osmand.shared.gpx.TrackItem import net.osmand.plus.myplaces.tracks.DialogClosedListener import net.osmand.plus.myplaces.tracks.EmptySmartFolderListener -import net.osmand.plus.myplaces.tracks.TracksSearchFilter -import net.osmand.plus.myplaces.tracks.dialogs.TracksFilterFragment.Companion.showInstance -import net.osmand.shared.gpx.SmartFolderUpdateListener -import net.osmand.shared.gpx.data.SmartFolder -import net.osmand.shared.gpx.data.TracksGroup import net.osmand.plus.utils.AndroidUtils import net.osmand.plus.widgets.popup.PopUpMenu import net.osmand.plus.widgets.popup.PopUpMenuDisplayData import net.osmand.plus.widgets.popup.PopUpMenuItem +import net.osmand.shared.gpx.SmartFolderUpdateListener +import net.osmand.shared.gpx.TrackItem +import net.osmand.shared.gpx.data.SmartFolder +import net.osmand.shared.gpx.data.TracksGroup class SmartFolderFragment : TrackFolderFragment(), SmartFolderUpdateListener, EmptySmartFolderListener, @@ -148,14 +146,7 @@ class SmartFolderFragment : TrackFolderFragment(), SmartFolderUpdateListener, override fun editFilters() { if (smartFolder != null) { - val manager = fragmentManager - val trackItems = ArrayList() - trackItems.addAll(smartFolderHelper.getAllAvailableTrackItems()) - val filter = TracksSearchFilter(app, trackItems) - filter.initSelectedFilters(smartFolder.filters) - if (manager != null) { - targetFragment?.let { showInstance(app, manager, it, filter, this, smartFolder, null) } - } + showEditFiltersDialog(smartFolder, this) } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/TracksFilterFragment.kt b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/TracksFilterFragment.kt index cfe4d3779b0..b9d4716163b 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/TracksFilterFragment.kt +++ b/OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/TracksFilterFragment.kt @@ -27,16 +27,18 @@ import net.osmand.plus.myplaces.tracks.DialogClosedListener import net.osmand.plus.myplaces.tracks.SearchMyPlacesTracksFragment import net.osmand.plus.myplaces.tracks.TracksSearchFilter import net.osmand.plus.myplaces.tracks.filters.FiltersAdapter -import net.osmand.shared.gpx.SmartFolderHelper -import net.osmand.shared.gpx.SmartFolderUpdateListener -import net.osmand.shared.gpx.data.TrackFolder import net.osmand.plus.utils.AndroidUtils import net.osmand.plus.utils.ColorUtilities.getStatusBarSecondaryColor import net.osmand.plus.widgets.dialogbutton.DialogButton +import net.osmand.shared.gpx.SmartFolderHelper +import net.osmand.shared.gpx.SmartFolderUpdateListener +import net.osmand.shared.gpx.TrackItem +import net.osmand.shared.gpx.data.SmartFolder +import net.osmand.shared.gpx.data.TrackFolder import net.osmand.shared.gpx.filters.BaseTrackFilter +import net.osmand.shared.gpx.filters.DateTrackFilter import net.osmand.shared.gpx.filters.FilterChangedListener -import net.osmand.shared.gpx.data.SmartFolder -import net.osmand.shared.gpx.TrackItem +import net.osmand.shared.gpx.filters.TrackFilterType import net.osmand.util.Algorithms class TracksFilterFragment : BaseOsmAndDialogFragment(), @@ -56,8 +58,7 @@ class TracksFilterFragment : BaseOsmAndDialogFragment(), (foundFragment as TracksFilterFragment).dialog?.dismiss() } if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) { - val initialFilter = TracksSearchFilter(app, arrayListOf()) - initialFilter.initSelectedFilters(filter.appliedFilters) + val initialFilter = TracksSearchFilter(app, arrayListOf(), filter.appliedFilters) val fragment = TracksFilterFragment() fragment.setTargetFragment(target, 0) fragment.initialFilterState = initialFilter diff --git a/OsmAnd/src/net/osmand/plus/plugins/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/plugins/OsmandPlugin.java index c65dc75a9d2..6e948e04b7a 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/plugins/OsmandPlugin.java @@ -566,4 +566,7 @@ public boolean isMapPositionIconNeeded() { public void onCarNavigationSessionCreated() { } + + public void newRouteIsCalculated(boolean newRoute) { + } } diff --git a/OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt b/OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt index f55a741afb2..a434c6a5d3a 100644 --- a/OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt +++ b/OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt @@ -66,14 +66,14 @@ import okio.sink import okio.source import org.json.JSONObject import java.util.UUID -import kotlin.jvm.Throws class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadStatusListener { private var mapActivity: MapActivity? = null private val handler = Handler(Looper.getMainLooper()) private val RECONNECT_DELAY = 5000L - private val RECONNECT_ATTEMPTS_COUNT = 10 + private val RECONNECT_ATTEMPTS_COUNT = 3 + private val RECALCULATE_RECONNECT_ATTEMPTS_COUNT = 1 private var currentReconnectAttempt = 0 private var connectionState = OBDConnectionState.DISCONNECTED @@ -359,7 +359,7 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS disconnect(false) } currentReconnectAttempt-- - if (currentReconnectAttempt <= 0) { + if (currentReconnectAttempt < 0) { return } LOG.debug("connectToObd $deviceInfo reconnectCount $currentReconnectAttempt") @@ -708,9 +708,16 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS override fun mapActivityCreate(activity: MapActivity) { super.mapActivityCreate(activity) + connectToLastConnectedDevice(activity, RECONNECT_ATTEMPTS_COUNT) + } + + private fun connectToLastConnectedDevice(activity: MapActivity, attemptsCount: Int) { val lastConnectedDevice = getLastConnectedDevice() - if (connectedDeviceInfo == null && lastConnectedDevice != null) { - connectToObd(activity, lastConnectedDevice) + val registry = app.osmandMap.mapLayers.mapWidgetRegistry + if (connectedDeviceInfo == null && lastConnectedDevice != null && registry.allWidgets.any { + it.widget is OBDTextWidget && it.isEnabledForAppMode(app.settings.applicationMode)}) { + currentReconnectAttempt = attemptsCount + connectToObdInternal(activity, lastConnectedDevice) } } @@ -946,4 +953,10 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS connectToObd(activity, lastConnectedDevice) } } + + override fun newRouteIsCalculated(newRoute: Boolean) { + mapActivity?.let { + connectToLastConnectedDevice(it, RECALCULATE_RECONNECT_ATTEMPTS_COUNT) + } + } } \ No newline at end of file