Skip to content

Commit

Permalink
Merge branch 'r4.9'
Browse files Browse the repository at this point in the history
  • Loading branch information
Chumva committed Nov 21, 2024
2 parents d1bb16e + 9359242 commit cc74459
Show file tree
Hide file tree
Showing 10 changed files with 74 additions and 48 deletions.
4 changes: 4 additions & 0 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1537,6 +1538,9 @@ public void newRouteIsCalculated(boolean newRoute, ValueHolder<Boolean> showToas
sim.startStopRouteAnimation(this);
}
}
for (OsmandPlugin plugin: PluginsHelper.getEnabledPlugins()) {
plugin.newRouteIsCalculated(newRoute);
}
}

private void fitCurrentRouteToMap() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected SearchTracksAdapter createAdapter(@NonNull Context context, List<Track
if (externalFilter != null) {
return new SearchTracksAdapter(app, trackItems, nightMode, selectionMode, externalFilter);
} else {
TracksSearchFilter filter = new TracksSearchFilter(app, trackItems, currentFolder);
TracksSearchFilter filter = new TracksSearchFilter(app, trackItems, currentFolder, null);
return new SearchTracksAdapter(app, trackItems, nightMode, selectionMode, filter);
}
}
Expand Down
42 changes: 27 additions & 15 deletions OsmAnd/src/net/osmand/plus/myplaces/tracks/TracksSearchFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,24 @@ public class TracksSearchFilter extends Filter implements FilterChangedListener
private Map<TrackFilterType, List<TrackItem>> filterSpecificSearchResults = new HashMap<>();
@Nullable
private TrackFolder currentFolder;
@Nullable
private List<BaseTrackFilter> initialSelectedFilters;

private OsmandApplication app;

public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List<TrackItem> trackItems, @Nullable List<BaseTrackFilter> initialSelectedFilters) {
this(app, trackItems, null, initialSelectedFilters);
}

public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List<TrackItem> trackItems) {
this(app, trackItems, null);
this(app, trackItems, null, null);
}

public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List<TrackItem> trackItems, @Nullable TrackFolder currentFolder) {
public TracksSearchFilter(@NonNull OsmandApplication app, @NonNull List<TrackItem> trackItems, @Nullable TrackFolder currentFolder, @Nullable List<BaseTrackFilter> initialSelectedFilters) {
this.app = app;
this.trackItems = trackItems;
this.currentFolder = currentFolder;
this.initialSelectedFilters = initialSelectedFilters;
initFilters(app);
}

Expand All @@ -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();
Expand All @@ -95,9 +100,12 @@ protected Void doInBackground(Void... voids) {
}
}
}
break;
default:
break;
}
default -> {
}
}
if (initialSelectedFilters != null) {
fillFiltersWithValues(initialSelectedFilters);
}
}
return null;
Expand Down Expand Up @@ -261,11 +269,15 @@ void recreateFilters() {
public void initSelectedFilters(@Nullable List<BaseTrackFilter> 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<BaseTrackFilter> selectedFilters) {
for (BaseTrackFilter filter : getCurrentFilters()) {
for (BaseTrackFilter selectedFilter : selectedFilters) {
if (filter.getTrackFilterType() == selectedFilter.getTrackFilterType()) {
filter.initWithValue(selectedFilter);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<TrackItem> 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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -148,14 +146,7 @@ class SmartFolderFragment : TrackFolderFragment(), SmartFolderUpdateListener,

override fun editFilters() {
if (smartFolder != null) {
val manager = fragmentManager
val trackItems = ArrayList<TrackItem>()
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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions OsmAnd/src/net/osmand/plus/plugins/OsmandPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -566,4 +566,7 @@ public boolean isMapPositionIconNeeded() {
public void onCarNavigationSessionCreated() {

}

public void newRouteIsCalculated(boolean newRoute) {
}
}
23 changes: 18 additions & 5 deletions OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
}

0 comments on commit cc74459

Please sign in to comment.