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/src/main/java/org/obd/graphs/activity/NavigationRouter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import org.obd.graphs.preferences.PREFERENCE_SCREEN_KEY_GRAPH
import org.obd.graphs.preferences.PREFERENCE_SCREEN_KEY_PERFORMANCE
import org.obd.graphs.preferences.PREFERENCE_SCREEN_KEY_TRIP_INFO
import org.obd.graphs.preferences.PREF_GAUGE_TRIPS
import org.obd.graphs.preferences.PREF_LOGS
import org.obd.graphs.preferences.PREF_TRIP_LOGS
import org.obd.graphs.preferences.Prefs
import org.obd.graphs.preferences.getS
import org.obd.graphs.preferences.getStringSet
Expand Down Expand Up @@ -109,7 +109,7 @@ internal object NavigationRouter {
R.id.nav_preferences -> navigateToPreferencesScreen("pref.root")
R.id.navigation_adapter_connection -> navigateToPreferencesScreen("pref.adapter.connection")
R.id.navigation_adapter_settings -> navigateToPreferencesScreen("pref.adapter")
R.id.navigation_trip_logs -> navigateToPreferencesScreen(PREF_LOGS)
R.id.navigation_trip_logs -> navigateToPreferencesScreen(PREF_TRIP_LOGS)

R.id.navigation_giulia -> navigateToScreen(R.id.nav_giulia)
R.id.navigation_graph -> navigateToScreen(R.id.nav_graph)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/obd/graphs/activity/Receivers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import org.obd.graphs.ScreenLock
import org.obd.graphs.TRIPS_UPLOAD_FAILED
import org.obd.graphs.TRIPS_UPLOAD_NO_FILES_SELECTED
import org.obd.graphs.TRIPS_UPLOAD_SUCCESSFUL
import org.obd.graphs.TRIP_LOG_WRITE_COMPLETED
import org.obd.graphs.bl.datalogger.DATA_LOGGER_ADAPTER_NOT_SET_EVENT
import org.obd.graphs.bl.datalogger.DATA_LOGGER_CONNECTED_EVENT
import org.obd.graphs.bl.datalogger.DATA_LOGGER_CONNECTING_EVENT
Expand All @@ -75,6 +76,7 @@ import org.obd.graphs.bl.extra.EVENT_VEHICLE_STATUS_VEHICLE_IDLING
import org.obd.graphs.bl.extra.EVENT_VEHICLE_STATUS_VEHICLE_RUNNING
import org.obd.graphs.getContext
import org.obd.graphs.getSerializableCompat
import org.obd.graphs.integrations.gcp.gdrive.DriveSync
import org.obd.graphs.preferences.PREFS_CONNECTION_TYPE_CHANGED_EVENT
import org.obd.graphs.preferences.Prefs
import org.obd.graphs.preferences.isEnabled
Expand All @@ -101,6 +103,10 @@ private const val EVENT_VEHICLE_STATUS_CHANGED = "event.vehicle.status.CHANGED"

internal fun MainActivity.receive(intent: Intent?) {
when (intent?.action) {
TRIP_LOG_WRITE_COMPLETED -> {
DriveSync.start(this)
}

DATA_LOGGER_SCHEDULED_STOP_EVENT -> {
Log.d(
LOG_TAG,
Expand Down Expand Up @@ -388,6 +394,7 @@ internal fun MainActivity.registerReceiver() {
it.addAction(NAVIGATION_BUTTONS_VISIBILITY_CHANGED)
it.addAction(DATA_LOGGER_SCHEDULED_STOP_EVENT)
it.addAction(PROFILE_NAME_CHANGED_EVENT)
it.addAction(TRIP_LOG_WRITE_COMPLETED)
}

registerReceiver(this, DataLoggerRepository.broadcastReceivers()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const val PREFERENCE_SCREEN_KEY = "preferences.rootKey"
const val PREFS_CONNECTION_TYPE_CHANGED_EVENT = "prefs.connection_type.changed.event"

const val PREF_GAUGE_TRIPS = "pref.gauge.recordings"
const val PREF_LOGS = "pref.trip_logs"
const val PREF_TRIP_LOGS = "pref.trip_logs"

const val PREFERENCE_CONNECTION_TYPE = "pref.adapter.connection.type"
private const val LOG_KEY = "Prefs"
Expand Down Expand Up @@ -278,7 +278,7 @@ class PreferencesFragment : PreferenceFragmentCompat() {
private fun openPreferenceDialogFor(preferenceKey: String) {
when (preferenceKey) {
PREF_GAUGE_TRIPS -> TripLogListDialogFragment(enableUploadCloudButton = false).show(parentFragmentManager, null)
PREF_LOGS -> TripLogListDialogFragment(enableDeleteButtons = false).show(parentFragmentManager, null)
PREF_TRIP_LOGS -> TripLogListDialogFragment(enableDeleteButtons = false).show(parentFragmentManager, null)

PREFERENCE_SCREEN_KEY_TRIP_INFO ->
openPIDsDialog(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package org.obd.graphs.preferences.trips

import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
Expand All @@ -33,11 +36,13 @@ import org.obd.graphs.R
import org.obd.graphs.SCREEN_LOCK_PROGRESS_EVENT
import org.obd.graphs.SCREEN_UNLOCK_PROGRESS_EVENT
import org.obd.graphs.TRIPS_UPLOAD_NO_FILES_SELECTED
import org.obd.graphs.TRIPS_UPLOAD_SUCCESSFUL
import org.obd.graphs.activity.navigateToScreen
import org.obd.graphs.bl.trip.TripFileDesc
import org.obd.graphs.bl.trip.tripManager
import org.obd.graphs.integrations.gcp.gdrive.TripLogDriveManager
import org.obd.graphs.preferences.CoreDialogFragment
import org.obd.graphs.registerReceiver
import org.obd.graphs.sendBroadcastEvent
import java.io.File

Expand All @@ -52,6 +57,39 @@ class TripLogListDialogFragment(
) : CoreDialogFragment() {
private lateinit var tripLogDriveManager: TripLogDriveManager

private lateinit var adapter: TripViewAdapter

private var broadcastReceiver =
object : BroadcastReceiver() {
@SuppressLint("NotifyDataSetChanged")
override fun onReceive(
context: Context?,
intent: Intent?
) {
when (intent?.action) {
TRIPS_UPLOAD_SUCCESSFUL -> {
if (isAdded && isVisible) {
adapter.data = tripManager.findAllTripsBy().map { TripLogDetails(source = it) }.toMutableList()
adapter.notifyDataSetChanged()
}
}
}
}
}

override fun onPause() {
super.onPause()
requireContext().unregisterReceiver(broadcastReceiver)
}

override fun onResume() {
super.onResume()

registerReceiver(activity, broadcastReceiver) {
it.addAction(TRIPS_UPLOAD_SUCCESSFUL)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
tripLogDriveManager = TripLogDriveManager.instance(getString(R.string.ANDROID_WEB_CLIENT_ID), requireActivity(), this)
Expand All @@ -66,12 +104,13 @@ class TripLogListDialogFragment(
requestWindowFeatures()

val root = inflater.inflate(R.layout.dialog_trip, container, false)
val adapter =
adapter =
TripViewAdapter(
context,
tripManager.findAllTripsBy().map { TripLogDetails(source = it) }.toMutableList(),
enableDeleteButtons
)

val recyclerView: RecyclerView = root.findViewById(R.id.recycler_view)
recyclerView.layoutManager = GridLayoutManager(context, 1)
recyclerView.adapter = adapter
Expand Down Expand Up @@ -131,7 +170,7 @@ class TripLogListDialogFragment(
sendBroadcastEvent(TRIPS_UPLOAD_NO_FILES_SELECTED)
} else {
lifecycleScope.launch {
tripLogDriveManager.exportTrips(files)
tripLogDriveManager.uploadTrips(files)
}
}
}.setNegativeButton(no) { dialog, _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package org.obd.graphs.preferences.trips
import android.content.Context
import android.graphics.Color
import android.graphics.Typeface
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
import android.util.Log
import android.view.LayoutInflater
import android.view.View
Expand All @@ -28,6 +31,7 @@ import android.widget.CheckBox
import android.widget.LinearLayout
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.core.graphics.toColorInt
import androidx.recyclerview.widget.RecyclerView
import org.obd.graphs.R
import org.obd.graphs.bl.trip.tripManager
Expand Down Expand Up @@ -80,7 +84,28 @@ class TripViewAdapter internal constructor(
startTs = dateFormat.format(Date(it))
}

holder.tripStartDate.setText(startTs, Color.GRAY, Typeface.NORMAL, 0.9f)
source.startTime.toLongOrNull()?.let {
startTs = dateFormat.format(Date(it))
}

if (source.isSynced) {
val syncText = " ☁️ Synced"
val fullText = startTs + syncText

holder.tripStartDate.setText(fullText, Color.GRAY, Typeface.NORMAL, 0.9f)

val spannable = SpannableString(fullText)
spannable.setSpan(
ForegroundColorSpan("#4CAF50".toColorInt()), // A nice Material Green
startTs.length,
fullText.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)

holder.tripStartDate.text = spannable
} else {
holder.tripStartDate.setText(startTs, Color.GRAY, Typeface.NORMAL, 0.9f)
}

holder.selected.isChecked = checked
holder.selected.setOnCheckedChangeListener { buttonView, isChecked ->
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/left_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@
<item
android:id="@+id/navigation_graph_tripe"
android:checkable="true"
android:title="@string/pref.trips_recordings" />
android:title="@string/pref.trips.title" />

<item
android:id="@+id/navigation_graph_pids"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@
<string name="pref.dash_swipe_to_delete">Włącz usunięcie metryki przesunięciem</string>
<string name="pref.dash_top_values_blink">Alarm dla najwyższych wartości</string>
<string name="pref.trips_category">Trasy</string>
<string name="pref.trips_recordings">Nagrane trasy</string>
<string name="pref.trips.title">Nagrane trasy</string>

<string name="pref.trips.drive.auto_sync_enabled">Automatyczna synchronizacja z Dyskiem Google</string>
<string name="pref.trips.drive.auto_sync_enabled_summary">Automatycznie przesyłaj nowe przejazdy na Dysk Google po połączeniu z siecią Wi-Fi.</string>

<string name="pref.view_category_summary">W tej sekcji możesz dostosować ustawienia związane z widokami Gauge, Wykres i Giulia.</string>
<string name="pref.view_category">Widoki</string>
<string name="pref.toolbar_category">Pasek narzędzi</string>
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<string name="nav_open">Open</string>
<string name="nav_close">Close</string>




<string name="pref.performance.screen_label_y_padding"><b><i>Gauge</i></b> label top offset</string>
<string name="pref.performance.screen_top_margin">Top margin</string>

Expand Down Expand Up @@ -423,7 +426,10 @@
<string name="pref.dash_swipe_to_delete">Enable swipe to delete metric</string>
<string name="pref.dash_top_values_blink">Alarm for highest values</string>
<string name="pref.trips_category">Trips</string>
<string name="pref.trips_recordings">Recorded trips</string>
<string name="pref.trips.title">Recorded trips</string>
<string name="pref.trips.drive.auto_sync_enabled">Auto-Sync to Google Drive</string>
<string name="pref.trips.drive.auto_sync_enabled_summary">Automatically upload new trips to Google Drive when connected to Wi-Fi.</string>

<string name="pref.view_category_summary">In this section, you can adjust settings related to the Gauge, Graph, and Giulia views.</string>
<string name="pref.view_category">Views</string>
<string name="pref.toolbar_category">Toolbar</string>
Expand Down
20 changes: 16 additions & 4 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@
android:summary="@string/pref.language.summary"
android:persistent="false" />

<PreferenceCategory android:title="@string/pref.trips.title">
<SwitchPreferenceCompat
android:defaultValue="false"
android:dialogTitle="@string/pref.trips.drive.auto_sync_enabled"
android:key="pref.trips.drive.auto_sync"
android:title="@string/pref.trips.drive.auto_sync_enabled"
android:summary="@string/pref.trips.drive.auto_sync_enabled_summary"
app:singleLineTitle="false" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref.registry.category">
<PreferenceScreen
android:key="pref.registry"
Expand Down Expand Up @@ -1904,12 +1914,14 @@
</PreferenceScreen>
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref.trips_recordings">
<PreferenceCategory android:title="@string/pref.trips.title">


<PreferenceScreen
android:summary="@string/pref.trips_recordings"
android:title="@string/pref.trips_recordings"
android:summary="@string/pref.trips.title"
android:title="@string/pref.trips.title"
app:key="pref.gauge.recordings">
<PreferenceCategory android:title="@string/pref.trips_recordings">
<PreferenceCategory android:title="@string/pref.trips.title">
<org.obd.graphs.preferences.trips.TripsListPreferences
android:defaultValue="@array/pref.empty_array"
android:key="pref.graph.trips.selected"
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/org/obd/graphs/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
package org.obd.graphs

const val TRIP_LOG_WRITE_COMPLETED = "trip.log.write.completed.event"

const val LANGUAGE_CHANGE_EVENT = "lang.change.event"

const val SCREEN_LOCK_DIALOG_CANCELLED_EVENT = "screen.lock.dialog.cancelled.event"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.util.Log
import org.obd.graphs.SCREEN_LOCK_PROGRESS_EVENT
import org.obd.graphs.SCREEN_UNLOCK_PROGRESS_EVENT
import org.obd.graphs.ScreenLock
import org.obd.graphs.TRIP_LOG_WRITE_COMPLETED
import org.obd.graphs.bl.datalogger.DataLoggerRepository
import org.obd.graphs.bl.datalogger.scaleToRange
import org.obd.graphs.commons.R
Expand Down Expand Up @@ -188,6 +189,7 @@ internal class DefaultTripManager : TripManager {

activeTripId = null
ts = System.currentTimeMillis() - ts
sendBroadcastEvent(TRIP_LOG_WRITE_COMPLETED)
Log.i(LOG_TAG, "Trip: $currentTripId is saved. It took $ts ms")
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@ class TripDescParser {
val startTime = if (p.size > 2) p[2] else ""
val tripTimeSec = if (p.size > 3) p[3] else "0"

val isSynced = fileName.endsWith(".synced")

return TripFileDesc(
fileName = fileName,
profileId = profileId,
profileLabel = profileLabel,
startTime = startTime,
tripTimeSec = tripTimeSec
tripTimeSec = tripTimeSec,
isSynced = isSynced
)
}

fun decodeTripName(fileName: String): List<String> {
val nameWithoutExtension = fileName.substringBeforeLast(".")
val cleanName = fileName.removeSuffix(".synced")
val nameWithoutExtension = cleanName.substringBeforeLast(".")
return nameWithoutExtension.split("-")
}
}
3 changes: 2 additions & 1 deletion datalogger/src/main/java/org/obd/graphs/bl/trip/TripModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ data class TripFileDesc(
val profileId: String,
val profileLabel: String,
val startTime: String,
val tripTimeSec: String
val tripTimeSec: String,
val isSynced: Boolean = false
)

@JsonIgnoreProperties(ignoreUnknown = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ internal class FileTripRepository(
.filter {
try {
parser.decodeTripName(it).size > 3
} catch (e: Throwable) {
} catch (_: Throwable) {
false
}
}.mapNotNull { fileName ->
Expand Down
3 changes: 3 additions & 0 deletions integrations/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dependencies {
implementation project(":datalogger")
implementation("com.google.code.gson:gson:2.10.1")

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.7.3"
implementation "androidx.work:work-runtime-ktx:2.9.1"

// This specific library provides lifecycleScope
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
// (Optional) If you are using it in a ViewModel, you might also need:
Expand Down
Loading
Loading