Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ android {
resValue "string", "DEFAULT_PROFILE", "profile_8"
resValue "string", "applicationId", "org.obd.graphs.my.giulia.aa"
applicationId "org.obd.graphs.my.giulia.aa"
versionCode 221
versionCode 222
}

giuliaPerformanceMonitor {
dimension "version"
resValue "string", "DEFAULT_PROFILE", "profile_8"
resValue "string", "applicationId", "org.obd.graphs.my.giulia.performance_monitor"
applicationId "org.obd.graphs.my.giulia.performance_monitor"
versionCode 102
versionCode 103
}

giulia {
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/obd/graphs/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class MainActivity :
AppCompatActivity(),
EasyPermissions.PermissionCallbacks {

internal lateinit var statusPanel: StatusPanel
internal val screenLockManager = ScreenLockManager(this)
internal lateinit var backupManager: BackupManager

Expand Down Expand Up @@ -142,6 +143,11 @@ class MainActivity :
isAppReady = true
}

private fun setupStatusPanel() {
statusPanel = StatusPanel(this)
statusPanel.setup()
}

private fun setupFabButtons() {
FabButtons.setupSpeedDialView(this)

Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/org/obd/graphs/activity/Receivers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ internal fun MainActivity.receive(intent: Intent?) {
TOOLBAR_SHOW -> Toolbar.hide(this, false)
TOOLBAR_TOGGLE_ACTION -> Toolbar.toggle(this)

PROFILE_NAME_CHANGED_EVENT -> updateVehicleProfile()
PROFILE_NAME_CHANGED_EVENT -> statusPanel.updateVehicleProfile()

PROFILE_CHANGED_EVENT -> {
updateVehicleProfile()
updateAdapterConnectionType()
statusPanel.updateVehicleProfile()
statusPanel.updateAdapterConnectionType()

toggleNavigationItem(GIULIA_VIEW_ID, R.id.nav_giulia)
toggleNavigationItem(GRAPH_VIEW_ID, R.id.nav_graph)
Expand Down Expand Up @@ -276,7 +276,7 @@ internal fun MainActivity.receive(intent: Intent?) {
}
}

PREFS_CONNECTION_TYPE_CHANGED_EVENT -> updateAdapterConnectionType()
PREFS_CONNECTION_TYPE_CHANGED_EVENT -> statusPanel.updateAdapterConnectionType()

DATA_LOGGER_NO_NETWORK_EVENT -> {
toast(org.obd.graphs.commons.R.string.main_activity_toast_connection_no_network)
Expand All @@ -301,7 +301,7 @@ internal fun MainActivity.receive(intent: Intent?) {
}

Toolbar.hide(this, true)
updateAdapterConnectionType()
statusPanel.updateAdapterConnectionType()
}

DATA_LOGGER_STOPPED_EVENT -> {
Expand All @@ -314,13 +314,13 @@ internal fun MainActivity.receive(intent: Intent?) {
handleStop()
}

EVENT_VEHICLE_STATUS_VEHICLE_RUNNING -> updateVehicleStatus("Running")
EVENT_VEHICLE_STATUS_VEHICLE_IDLING -> updateVehicleStatus("Idling")
EVENT_VEHICLE_STATUS_IGNITION_ON -> updateVehicleStatus("Key on")
EVENT_VEHICLE_STATUS_CHANGED -> updateVehicleStatus("")
EVENT_VEHICLE_STATUS_VEHICLE_RUNNING -> statusPanel.updateVehicleStatus("Running")
EVENT_VEHICLE_STATUS_VEHICLE_IDLING -> statusPanel.updateVehicleStatus("Idling")
EVENT_VEHICLE_STATUS_IGNITION_ON -> statusPanel.updateVehicleStatus("Key on")
EVENT_VEHICLE_STATUS_CHANGED -> statusPanel.updateVehicleStatus("")

EVENT_VEHICLE_STATUS_IGNITION_OFF -> {
updateVehicleStatus("Key off")
statusPanel.updateVehicleStatus("Key off")
if (dataLoggerSettings.instance().vehicleStatusDisconnectWhenOff) {
Log.i(LOG_TAG, "Received vehicle status OFF event. Closing the session.")
withDataLogger {
Expand Down
123 changes: 64 additions & 59 deletions app/src/main/java/org/obd/graphs/activity/StatusPanel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package org.obd.graphs.activity

import android.annotation.SuppressLint
import android.graphics.Color
import android.widget.ImageView
import android.widget.TextView
Expand All @@ -27,77 +26,83 @@ import org.obd.graphs.profile.profile
import org.obd.graphs.sendBroadcastEvent
import org.obd.graphs.ui.common.*


internal fun MainActivity.updateVehicleStatus(status: String) {

updateTextField(
R.id.vehicle_status,
resources.getString(R.string.status_panel_vehicle_status),
status,
COLOR_CARDINAL,
1.0f
){
it.isGone = !dataLoggerSettings.instance().vehicleStatusPanelEnabled
class StatusPanel(private val activity: MainActivity) {
companion object {
private const val MAX_PROFILE_NAME_LENGTH = 15
private const val TEXT_SIZE_PRIMARY = 1.0f
private const val TEXT_SIZE_SECONDARY = 0.7f
}
}

internal fun MainActivity.updateAdapterConnectionType() {
updateTextField(
R.id.connection_status,
resources.getString(R.string.status_panel_adapter_connection_type),
dataLoggerSettings.instance().adapter.connectionType,
COLOR_PHILIPPINE_GREEN,
1.0f
)
}

internal fun MainActivity.setupStatusPanel() {
updateAdapterConnectionType()
updateVehicleProfile()
updateVehicleStatus("")
fun setup() {
updateAdapterConnectionType()
updateVehicleProfile()
updateVehicleStatus("")

(findViewById<TextView>(R.id.connection_status)).let {
it.setOnClickListener {
activity.findViewById<TextView>(R.id.connection_status)?.setOnClickListener {
navigateToPreferencesScreen("pref.adapter.connection")
}
}

(findViewById<TextView>(R.id.vehicle_profile)).let {
it.setOnClickListener {
activity.findViewById<TextView>(R.id.vehicle_profile)?.setOnClickListener {
navigateToPreferencesScreen("pref.profiles")
}

activity.findViewById<ImageView>(R.id.toggle_fullscreen)?.setOnClickListener {
sendBroadcastEvent(TOOLBAR_TOGGLE_ACTION)
}
}

(findViewById<ImageView>(R.id.toggle_fullscreen)).let {
it.setOnClickListener {
sendBroadcastEvent(TOOLBAR_TOGGLE_ACTION)
fun updateVehicleStatus(status: String) {
updateTextField(
R.id.vehicle_status,
activity.getString(R.string.status_panel_vehicle_status),
status,
COLOR_CARDINAL,
TEXT_SIZE_PRIMARY
) {
it.isGone = !dataLoggerSettings.instance().vehicleStatusPanelEnabled
}
}
}

internal fun MainActivity.updateVehicleProfile() {
updateTextField(
R.id.vehicle_profile,
resources.getString(R.string.status_panel_vehicle_profile),
profile.getCurrentProfileName(),
COLOR_RAINBOW_INDIGO,
1.0f
)
}
fun updateVehicleProfile() {
val fullProfileName = profile.getCurrentProfileName()
var displayName = fullProfileName.substringBefore("(").trim()

if (displayName.length > MAX_PROFILE_NAME_LENGTH) {
displayName = displayName.substring(0, MAX_PROFILE_NAME_LENGTH).trimEnd() + "..."
}

updateTextField(
R.id.vehicle_profile,
activity.getString(R.string.status_panel_vehicle_profile),
displayName,
COLOR_RAINBOW_INDIGO,
TEXT_SIZE_PRIMARY
)
}

fun updateAdapterConnectionType() {
updateTextField(
R.id.connection_status,
activity.getString(R.string.status_panel_adapter_connection_type),
dataLoggerSettings.instance().adapter.connectionType,
COLOR_PHILIPPINE_GREEN,
TEXT_SIZE_PRIMARY
)
}

@SuppressLint("SetTextI18n")
private fun MainActivity.updateTextField(
viewId: Int,
text1: String,
text2: String,
color: Int,
text2Size: Float,
func: (p: TextView) -> Unit = {}
) {
(findViewById<TextView>(viewId)).let {
func(it)
it.text = "$text1 $text2"
it.highLightText(text1, 0.7f, Color.WHITE)
it.highLightText(text2, text2Size, color)
private fun updateTextField(
viewId: Int,
text1: String,
text2: String,
color: Int,
text2Size: Float,
func: (p: TextView) -> Unit = {}
) {
activity.findViewById<TextView>(viewId)?.apply {
func(this)
text = "$text1 $text2"
highLightText(text1, TEXT_SIZE_SECONDARY, Color.WHITE)
highLightText(text2, text2Size, color)
}
}
}
20 changes: 13 additions & 7 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
android:text="@string/status_panel.adapter_connection_type"
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/vehicle_profile"
app:layout_constraintTop_toTopOf="parent" />

<TextView
Expand All @@ -48,9 +51,12 @@
android:text="@string/status_panel.vehicle_profile"
android:textColor="@color/white"
android:textSize="12sp"
android:maxWidth="200dp"
android:maxLines="1"
android:ellipsize="end"
app:layout_constrainedWidth="true"
app:layout_constraintBaseline_toBaselineOf="@id/connection_status"
app:layout_constraintStart_toEndOf="@id/connection_status" />
app:layout_constraintStart_toEndOf="@id/connection_status"
app:layout_constraintEnd_toStartOf="@+id/vehicle_status" />

<TextView
android:id="@+id/vehicle_status"
Expand All @@ -62,19 +68,20 @@
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintBaseline_toBaselineOf="@id/connection_status"
app:layout_constraintStart_toEndOf="@id/vehicle_profile" />
app:layout_constraintStart_toEndOf="@id/vehicle_profile"
app:layout_constraintEnd_toStartOf="@+id/timer" />

<Chronometer
android:id="@+id/timer"
android:layout_width="0dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:padding="2dp"
android:textColor="@color/white"
android:textSize="12sp"
app:layout_constraintBaseline_toBaselineOf="@id/connection_status"
app:layout_constraintEnd_toStartOf="@id/toggle_fullscreen"
app:layout_constraintStart_toEndOf="@id/vehicle_status" />
app:layout_constraintStart_toEndOf="@id/vehicle_status"
app:layout_constraintEnd_toStartOf="@id/toggle_fullscreen" />

<ImageView
android:id="@+id/toggle_fullscreen"
Expand Down Expand Up @@ -168,7 +175,6 @@
app:layout_behavior="com.google.android.material.behavior.HideBottomViewOnScrollBehavior"
tools:ignore="ContentDescription" />


<TextView
android:id="@+id/configure_view_action_label"
android:layout_width="wrap_content"
Expand Down
Loading