Skip to content

Colota - Android GPS Location tracker

feat: warn when Stationary profile interval exceeds 60s and extract FieldMessage for inline field messages

Max Dietrich8746885e22a4
diff --git a/apps/mobile/src/components/features/settings/ConnectionSettings.tsx b/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
index e86c45be..2cdde300 100644
--- a/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
+++ b/apps/mobile/src/components/features/settings/ConnectionSettings.tsx
@@ -21,7 +21,7 @@ import { SettingRow } from "../../ui/SettingRow"
import { useTimeout } from "../../../hooks/useTimeout"
import { CONNECTION_TEST_TIMEOUT, TEST_RESULT_DISPLAY_MS } from "../../../constants"
import { logger } from "../../../utils/logger"
-import { Button, Card, SectionTitle, Divider } from "../../index"
+import { Button, Card, SectionTitle, Divider, FieldMessage } from "../../index"
import { showChoice } from "../../../services/modalService"
interface ConnectionSettingsProps {
@@ -303,21 +303,15 @@ export function ConnectionSettings({
/>
{!endpointInput && (
- <Text style={[styles.endpointHint, { color: colors.warning }]}>
- No server configured. Locations are saved locally
- </Text>
+ <FieldMessage variant="warning">No server configured. Locations are saved locally</FieldMessage>
)}
{endpointInput.startsWith("http://") && !endpointPrivate && (
- <Text style={[styles.httpWarning, { color: colors.warning }]}>
- HTTP only allowed for private IPs / localhost
- </Text>
+ <FieldMessage variant="warning">HTTP only allowed for private IPs / localhost</FieldMessage>
)}
{endpointInput.includes("%") && (
- <Text style={[styles.endpointHint, { color: colors.textSecondary }]}>
- Variables: %DATE, %YEAR, %MONTH, %DAY, %TIMESTAMP
- </Text>
+ <FieldMessage>Variables: %DATE, %YEAR, %MONTH, %DAY, %TIMESTAMP</FieldMessage>
)}
</View>
@@ -441,15 +435,5 @@ const styles = StyleSheet.create({
linkSub: {
fontSize: 13,
...fonts.regular
- },
- endpointHint: {
- marginTop: 6,
- fontSize: 12,
- ...fonts.medium
- },
- httpWarning: {
- marginTop: 6,
- fontSize: 12,
- ...fonts.medium
}
})
diff --git a/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx b/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
index a05d24a8..870631e9 100644
--- a/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
+++ b/apps/mobile/src/components/features/settings/__tests__/ConnectionSettings.test.tsx
@@ -18,7 +18,8 @@ jest.mock("../../../index", () => {
R.createElement(Text, null, label),
hint && R.createElement(Text, null, hint),
children
- )
+ ),
+ FieldMessage: ({ children }: any) => R.createElement(Text, null, children)
}
})
diff --git a/apps/mobile/src/components/index.ts b/apps/mobile/src/components/index.ts
index fc63d470..df7c92b7 100644
--- a/apps/mobile/src/components/index.ts
+++ b/apps/mobile/src/components/index.ts
@@ -31,6 +31,7 @@ export { FormatOption } from "./ui/FormatOption"
export { FormatSelector } from "./ui/FormatSelector"
export { RadioDot } from "./ui/RadioDot"
export { SettingRow } from "./ui/SettingRow"
+export { FieldMessage } from "./ui/FieldMessage"
export { ListItem } from "./ui/ListItem"
export { BottomTabBar } from "./ui/BottomTabBar"
diff --git a/apps/mobile/src/components/ui/FieldMessage.tsx b/apps/mobile/src/components/ui/FieldMessage.tsx
new file mode 100644
index 00000000..b380ca77
--- /dev/null
+++ b/apps/mobile/src/components/ui/FieldMessage.tsx
@@ -0,0 +1,32 @@
+/**
+ * Copyright (C) 2026 Max Dietrich
+ * Licensed under the GNU AGPLv3. See LICENSE in the project root for details.
+ */
+
+import React from "react"
+import { Text, StyleSheet, StyleProp, TextStyle } from "react-native"
+import { useTheme } from "../../hooks/useTheme"
+import { fonts } from "../../styles/typography"
+
+type FieldMessageVariant = "info" | "warning" | "error"
+
+type FieldMessageProps = {
+ children: React.ReactNode
+ variant?: FieldMessageVariant
+ style?: StyleProp<TextStyle>
+}
+
+export function FieldMessage({ children, variant = "info", style }: FieldMessageProps) {
+ const { colors } = useTheme()
+ const color =
+ variant === "error" ? colors.error : variant === "warning" ? (colors.warning ?? colors.error) : colors.textSecondary
+ return <Text style={[styles.message, { color }, style]}>{children}</Text>
+}
+
+const styles = StyleSheet.create({
+ message: {
+ fontSize: 12,
+ marginTop: 6,
+ ...fonts.medium
+ }
+})
diff --git a/apps/mobile/src/components/ui/__tests__/FieldMessage.test.tsx b/apps/mobile/src/components/ui/__tests__/FieldMessage.test.tsx
new file mode 100644
index 00000000..bb68a173
--- /dev/null
+++ b/apps/mobile/src/components/ui/__tests__/FieldMessage.test.tsx
@@ -0,0 +1,51 @@
+import React from "react"
+import { render } from "@testing-library/react-native"
+import { FieldMessage } from "../FieldMessage"
+
+const mockColors = {
+ textSecondary: "#6b7280",
+ warning: "#f59e0b",
+ error: "#ef4444"
+} as any
+
+jest.mock("../../../hooks/useTheme", () => ({
+ useTheme: () => ({ colors: mockColors })
+}))
+
+describe("FieldMessage", () => {
+ it("renders its children", () => {
+ const { getByText } = render(<FieldMessage>Hello</FieldMessage>)
+ expect(getByText("Hello")).toBeTruthy()
+ })
+
+ it("uses textSecondary color for default info variant", () => {
+ const { getByText } = render(<FieldMessage>Info text</FieldMessage>)
+ const node = getByText("Info text")
+ expect(node.props.style).toEqual(
+ expect.arrayContaining([expect.objectContaining({ color: mockColors.textSecondary })])
+ )
+ })
+
+ it("uses warning color for warning variant", () => {
+ const { getByText } = render(<FieldMessage variant="warning">Warn</FieldMessage>)
+ const node = getByText("Warn")
+ expect(node.props.style).toEqual(expect.arrayContaining([expect.objectContaining({ color: mockColors.warning })]))
+ })
+
+ it("uses error color for error variant", () => {
+ const { getByText } = render(<FieldMessage variant="error">Bad</FieldMessage>)
+ const node = getByText("Bad")
+ expect(node.props.style).toEqual(expect.arrayContaining([expect.objectContaining({ color: mockColors.error })]))
+ })
+
+ it("falls back to error color when theme has no warning color", () => {
+ jest.resetModules()
+ jest.doMock("../../../hooks/useTheme", () => ({
+ useTheme: () => ({ colors: { ...mockColors, warning: undefined } })
+ }))
+ const Fresh = require("../FieldMessage").FieldMessage
+ const { getByText } = render(<Fresh variant="warning">Warn</Fresh>)
+ const node = getByText("Warn")
+ expect(node.props.style).toEqual(expect.arrayContaining([expect.objectContaining({ color: mockColors.error })]))
+ })
+})
diff --git a/apps/mobile/src/constants/index.ts b/apps/mobile/src/constants/index.ts
index 3fa2f882..691ad1c5 100644
--- a/apps/mobile/src/constants/index.ts
+++ b/apps/mobile/src/constants/index.ts
@@ -34,6 +34,9 @@ export const MIN_STATS_INTERVAL_MS = 2000
// Profiles
export const MS_TO_KMH = 3.6
+// Doze batches motion sensors past this; longer Stationary intervals risk missed trip starts.
+export const STATIONARY_MAX_INTERVAL_SECONDS = 60
+
export const PROFILE_CONDITIONS: {
type: ProfileConditionType
label: string
diff --git a/apps/mobile/src/screens/GeofenceEditorScreen.tsx b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
index d52cb6b4..6e72113f 100644
--- a/apps/mobile/src/screens/GeofenceEditorScreen.tsx
+++ b/apps/mobile/src/screens/GeofenceEditorScreen.tsx
@@ -18,7 +18,7 @@ import { useTheme } from "../hooks/useTheme"
import NativeLocationService from "../services/NativeLocationService"
import { showAlert, showConfirm } from "../services/modalService"
import { fonts } from "../styles/typography"
-import { Container, SectionTitle, Card, SettingRow, Button } from "../components"
+import { Container, SectionTitle, Card, SettingRow, Button, FieldMessage } from "../components"
import { Check, Trash2 } from "lucide-react-native"
import { logger } from "../utils/logger"
import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"
@@ -295,7 +295,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo
/>
</SettingRow>
{!isPositiveInt(motionlessTimeoutStr) && (
- <Text style={[styles.fieldError, { color: colors.error }]}>Must be at least 1 minute</Text>
+ <FieldMessage variant="error">Must be at least 1 minute</FieldMessage>
)}
</View>
)}
@@ -329,7 +329,7 @@ export function GeofenceEditorScreen({ navigation, route }: RootScreenProps<"Geo
/>
</SettingRow>
{!isPositiveInt(heartbeatIntervalStr) && (
- <Text style={[styles.fieldError, { color: colors.error }]}>Must be at least 1 minute</Text>
+ <FieldMessage variant="error">Must be at least 1 minute</FieldMessage>
)}
</View>
)}
@@ -384,10 +384,5 @@ const styles = StyleSheet.create({
...fonts.regular,
lineHeight: 17,
fontStyle: "italic"
- },
- fieldError: {
- fontSize: 12,
- ...fonts.regular,
- marginTop: 4
}
})
diff --git a/apps/mobile/src/screens/ProfileEditorScreen.tsx b/apps/mobile/src/screens/ProfileEditorScreen.tsx
index 90ede302..9680f4e3 100644
--- a/apps/mobile/src/screens/ProfileEditorScreen.tsx
+++ b/apps/mobile/src/screens/ProfileEditorScreen.tsx
@@ -11,11 +11,17 @@ import { ProfileService } from "../services/ProfileService"
import { showAlert } from "../services/modalService"
import { TrackingProfile, ProfileConditionType } from "../types/global"
import { fonts } from "../styles/typography"
-import { Container, SectionTitle, Card, Divider, SettingRow, NumericInput } from "../components"
+import { Container, SectionTitle, Card, Divider, SettingRow, NumericInput, FieldMessage } from "../components"
import { Check } from "lucide-react-native"
import { logger } from "../utils/logger"
import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"
-import { MS_TO_KMH, PROFILE_CONDITIONS, SYNC_INTERVAL_PRESETS, SYNC_INTERVAL_LABELS } from "../constants"
+import {
+ MS_TO_KMH,
+ PROFILE_CONDITIONS,
+ SYNC_INTERVAL_PRESETS,
+ SYNC_INTERVAL_LABELS,
+ STATIONARY_MAX_INTERVAL_SECONDS
+} from "../constants"
import type { RootScreenProps } from "../types/navigation"
function formatSyncDefault(seconds: number): string {
@@ -273,6 +279,13 @@ export function ProfileEditorScreen({ navigation, route }: RootScreenProps<"Prof
</View>
</SettingRow>
+ {profile.condition.type === "stationary" && profile.interval > STATIONARY_MAX_INTERVAL_SECONDS && (
+ <FieldMessage variant="warning">
+ The device may miss the first {Math.floor(profile.interval / 60)} minutes of a trip when you start moving
+ with the specified interval!
+ </FieldMessage>
+ )}
+
<Divider />
<SettingRow
diff --git a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
index 05575f3f..07e84d9e 100644
--- a/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/GeofenceEditorScreen.test.tsx
@@ -88,7 +88,8 @@ jest.mock("../../components", () => {
accessibilityState: { disabled: !!disabled }
},
R.createElement(Text, null, title)
- )
+ ),
+ FieldMessage: ({ children }: any) => R.createElement(Text, null, children)
}
})
diff --git a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx
index 97608c2c..351fc882 100644
--- a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx
@@ -89,7 +89,8 @@ jest.mock("../../components", () => {
R.createElement(Text, null, label),
hint && R.createElement(Text, null, hint),
children
- )
+ ),
+ FieldMessage: ({ children }: any) => R.createElement(Text, null, children)
}
})
@@ -332,4 +333,60 @@ describe("ProfileEditorScreen", () => {
expect(getByDisplayValue("25")).toBeTruthy()
})
+
+ // --- Stationary interval warning ---
+
+ describe("stationary interval warning", () => {
+ it("does not show the warning while interval is at or below 60s", () => {
+ const { getByText, queryByText, getByDisplayValue } = renderNewProfile()
+
+ fireEvent.press(getByText("Stationary"))
+ const intervalInput = getByDisplayValue("5")
+ fireEvent.changeText(intervalInput, "60")
+
+ expect(queryByText(/may miss the first minutes of a trip/)).toBeNull()
+ })
+
+ it("shows a warning when the interval exceeds 60s", () => {
+ const { getByText, getByDisplayValue } = renderNewProfile()
+
+ fireEvent.press(getByText("Stationary"))
+ const intervalInput = getByDisplayValue("5")
+ fireEvent.changeText(intervalInput, "600")
+
+ expect(getByText(/may miss the first minutes of a trip/)).toBeTruthy()
+ })
+
+ it("does not show the warning for non-stationary conditions even with large intervals", () => {
+ const { queryByText, getByDisplayValue } = renderNewProfile()
+
+ const intervalInput = getByDisplayValue("5")
+ fireEvent.changeText(intervalInput, "3600")
+
+ expect(queryByText(/may miss the first minutes of a trip/)).toBeNull()
+ })
+
+ it("loads an existing Stationary profile with interval > 60 unchanged", async () => {
+ mockGetProfiles.mockResolvedValueOnce([
+ {
+ id: 1,
+ name: "Old Stationary",
+ interval: 3600,
+ distance: 0,
+ syncInterval: 0,
+ priority: 10,
+ condition: { type: "stationary" },
+ deactivationDelay: 0,
+ enabled: true
+ }
+ ])
+
+ const { getByDisplayValue, getByText } = renderEditProfile()
+
+ await waitFor(() => {
+ expect(getByDisplayValue("3600")).toBeTruthy()
+ })
+ expect(getByText(/may miss the first minutes of a trip/)).toBeTruthy()
+ })
+ })
})
diff --git a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
index be958054..388d037e 100644
--- a/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
+++ b/apps/mobile/src/screens/__tests__/SetupImportScreen.test.tsx
@@ -599,6 +599,50 @@ describe("SetupImportScreen", () => {
)
})
+ it("preserves stationary profile interval as set, even when large", async () => {
+ const config = {
+ profiles: [
+ {
+ name: "Stationary",
+ interval: 3600,
+ distance: 0,
+ syncInterval: 0,
+ condition: { type: "stationary" }
+ }
+ ]
+ }
+ const { getByText } = renderScreen(encode(config))
+
+ fireEvent.press(getByText("Apply Configuration"))
+
+ await waitFor(() => {
+ expect(mockCreateProfile).toHaveBeenCalledTimes(1)
+ })
+ expect(mockCreateProfile.mock.calls[0][0].interval).toBe(3600)
+ })
+
+ it("leaves non-stationary profile intervals untouched", async () => {
+ const config = {
+ profiles: [
+ {
+ name: "Driving",
+ interval: 3600,
+ distance: 0,
+ syncInterval: 0,
+ condition: { type: "speed_above", speedThreshold: 8.33 }
+ }
+ ]
+ }
+ const { getByText } = renderScreen(encode(config))
+
+ fireEvent.press(getByText("Apply Configuration"))
+
+ await waitFor(() => {
+ expect(mockCreateProfile).toHaveBeenCalledTimes(1)
+ })
+ expect(mockCreateProfile.mock.calls[0][0].interval).toBe(3600)
+ })
+
it("creates multiple profiles in order", async () => {
const config = {
profiles: [validProfile, { ...validProfile, name: "Stationary", condition: { type: "stationary" } }]