Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
refactor(connectors): pick the auto-sync interval with a slider
Durganshu Mishra8e594f30bbd7
diff --git a/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt b/app/src/main/java/com/gotcha/ui/ConnectorsSection.ktindex 5a76a0f..2f8ad51 100644--- a/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt+++ b/app/src/main/java/com/gotcha/ui/ConnectorsSection.kt@@ -2,17 +2,15 @@ package com.gotcha.uiimport androidx.compose.foundation.layout.Arrangementimport androidx.compose.foundation.layout.Column-import androidx.compose.foundation.layout.ExperimentalLayoutApi-import androidx.compose.foundation.layout.FlowRowimport androidx.compose.foundation.layout.Rowimport androidx.compose.foundation.layout.Spacerimport androidx.compose.foundation.layout.fillMaxWidthimport androidx.compose.foundation.layout.widthimport androidx.compose.material3.Checkbox-import androidx.compose.material3.FilterChipimport androidx.compose.material3.HorizontalDividerimport androidx.compose.material3.MaterialThemeimport androidx.compose.material3.OutlinedTextField+import androidx.compose.material3.Sliderimport androidx.compose.material3.Textimport androidx.compose.material3.TextButtonimport androidx.compose.runtime.Composable@@ -38,6 +36,7 @@ import com.gotcha.connectors.microsoft.MicrosoftConnectorimport com.gotcha.connectors.notion.NotionConnectorimport com.gotcha.connectors.oauth.OAuthConnectFlowimport com.gotcha.data.SettingsRepository+import kotlin.math.roundToIntimport kotlinx.coroutines.delayimport kotlinx.coroutines.isActiveimport kotlinx.coroutines.launch@@ -118,7 +117,35 @@ fun ConnectorsSection() {}}-@OptIn(ExperimentalLayoutApi::class)+/**+ * The auto-sync intervals the slider offers, in minutes, with the label shown+ * for each. 1m is the floor: the loop driving auto-sync in [ConnectorsSection]+ * ticks every 60s, so anything finer would be a setting the app cannot honour.+ */+private val AUTO_REFRESH_INTERVALS = listOf(+ 0 to "Off",+ 1 to "1m",+ 2 to "2m",+ 5 to "5m",+ 10 to "10m",+ 15 to "15m",+ 30 to "30m",+ 120 to "2h"+)++/**+ * Slider index for a stored interval. A value that is not one of the offered+ * steps -- written by an older build, or by a settings import -- snaps to the+ * nearest one rather than resetting the user to Off.+ */+private fun indexOfInterval(minutes: Int): Int {+ val exact = AUTO_REFRESH_INTERVALS.indexOfFirst { it.first == minutes }+ if (exact >= 0) return exact+ return AUTO_REFRESH_INTERVALS.indices.minByOrNull {+ kotlin.math.abs(AUTO_REFRESH_INTERVALS[it].first - minutes)+ } ?: 0+}+@Composableprivate fun AutoRefreshHeader(intervalMinutes: Int,@@ -130,6 +157,13 @@ private fun AutoRefreshHeader(var isRefreshing by remember { mutableStateOf(false) }var syncFeedback by remember { mutableStateOf("") }var tick by remember { mutableStateOf(0) }+ // Position is held locally so the thumb tracks the finger; it is re-seeded+ // whenever the stored interval changes underneath us.+ var sliderPosition by remember(intervalMinutes) {+ mutableStateOf(indexOfInterval(intervalMinutes).toFloat())+ }+ val sliderIndex = sliderPosition.roundToInt()+ .coerceIn(0, AUTO_REFRESH_INTERVALS.lastIndex)// Live recomposition ticker for "X min ago" displayLaunchedEffect(lastRefreshedAt) {@@ -189,36 +223,36 @@ private fun AutoRefreshHeader(Text(syncFeedback, style = MaterialTheme.typography.bodySmall)}- // Eight choices no longer fit one phone-width line, so the chips wrap.- FlowRow(- modifier = Modifier.fillMaxWidth(),- horizontalArrangement = Arrangement.spacedBy(8.dp),- verticalArrangement = Arrangement.spacedBy(4.dp)- ) {- Text(- "Interval:",- style = MaterialTheme.typography.bodyMedium,- modifier = Modifier.align(Alignment.CenterVertically)- )- // Anything under a minute would be finer than the 60s poll tick in- // ConnectorsSection can honour, so 1m is the floor.- val intervals = listOf(- 0 to "Off",- 1 to "1m",- 2 to "2m",- 5 to "5m",- 10 to "10m",- 15 to "15m",- 30 to "30m",- 120 to "2h"- )- intervals.forEach { (mins, label) ->- FilterChip(- selected = intervalMinutes == mins,- onClick = { onIntervalChange(mins) },- label = { Text(label) }+ // Eight choices are too many to sit on one phone-width line as chips, so+ // the interval is a slider that snaps to the steps below. The spacing is+ // deliberately not proportional to the durations -- every step is one+ // notch, so the far end stays reachable without a 2h-wide gap.+ Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {+ Row(+ modifier = Modifier.fillMaxWidth(),+ horizontalArrangement = Arrangement.SpaceBetween,+ verticalAlignment = Alignment.CenterVertically+ ) {+ Text("Interval", style = MaterialTheme.typography.bodyMedium)+ Text(+ AUTO_REFRESH_INTERVALS[sliderIndex].second,+ style = MaterialTheme.typography.bodyMedium,+ fontWeight = FontWeight.Bold)}+ Slider(+ value = sliderPosition,+ onValueChange = { sliderPosition = it },+ // The interval only reaches Settings once the thumb is let go;+ // dragging would otherwise write SharedPreferences every frame+ // and restart the refresh loop on each one.+ onValueChangeFinished = {+ onIntervalChange(AUTO_REFRESH_INTERVALS[sliderIndex].first)+ },+ valueRange = 0f..(AUTO_REFRESH_INTERVALS.size - 1).toFloat(),+ steps = AUTO_REFRESH_INTERVALS.size - 2,+ modifier = Modifier.fillMaxWidth()+ )}}}