Skip to content

Commit

Permalink
feat: Add WorkflowStatus enum for indicating current state of workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
tzebrowski committed Aug 26, 2023
1 parent 2cd1af2 commit 11cf417
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 17 deletions.
6 changes: 6 additions & 0 deletions automotive/src/main/java/org/obd/graphs/aa/CarScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ internal class CarScreen(
}

DATA_LOGGER_CONNECTING_EVENT -> {
surfaceController.renderFrame()
invalidate()
toast.show(carContext, R.string.main_activity_toast_connection_connecting)
}
Expand Down Expand Up @@ -146,6 +147,11 @@ internal class CarScreen(
invalidate()
}

DATA_LOGGER_STOPPING_EVENT -> {
surfaceController.renderFrame()
invalidate()
}

DATA_LOGGER_ERROR_CONNECT_EVENT -> {
invalidate()
toast.show(carContext, R.string.main_activity_toast_connection_connect_error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.obd.metrics.pid.PidDefinitionRegistry

interface DataLogger {
val eventsReceiver: BroadcastReceiver
fun status(): WorkflowStatus

fun observe(lifecycleOwner: LifecycleOwner, observer: (metric: ObdMetric) -> Unit)
fun isRunning(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ class DataLoggerService : JobIntentService(), DataLogger {
}
}

override fun status(): WorkflowStatus = workflowOrchestrator.status()

override fun scheduleStart(delay: Long) {
enqueueWork(SCHEDULED_ACTION_START) {
it.putExtra(SCHEDULED_START_DELAY, delay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ internal class WorkflowOrchestrator internal constructor() {

private var lifecycle = object : Lifecycle {
override fun onConnecting() {
status = WorkflowStatus.Connecting
Log.i(LOGGER_TAG, "Start collecting process")
sendBroadcastEvent(DATA_LOGGER_CONNECTING_EVENT)
}

override fun onRunning(vehicleCapabilities: VehicleCapabilities) {
status = WorkflowStatus.Connected
Log.i(LOGGER_TAG, "We are connected to the vehicle: $vehicleCapabilities")
vehicleCapabilitiesManager.updateCapabilities(vehicleCapabilities)
sendBroadcastEvent(DATA_LOGGER_CONNECTED_EVENT)
Expand All @@ -73,6 +75,7 @@ internal class WorkflowOrchestrator internal constructor() {
}

override fun onStopped() {
status = WorkflowStatus.Disconnected
Log.i(
LOGGER_TAG,
"Collecting process is completed."
Expand All @@ -81,12 +84,14 @@ internal class WorkflowOrchestrator internal constructor() {
}

override fun onStopping() {
status = WorkflowStatus.Stopping
Log.i(LOGGER_TAG, "Stopping collecting process...")
sendBroadcastEvent(DATA_LOGGER_STOPPING_EVENT)
}
}

private var workflow: Workflow = workflow()
private var status = WorkflowStatus.Disconnected

fun observe(lifecycleOwner: LifecycleOwner, observer: (metric: ObdMetric) -> Unit) =
metricsObserver.observe(lifecycleOwner){
Expand All @@ -95,6 +100,7 @@ internal class WorkflowOrchestrator internal constructor() {
}
}

fun status(): WorkflowStatus = status

fun isRunning(): Boolean = workflow.isRunning

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.obd.graphs.bl.datalogger

enum class WorkflowStatus {
Connected, Disconnected, Connecting, Stopping
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.graphics.*
import org.obd.graphs.bl.collector.CarMetric
import org.obd.graphs.ValueScaler
import org.obd.graphs.bl.datalogger.WorkflowStatus
import org.obd.graphs.bl.datalogger.dataLogger
import org.obd.graphs.commons.R
import org.obd.graphs.preferences.Prefs
Expand All @@ -30,8 +31,6 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
BitmapFactory.decodeResource(context.resources, R.drawable.background)

private val statusLabel: String
private val statusConnected: String
private val statusDisconnected: String
private val profileLabel: String
private val fpsLabel: String

Expand All @@ -55,8 +54,6 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
profileLabel = context.resources.getString(R.string.status_bar_profile)
fpsLabel = context.resources.getString(R.string.status_bar_fps)
statusLabel = context.resources.getString(R.string.status_bar_status)
statusConnected = context.resources.getString(R.string.status_bar_connected)
statusDisconnected = context.resources.getString(R.string.status_bar_disconnected)
}

fun updateCanvas(canvas: Canvas) {
Expand Down Expand Up @@ -149,7 +146,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
text,
horizontalAlignment,
statusVerticalPos,
Color.WHITE,
Color.LTGRAY,
12f,
statusPaint
)
Expand All @@ -158,12 +155,16 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet

val color: Int
val colorTheme = settings.colorTheme()
if (dataLogger.isRunning()) {
text = statusConnected
color = colorTheme.statusConnectedColor
} else {
text = statusDisconnected
color = colorTheme.statusDisconnectedColor
text = dataLogger.status().name.lowercase()

color = when (dataLogger.status()) {
WorkflowStatus.Disconnected -> colorTheme.statusDisconnectedColor

WorkflowStatus.Stopping -> colorTheme.statusDisconnectedColor

WorkflowStatus.Connecting -> colorTheme.statusConnectingColor

WorkflowStatus.Connected -> colorTheme.statusConnectedColor
}

drawText(
Expand All @@ -182,7 +183,7 @@ internal class DrawingManager(context: Context, private val settings: ScreenSet
text,
horizontalAlignment,
statusVerticalPos,
Color.WHITE,
Color.LTGRAY,
12f,
statusPaint
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ enum class DynamicSelectorMode {

data class ColorTheme(val dividerColor: Int = Color.WHITE,
var progressColor: Int = COLOR_CARDINAL,
val statusConnectingColor: Int = Color.YELLOW,
val statusConnectedColor: Int = Color.GREEN,
val statusDisconnectedColor: Int = Color.YELLOW,
val statusDisconnectedColor: Int = COLOR_DYNAMIC_SELECTOR_SPORT,
val currentValueColor: Int = Color.WHITE,
val currentValueInAlertColor: Int = COLOR_DYNAMIC_SELECTOR_SPORT,
val currentProfileColor: Int = Color.YELLOW,
val currentProfileColor: Int = Color.WHITE,
val actionsBtnConnectColor: Int = Color.GREEN,
val actionsBtnDisconnectColor: Int = Color.RED,
val actionsBtnVirtualScreensColor: Int = Color.YELLOW)
val actionsBtnVirtualScreensColor: Int = Color.WHITE)

interface ScreenSettings {

Expand Down
2 changes: 0 additions & 2 deletions giulia_renderer/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@
<string name="status_bar.status">status: </string>
<string name="status_bar.profile">profile: </string>
<string name="status_bar.fps">fps: </string>
<string name="status_bar.connected">connected</string>
<string name="status_bar.disconnected">disconnected</string>
</resources>

0 comments on commit 11cf417

Please sign in to comment.