Skip to content

Commit

Permalink
Merge branch 'r4.9'
Browse files Browse the repository at this point in the history
# Conflicts:
#	OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt
#	OsmAnd/src/net/osmand/plus/plugins/odb/dialogs/OBDDevicesListFragment.kt
#	OsmAnd/src/net/osmand/plus/plugins/odb/dialogs/OBDMainFragment.kt
  • Loading branch information
Chumva committed Nov 18, 2024
2 parents e1e5850 + ef0c8be commit 5641b51
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 26 deletions.
32 changes: 8 additions & 24 deletions OsmAnd/src/net/osmand/plus/plugins/odb/VehicleMetricsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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
Expand Down Expand Up @@ -121,28 +122,11 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS
mapActivity: MapActivity, widgetsInfos: MutableList<MapWidgetInfo?>,
appMode: ApplicationMode) {
val creator = WidgetInfoCreator(app, appMode)
val speedWidget: MapWidget = createMapWidgetForParams(mapActivity, WidgetType.OBD_SPEED)
widgetsInfos.add(creator.createWidgetInfo(speedWidget))
val rpmWidget: MapWidget = createMapWidgetForParams(mapActivity, WidgetType.OBD_RPM)
widgetsInfos.add(creator.createWidgetInfo(rpmWidget))
val airIntakeTempWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_AIR_INTAKE_TEMP)
widgetsInfos.add(creator.createWidgetInfo(airIntakeTempWidget))
val ambientAirTempWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_AMBIENT_AIR_TEMP)
widgetsInfos.add(creator.createWidgetInfo(ambientAirTempWidget))
val batteryVoltageWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_BATTERY_VOLTAGE)
widgetsInfos.add(creator.createWidgetInfo(batteryVoltageWidget))
val remainingFuelWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_REMAINING_FUEL)
widgetsInfos.add(creator.createWidgetInfo(remainingFuelWidget))
val fuelConsumptionWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_FUEL_CONSUMPTION)
widgetsInfos.add(creator.createWidgetInfo(fuelConsumptionWidget))
val engineCoolantTempWidget: MapWidget =
createMapWidgetForParams(mapActivity, WidgetType.OBD_ENGINE_COOLANT_TEMP)
widgetsInfos.add(creator.createWidgetInfo(engineCoolantTempWidget))
for (widgetType in WidgetType.getObdTypes()) {
val obdWidget: MapWidget =
createMapWidgetForParams(mapActivity, widgetType)
widgetsInfos.add(creator.createWidgetInfo(obdWidget))
}
}

override fun createMapWidgetForParams(
Expand Down Expand Up @@ -324,7 +308,6 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS

@MainThread
fun disconnect(forgetCurrentDeviceConnected: Boolean) {
LOG.debug("disconnect $forgetCurrentDeviceConnected")
obdDispatcher?.stopReading()
val lastConnectedDeviceInfo = connectedDeviceInfo
connectedDeviceInfo = null
Expand Down Expand Up @@ -372,14 +355,14 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS
@SuppressLint("MissingPermission")
@MainThread
private fun connectToObdInternal(activity: Activity, deviceInfo: BTDeviceInfo) {
LOG.debug("connectToObd $deviceInfo reconnectCount $currentReconnectAttempt")
if (connectionState != OBDConnectionState.DISCONNECTED) {
disconnect(false)
}
currentReconnectAttempt--
if (currentReconnectAttempt <= 0) {
return
}
LOG.debug("connectToObd $deviceInfo reconnectCount $currentReconnectAttempt")
if (BLEUtils.isBLEEnabled(activity)) {
if (AndroidUtils.hasBLEPermission(activity)) {
onConnecting(deviceInfo)
Expand Down Expand Up @@ -452,6 +435,7 @@ class VehicleMetricsPlugin(app: OsmandApplication) : OsmandPlugin(app), OBDReadS
socket = connectedDevice.createRfcommSocketToServiceRecord(uuid)
}

@Throws(IOException::class)
override fun connect(): Pair<Source, Sink>? {
socket?.apply {
connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class OBDDevicesListFragment : OBDDevicesBaseFragment(),
}

override fun onDisconnect(device: BTDeviceInfo) {
vehicleMetricsPlugin?.disconnect(true)
vehicleMetricsPlugin.disconnect(true)
}

override fun onConnect(device: BTDeviceInfo) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class OBDMainFragment : OBDDevicesBaseFragment(), VehicleMetricsPlugin.Connectio
pairBtnTextColorId = connectedStateBtnTextColor
pairBtnTextId = R.string.external_device_details_disconnect
pairButton.setOnClickListener {
vehicleMetricsPlugin?.disconnect(true)
vehicleMetricsPlugin.disconnect(true)
}
}

Expand Down
11 changes: 11 additions & 0 deletions OsmAnd/src/net/osmand/plus/views/mapwidgets/WidgetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -472,4 +472,15 @@ public static String getDuplicateWidgetId(@NonNull WidgetType widgetType) {
public static String getDuplicateWidgetId(@NonNull String widgetId) {
return getDefaultWidgetId(widgetId) + DELIMITER + System.currentTimeMillis();
}

@NonNull
public static List<WidgetType> getObdTypes() {
List<WidgetType> obdWidgets = new ArrayList<>();
for (WidgetType widgetType : values()) {
if (VEHICLE_METRICS == widgetType.getGroup()) {
obdWidgets.add(widgetType);
}
}
return obdWidgets;
}
}

0 comments on commit 5641b51

Please sign in to comment.