Skip to content

Commit 33b8ec2

Browse files
committed
feat: conditionally enable drive auto-sync
1 parent 15e38ce commit 33b8ec2

5 files changed

Lines changed: 52 additions & 22 deletions

File tree

app/src/main/res/menu/left_nav_menu.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
<item
259259
android:id="@+id/navigation_graph_tripe"
260260
android:checkable="true"
261-
android:title="@string/pref.trips_recordings" />
261+
android:title="@string/pref.trips.title" />
262262

263263
<item
264264
android:id="@+id/navigation_graph_pids"

app/src/main/res/values-pl/strings.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@
424424
<string name="pref.dash_swipe_to_delete">Włącz usunięcie metryki przesunięciem</string>
425425
<string name="pref.dash_top_values_blink">Alarm dla najwyższych wartości</string>
426426
<string name="pref.trips_category">Trasy</string>
427-
<string name="pref.trips_recordings">Nagrane trasy</string>
427+
<string name="pref.trips.title">Nagrane trasy</string>
428+
429+
<string name="pref.trips.drive.auto_sync_enabled">Automatyczna synchronizacja z Dyskiem Google</string>
430+
<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>
431+
428432
<string name="pref.view_category_summary">W tej sekcji możesz dostosować ustawienia związane z widokami Gauge, Wykres i Giulia.</string>
429433
<string name="pref.view_category">Widoki</string>
430434
<string name="pref.toolbar_category">Pasek narzędzi</string>

app/src/main/res/values/strings.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
<string name="nav_open">Open</string>
33
<string name="nav_close">Close</string>
44

5+
6+
7+
58
<string name="pref.performance.screen_label_y_padding"><b><i>Gauge</i></b> label top offset</string>
69
<string name="pref.performance.screen_top_margin">Top margin</string>
710

@@ -423,7 +426,10 @@
423426
<string name="pref.dash_swipe_to_delete">Enable swipe to delete metric</string>
424427
<string name="pref.dash_top_values_blink">Alarm for highest values</string>
425428
<string name="pref.trips_category">Trips</string>
426-
<string name="pref.trips_recordings">Recorded trips</string>
429+
<string name="pref.trips.title">Recorded trips</string>
430+
<string name="pref.trips.drive.auto_sync_enabled">Auto-Sync to Google Drive</string>
431+
<string name="pref.trips.drive.auto_sync_enabled_summary">Automatically upload new trips to Google Drive when connected to Wi-Fi.</string>
432+
427433
<string name="pref.view_category_summary">In this section, you can adjust settings related to the Gauge, Graph, and Giulia views.</string>
428434
<string name="pref.view_category">Views</string>
429435
<string name="pref.toolbar_category">Toolbar</string>

app/src/main/res/xml/preferences.xml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@
88
android:summary="@string/pref.language.summary"
99
android:persistent="false" />
1010

11+
<PreferenceCategory android:title="@string/pref.trips.title">
12+
<SwitchPreferenceCompat
13+
android:defaultValue="false"
14+
android:dialogTitle="@string/pref.trips.drive.auto_sync_enabled"
15+
android:key="pref.trips.drive.auto_sync"
16+
android:title="@string/pref.trips.drive.auto_sync_enabled"
17+
android:summary="@string/pref.trips.drive.auto_sync_enabled_summary"
18+
app:singleLineTitle="false" />
19+
</PreferenceCategory>
20+
1121
<PreferenceCategory android:title="@string/pref.registry.category">
1222
<PreferenceScreen
1323
android:key="pref.registry"
@@ -1904,12 +1914,14 @@
19041914
</PreferenceScreen>
19051915
</PreferenceCategory>
19061916

1907-
<PreferenceCategory android:title="@string/pref.trips_recordings">
1917+
<PreferenceCategory android:title="@string/pref.trips.title">
1918+
1919+
19081920
<PreferenceScreen
1909-
android:summary="@string/pref.trips_recordings"
1910-
android:title="@string/pref.trips_recordings"
1921+
android:summary="@string/pref.trips.title"
1922+
android:title="@string/pref.trips.title"
19111923
app:key="pref.gauge.recordings">
1912-
<PreferenceCategory android:title="@string/pref.trips_recordings">
1924+
<PreferenceCategory android:title="@string/pref.trips.title">
19131925
<org.obd.graphs.preferences.trips.TripsListPreferences
19141926
android:defaultValue="@array/pref.empty_array"
19151927
android:key="pref.graph.trips.selected"

integrations/src/main/java/org/obd/graphs.integrations/gcp/gdrive/TripCloudSyncWorker.kt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import org.obd.graphs.integrations.gcp.authorization.SilentAuthorization
4141
import org.obd.graphs.integrations.gcp.gdrive.DriveHelper.findFolderIdRecursive
4242
import org.obd.graphs.integrations.log.OutputType
4343
import org.obd.graphs.integrations.log.TripLog
44+
import org.obd.graphs.preferences.Prefs
45+
import org.obd.graphs.preferences.isEnabled
4446
import java.io.File
4547

4648
private const val LOG_TAG = "TripCloudSyncWorker"
@@ -50,26 +52,32 @@ object DriveSync {
5052

5153
fun start(context: Context) {
5254
try {
53-
Log.i(LOG_TAG, "Drive start sync scheduling")
55+
val enabled = Prefs.isEnabled("pref.trips.drive.auto_sync")
5456

55-
val constraints = Constraints.Builder()
56-
.setRequiredNetworkType(NetworkType.UNMETERED)
57-
.setRequiresBatteryNotLow(true)
58-
.build()
57+
Log.i(LOG_TAG, "Received trips drive auto-sync request, sync enabled=$enabled")
5958

60-
val syncRequest = OneTimeWorkRequestBuilder<TripCloudSyncWorker>()
61-
.setConstraints(constraints)
62-
.build()
59+
if (enabled) {
60+
val constraints = Constraints.Builder()
61+
.setRequiredNetworkType(NetworkType.UNMETERED)
62+
.setRequiresBatteryNotLow(true)
63+
.build()
6364

64-
WorkManager.getInstance(context).enqueueUniqueWork(
65-
SYNC_WORK_NAME,
66-
ExistingWorkPolicy.KEEP,
67-
syncRequest
68-
)
65+
val syncRequest = OneTimeWorkRequestBuilder<TripCloudSyncWorker>()
66+
.setConstraints(constraints)
67+
.build()
6968

70-
Log.i(LOG_TAG, "Drive sync scheduled")
69+
WorkManager.getInstance(context).enqueueUniqueWork(
70+
SYNC_WORK_NAME,
71+
ExistingWorkPolicy.KEEP,
72+
syncRequest
73+
)
74+
75+
Log.i(LOG_TAG, "Drive auto-sync is scheduled")
76+
} else {
77+
Log.i(LOG_TAG, "Skipping Trips Drive auto-sync")
78+
}
7179
} catch (e: Exception) {
72-
Log.e(LOG_TAG, "Failed to schedule drive sync", e)
80+
Log.e(LOG_TAG, "Failed to schedule drive auto-sync", e)
7381
}
7482
}
7583
}

0 commit comments

Comments
 (0)