Colota - Android GPS Location tracker
feat: add API mapping templates (Dawarich, OwnTracks, Reitti) and custom static fields
Max Dietricha6aa7a5472e6
diff --git a/android/app/src/main/java/com/colota/DatabaseHelper.kt b/android/app/src/main/java/com/colota/DatabaseHelper.ktindex c26d442b..92cb9271 100644--- a/android/app/src/main/java/com/colota/DatabaseHelper.kt+++ b/android/app/src/main/java/com/colota/DatabaseHelper.kt@@ -154,7 +154,8 @@ class DatabaseHelper private constructor(context: Context) :"filterInaccurateLocations" to "false","maxRetries" to "5","retryInterval" to "30",- "isOfflineMode" to "false"+ "isOfflineMode" to "false",+ "customFields" to "[]")db.beginTransaction()diff --git a/android/app/src/main/java/com/colota/LocationForegroundService.kt b/android/app/src/main/java/com/colota/LocationForegroundService.ktindex 0c46fa16..de27a94d 100644--- a/android/app/src/main/java/com/colota/LocationForegroundService.kt+++ b/android/app/src/main/java/com/colota/LocationForegroundService.kt@@ -61,6 +61,7 @@ class LocationForegroundService : Service() {// --- Configuration (use ServiceConfig) ---private lateinit var config: ServiceConfigprivate var fieldMap: Map<String, String>? = null+ private var customFields: Map<String, String>? = nullprivate var authHeaders: Map<String, String> = emptyMap()private var consecutiveFailures = 0@@ -374,11 +375,12 @@ class LocationForegroundService : Service() {// Build payload onceval currentFieldMap = fieldMap ?: emptyMap()val payload = locationUtils.buildPayload(- location,- battery,- batteryStatus,- currentFieldMap,- timestampSec+ location,+ battery,+ batteryStatus,+ currentFieldMap,+ timestampSec,+ customFields)// Queue and optionally send (don't launch new coroutine if already in one)@@ -884,6 +886,11 @@ class LocationForegroundService : Service() {if (it.isNotBlank()) fieldMap = locationUtils.parseFieldMap(it)}+ // Parse customFields (static key-value pairs added to every payload)+ config.customFields?.let {+ if (it.isNotBlank()) customFields = locationUtils.parseCustomFields(it)+ }+if (BuildConfig.DEBUG) {val batteryStatusStr = deviceInfoHelper.getBatteryStatusString()diff --git a/android/app/src/main/java/com/colota/LocationsUtils.kt b/android/app/src/main/java/com/colota/LocationsUtils.ktindex afcd1985..74bd671a 100644--- a/android/app/src/main/java/com/colota/LocationsUtils.kt+++ b/android/app/src/main/java/com/colota/LocationsUtils.kt@@ -115,22 +115,28 @@ class LocationUtils(private val context: Context) {batteryLevel: Int,batteryStatus: Int,fieldMap: Map<String, String>,- timestamp: Long+ timestamp: Long,+ customFields: Map<String, String>? = null): JSONObject {return JSONObject().apply {+ // Add custom static fields first+ customFields?.forEach { (key, value) ->+ put(key, value)+ }+put(fieldMap["lat"] ?: "lat", location.latitude)put(fieldMap["lon"] ?: "lon", location.longitude)put(fieldMap["acc"] ?: "acc", location.accuracy.roundToInt())-+if (location.hasAltitude()) {put(fieldMap["alt"] ?: "alt", location.altitude.roundToInt())}-+put(fieldMap["vel"] ?: "vel", location.speed.roundToInt())put(fieldMap["batt"] ?: "batt", batteryLevel)put(fieldMap["bs"] ?: "bs", batteryStatus)put(fieldMap["tst"] ?: "tst", timestamp)-+if (location.hasBearing()) {put(fieldMap["bear"] ?: "bear", location.bearing.toDouble())}@@ -152,6 +158,26 @@ class LocationUtils(private val context: Context) {}}+ /**+ * Parses JSON array string of custom fields into a Map.+ * Expected format: [{"key":"_type","value":"location"},...]+ */+ fun parseCustomFields(jsonString: String?): Map<String, String>? {+ if (jsonString.isNullOrBlank() || jsonString == "[]") return null+ return try {+ val arr = org.json.JSONArray(jsonString)+ val map = mutableMapOf<String, String>()+ for (i in 0 until arr.length()) {+ val obj = arr.getJSONObject(i)+ map[obj.getString("key")] = obj.getString("value")+ }+ if (map.isEmpty()) null else map+ } catch (e: Exception) {+ Log.e(TAG, "Failed to parse custom fields", e)+ null+ }+ }+/*** Converts ReadableMap to JSON string with null safety.*/diff --git a/android/app/src/main/java/com/colota/ServiceConfig.kt b/android/app/src/main/java/com/colota/ServiceConfig.ktindex adde6204..7a1e994a 100644--- a/android/app/src/main/java/com/colota/ServiceConfig.kt+++ b/android/app/src/main/java/com/colota/ServiceConfig.kt@@ -24,7 +24,8 @@ data class ServiceConfig(val filterInaccurateLocations: Boolean = true,val retryIntervalSeconds: Int = 300,val isOfflineMode: Boolean = false,- val fieldMap: String? = null+ val fieldMap: String? = null,+ val customFields: String? = null) {companion object {/**@@ -43,7 +44,8 @@ data class ServiceConfig(filterInaccurateLocations = saved["filterInaccurateLocations"]?.toBoolean() ?: true,retryIntervalSeconds = saved["retryInterval"]?.toIntOrNull() ?: 300,isOfflineMode = saved["isOfflineMode"]?.toBoolean() ?: false,- fieldMap = saved["fieldMap"]+ fieldMap = saved["fieldMap"],+ customFields = saved["customFields"])}@@ -66,7 +68,8 @@ data class ServiceConfig(filterInaccurateLocations = extras.getBooleanOrDefault("filterInaccurateLocations", dbConfig.filterInaccurateLocations),retryIntervalSeconds = extras.getIntOrDefault("retryInterval", dbConfig.retryIntervalSeconds),isOfflineMode = extras.getBooleanOrDefault("isOfflineMode", dbConfig.isOfflineMode),- fieldMap = extras.getStringOrDefault("fieldMap", dbConfig.fieldMap)+ fieldMap = extras.getStringOrDefault("fieldMap", dbConfig.fieldMap),+ customFields = extras.getStringOrDefault("customFields", dbConfig.customFields))}}@@ -86,6 +89,7 @@ data class ServiceConfig(putExtra("retryInterval", retryIntervalSeconds)putExtra("isOfflineMode", isOfflineMode)fieldMap?.let { putExtra("fieldMap", it) }+ customFields?.let { putExtra("customFields", it) }}}}diff --git a/src/contexts/TrackingProvider.tsx b/src/contexts/TrackingProvider.tsxindex 9859801b..8ac0866b 100644--- a/src/contexts/TrackingProvider.tsx+++ b/src/contexts/TrackingProvider.tsx@@ -12,7 +12,12 @@ import React, {useCallback,useRef,} from "react";-import { Settings, DEFAULT_SETTINGS, LocationCoords } from "../types/global";+import {+ Settings,+ DEFAULT_SETTINGS,+ LocationCoords,+ ApiTemplateName,+} from "../types/global";import { useLocationTracking } from "../hooks/useLocationTracking";import NativeLocationService from "../services/NativeLocationService";import SettingsService from "../services/SettingsService";@@ -70,6 +75,13 @@ function parseRawSettings(allRaw: Record<string, string>): Settings {fieldMap: allRaw.fieldMap? JSON.parse(allRaw.fieldMap): DEFAULT_SETTINGS.fieldMap,++ customFields: allRaw.customFields+ ? JSON.parse(allRaw.customFields)+ : DEFAULT_SETTINGS.customFields,++ apiTemplate:+ (allRaw.apiTemplate as ApiTemplateName) ?? DEFAULT_SETTINGS.apiTemplate,};}diff --git a/src/screens/ApiSettingsScreen.tsx b/src/screens/ApiSettingsScreen.tsxindex 49527be3..21033a14 100644--- a/src/screens/ApiSettingsScreen.tsx+++ b/src/screens/ApiSettingsScreen.tsx@@ -12,7 +12,14 @@ import {ScrollView,TouchableOpacity,} from "react-native";-import { FieldMap, DEFAULT_FIELD_MAP, ScreenProps } from "../types/global";+import {+ FieldMap,+ DEFAULT_FIELD_MAP,+ ScreenProps,+ CustomField,+ ApiTemplateName,+ API_TEMPLATES,+} from "../types/global";import { useTheme } from "../hooks/useTheme";import { useTracking } from "../contexts/TrackingProvider";import {@@ -35,15 +42,30 @@ const FIELD_DESCRIPTIONS: Record<keyof FieldMap, string> = {bear: "Direction of travel (0-360°)",};+const TEMPLATE_OPTIONS: { value: ApiTemplateName; label: string }[] = [+ { value: "custom", label: "Custom" },+ { value: "dawarich", label: "Dawarich" },+ { value: "owntracks", label: "OwnTracks" },+ { value: "reitti", label: "Reitti" },+];++/**+ * Returns the reference field map for the current template.+ * Used for "Modified" badge comparison and "Reset" actions.+ */+function getReferenceFieldMap(template: ApiTemplateName): FieldMap {+ if (template === "custom") return DEFAULT_FIELD_MAP;+ return API_TEMPLATES[template].fieldMap;+}++function getReferenceCustomFields(template: ApiTemplateName): CustomField[] {+ if (template === "custom") return [];+ return API_TEMPLATES[template].customFields;+}+/**- * Screen for configuring API field name mappings.- *- * UX IMPROVEMENTS:- * - Two-column layout (key → value) for better scannability- * - Visual indicators for modified fields- * - Quick copy default name feature- * - Cleaner, more compact design- * - Better touch targets+ * Screen for configuring API field name mappings, backend templates,+ * and custom static fields.*/export function ApiSettingsScreen({}: ScreenProps) {const { settings, setSettings, restartTracking } = useTracking();@@ -52,38 +74,60 @@ export function ApiSettingsScreen({}: ScreenProps) {const [localFieldMap, setLocalFieldMap] = useState<FieldMap>(settings.fieldMap || DEFAULT_FIELD_MAP);+ const [localCustomFields, setLocalCustomFields] = useState<CustomField[]>(+ settings.customFields || []+ );+ const [localTemplate, setLocalTemplate] = useState<ApiTemplateName>(+ settings.apiTemplate || "custom"+ );const saveTimeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);const [saving, setSaving] = useState(false);const [saveSuccess, setSaveSuccess] = useState(false);+ const referenceFieldMap = getReferenceFieldMap(localTemplate);+/**- * Check if field has been modified from default+ * Check if field has been modified from the current template's defaults*/const isModified = (key: keyof FieldMap): boolean => {- return localFieldMap[key] !== DEFAULT_FIELD_MAP[key];+ return localFieldMap[key] !== referenceFieldMap[key];};/**- * Saves field map and restarts tracking if active+ * Saves all API config and restarts tracking if active*/- const saveSettings = useCallback(- async (newFieldMap: FieldMap) => {+ const saveAllSettings = useCallback(+ async (+ newFieldMap: FieldMap,+ newCustomFields: CustomField[],+ newTemplate: ApiTemplateName+ ) => {// Sanitize: trim all field valuesconst sanitizedMap = Object.fromEntries(Object.entries(newFieldMap).map(([key, value]) => [key, value.trim()])) as FieldMap;- // Prevent saving if any field is empty+ // Prevent saving if any field mapping is emptyif (Object.values(sanitizedMap).some((v) => v === "")) {return;}+ // Sanitize custom fields: trim and remove entries with empty keys+ const sanitizedCustomFields = newCustomFields+ .map((f) => ({ key: f.key.trim(), value: f.value.trim() }))+ .filter((f) => f.key.length > 0);+try {setSaving(true);setSaveSuccess(false);- const newSettings = { ...settings, fieldMap: sanitizedMap };+ const newSettings = {+ ...settings,+ fieldMap: sanitizedMap,+ customFields: sanitizedCustomFields,+ apiTemplate: newTemplate,+ };await setSettings(newSettings);await restartTracking(newSettings);@@ -93,7 +137,7 @@ export function ApiSettingsScreen({}: ScreenProps) {setTimeout(() => setSaveSuccess(false), 2000);} catch (err) {setSaving(false);- console.error("[ApiSettingsScreen] Failed to save field map:", err);+ console.error("[ApiSettingsScreen] Failed to save settings:", err);}},[settings, setSettings, restartTracking]@@ -103,59 +147,129 @@ export function ApiSettingsScreen({}: ScreenProps) {* Debounced save (1.5s delay)*/const debouncedSave = useCallback(- (newFieldMap: FieldMap) => {+ (+ newFieldMap: FieldMap,+ newCustomFields: CustomField[],+ newTemplate: ApiTemplateName+ ) => {if (saveTimeoutRef.current) {clearTimeout(saveTimeoutRef.current);}saveTimeoutRef.current = setTimeout(- () => saveSettings(newFieldMap),+ () => saveAllSettings(newFieldMap, newCustomFields, newTemplate),1500);},- [saveSettings]+ [saveAllSettings]);/**- * Handles field value changes with auto-save+ * Handles template selection+ */+ const handleTemplateChange = useCallback(+ (template: ApiTemplateName) => {+ setLocalTemplate(template);++ if (template === "custom") {+ // Keep current field map and custom fields, just save the template change+ if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);+ saveAllSettings(localFieldMap, localCustomFields, template);+ } else {+ const tmpl = API_TEMPLATES[template];+ setLocalFieldMap(tmpl.fieldMap);+ setLocalCustomFields(tmpl.customFields);++ // Save immediately on template change+ if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);+ saveAllSettings(tmpl.fieldMap, tmpl.customFields, template);+ }+ },+ [localFieldMap, localCustomFields, saveAllSettings]+ );++ /**+ * Handles field value changes with auto-save.+ * Switching to "custom" template if a known template was selected.*/const handleFieldChange = useCallback((key: keyof FieldMap, value: string) => {const newFieldMap = { ...localFieldMap, [key]: value };setLocalFieldMap(newFieldMap);- debouncedSave(newFieldMap);++ const newTemplate = localTemplate !== "custom" ? "custom" : localTemplate;+ if (newTemplate !== localTemplate) setLocalTemplate(newTemplate);++ debouncedSave(newFieldMap, localCustomFields, newTemplate);},- [localFieldMap, debouncedSave]+ [localFieldMap, localCustomFields, localTemplate, debouncedSave]);/**- * Reset single field to default+ * Reset single field to current template default*/const handleResetField = useCallback((key: keyof FieldMap) => {- const newFieldMap = { ...localFieldMap, [key]: DEFAULT_FIELD_MAP[key] };+ const newFieldMap = { ...localFieldMap, [key]: referenceFieldMap[key] };setLocalFieldMap(newFieldMap);- // Cancel debounce and save immediately- if (saveTimeoutRef.current) {- clearTimeout(saveTimeoutRef.current);- }- saveSettings(newFieldMap);+ if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);+ saveAllSettings(newFieldMap, localCustomFields, localTemplate);},- [localFieldMap, saveSettings]+ [+ localFieldMap,+ localCustomFields,+ localTemplate,+ referenceFieldMap,+ saveAllSettings,+ ]);/**- * Resets all fields to default values+ * Resets all fields to current template defaults*/const handleResetAll = useCallback(() => {- // Cancel any pending auto-saves- if (saveTimeoutRef.current) {- clearTimeout(saveTimeoutRef.current);- }+ if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);++ const refFields = getReferenceCustomFields(localTemplate);+ setLocalFieldMap(referenceFieldMap);+ setLocalCustomFields(refFields);+ saveAllSettings(referenceFieldMap, refFields, localTemplate);+ }, [referenceFieldMap, localTemplate, saveAllSettings]);++ // --- Custom Fields handlers ---++ const handleAddCustomField = useCallback(() => {+ const newFields = [...localCustomFields, { key: "", value: "" }];+ setLocalCustomFields(newFields);+ }, [localCustomFields]);++ const handleCustomFieldChange = useCallback(+ (index: number, field: "key" | "value", text: string) => {+ const newFields = [...localCustomFields];+ newFields[index] = { ...newFields[index], [field]: text };+ setLocalCustomFields(newFields);- setLocalFieldMap(DEFAULT_FIELD_MAP);- saveSettings(DEFAULT_FIELD_MAP);- }, [saveSettings]);+ const newTemplate = localTemplate !== "custom" ? "custom" : localTemplate;+ if (newTemplate !== localTemplate) setLocalTemplate(newTemplate);++ debouncedSave(localFieldMap, newFields, newTemplate);+ },+ [localCustomFields, localFieldMap, localTemplate, debouncedSave]+ );++ const handleRemoveCustomField = useCallback(+ (index: number) => {+ const newFields = localCustomFields.filter((_, i) => i !== index);+ setLocalCustomFields(newFields);++ const newTemplate = localTemplate !== "custom" ? "custom" : localTemplate;+ if (newTemplate !== localTemplate) setLocalTemplate(newTemplate);++ if (saveTimeoutRef.current) clearTimeout(saveTimeoutRef.current);+ saveAllSettings(localFieldMap, newFields, newTemplate);+ },+ [localCustomFields, localFieldMap, localTemplate, saveAllSettings]+ );// Cleanup timeout on unmountuseEffect(() => {@@ -166,11 +280,36 @@ export function ApiSettingsScreen({}: ScreenProps) {};}, []);- // Check if any field is modified+ // Check if any field mapping is modified from the referenceconst hasModifications = (Object.keys(DEFAULT_FIELD_MAP) as Array<keyof FieldMap>).some((key) => isModified(key));+ // Build example payload string showing all fields+ const examplePayload = (() => {+ const entries: string[] = [];++ // Custom static fields first+ localCustomFields.forEach((f) => {+ if (f.key) {+ entries.push(` "${f.key}": "${f.value}"`);+ }+ });++ // All mapped fields with realistic example values+ entries.push(` "${localFieldMap.lat}": 52.12345`);+ entries.push(` "${localFieldMap.lon}": -2.12345`);+ entries.push(` "${localFieldMap.acc}": 15`);+ if (localFieldMap.alt) entries.push(` "${localFieldMap.alt}": 380`);+ if (localFieldMap.vel) entries.push(` "${localFieldMap.vel}": 5`);+ if (localFieldMap.batt) entries.push(` "${localFieldMap.batt}": 85`);+ if (localFieldMap.bs) entries.push(` "${localFieldMap.bs}": 2`);+ if (localFieldMap.tst) entries.push(` "${localFieldMap.tst}": 1739362800`);+ if (localFieldMap.bear) entries.push(` "${localFieldMap.bear}": 180.0`);++ return "{\n" + entries.join(",\n") + "\n}";+ })();+return (<Container><ScrollView@@ -187,6 +326,52 @@ export function ApiSettingsScreen({}: ScreenProps) {</Text></View>+ {/* Template Selector */}+ <View style={styles.section}>+ <SectionTitle>BACKEND TEMPLATE</SectionTitle>+ <View style={styles.chipRow}>+ {TEMPLATE_OPTIONS.map(({ value, label }) => {+ const isSelected = localTemplate === value;+ return (+ <TouchableOpacity+ key={value}+ style={[+ styles.chip,+ {+ borderColor: colors.border,+ backgroundColor: colors.background,+ },+ isSelected && {+ borderColor: colors.primary,+ backgroundColor: colors.primary + "20",+ },+ ]}+ onPress={() => handleTemplateChange(value)}+ activeOpacity={0.7}+ >+ <Text+ style={[+ styles.chipText,+ {+ color: isSelected ? colors.primary : colors.text,+ },+ ]}+ >+ {label}+ </Text>+ </TouchableOpacity>+ );+ })}+ </View>+ {localTemplate !== "custom" && (+ <Text+ style={[styles.templateHint, { color: colors.textSecondary }]}+ >+ {API_TEMPLATES[localTemplate].description}+ </Text>+ )}+ </View>+{/* Field Mapping Section */}<View style={styles.fieldsSection}><View style={styles.sectionHeader}>@@ -260,7 +445,7 @@ export function ApiSettingsScreen({}: ScreenProps) {]}value={localFieldMap[key]}onChangeText={(text) => handleFieldChange(key, text)}- placeholder={DEFAULT_FIELD_MAP[key]}+ placeholder={referenceFieldMap[key]}placeholderTextColor={colors.placeholder}autoCapitalize="none"autoCorrect={false}@@ -296,6 +481,96 @@ export function ApiSettingsScreen({}: ScreenProps) {</View></View>+ {/* Custom Fields Section */}+ <View style={styles.fieldsSection}>+ <View style={styles.sectionHeader}>+ <SectionTitle>CUSTOM FIELDS</SectionTitle>+ </View>++ <View+ style={[+ styles.fieldsCard,+ { backgroundColor: colors.card, borderColor: colors.border },+ ]}+ >+ {localCustomFields.length === 0 ? (+ <Text style={[styles.emptyHint, { color: colors.textSecondary }]}>+ No custom fields. Add static key-value pairs to include in every+ payload.+ </Text>+ ) : (+ localCustomFields.map((field, index) => (+ <View key={index}>+ <View style={styles.customFieldRow}>+ <TextInput+ style={[+ styles.customFieldInput,+ {+ borderColor: colors.border,+ color: colors.text,+ backgroundColor: colors.background,+ },+ ]}+ value={field.key}+ onChangeText={(text) =>+ handleCustomFieldChange(index, "key", text)+ }+ placeholder="Key"+ placeholderTextColor={colors.placeholder}+ autoCapitalize="none"+ autoCorrect={false}+ />+ <TextInput+ style={[+ styles.customFieldInput,+ {+ borderColor: colors.border,+ color: colors.text,+ backgroundColor: colors.background,+ },+ ]}+ value={field.value}+ onChangeText={(text) =>+ handleCustomFieldChange(index, "value", text)+ }+ placeholder="Value"+ placeholderTextColor={colors.placeholder}+ autoCapitalize="none"+ autoCorrect={false}+ />+ <TouchableOpacity+ onPress={() => handleRemoveCustomField(index)}+ style={[+ styles.removeButton,+ { backgroundColor: colors.error + "15" },+ ]}+ >+ <Text+ style={[+ styles.removeButtonText,+ { color: colors.error },+ ]}+ >+ X+ </Text>+ </TouchableOpacity>+ </View>+ {index < localCustomFields.length - 1 && <Divider />}+ </View>+ ))+ )}++ <TouchableOpacity+ onPress={handleAddCustomField}+ style={[styles.addButton, { borderColor: colors.border }]}+ >+ <Text style={[styles.addButtonText, { color: colors.primary }]}>+ + Add Field+ </Text>+ </TouchableOpacity>+ </View>+ </View>+{/* Example payload preview */}<View style={styles.exampleSection}><SectionTitle>EXAMPLE PAYLOAD</SectionTitle>@@ -309,13 +584,7 @@ export function ApiSettingsScreen({}: ScreenProps) {]}><Text style={[styles.exampleCode, { color: colors.textSecondary }]}>- {`{\n`}- {` "${localFieldMap.lat}": 52.12345,\n`}- {` "${localFieldMap.lon}": -2.12345,\n`}- {` "${localFieldMap.acc}": 15,\n`}- {` "${localFieldMap.batt}": 85,\n`}- {` ...\n`}- {`}`}+ {examplePayload}</Text></View></View>@@ -357,6 +626,28 @@ const styles = StyleSheet.create({fontSize: 14,lineHeight: 20,},+ section: {+ marginBottom: 24,+ },+ chipRow: {+ flexDirection: "row",+ gap: 8,+ },+ chip: {+ flex: 1,+ borderWidth: 2,+ borderRadius: 10,+ paddingVertical: 10,+ alignItems: "center",+ },+ chipText: {+ fontSize: 12,+ fontWeight: "700",+ },+ templateHint: {+ fontSize: 12,+ marginTop: 8,+ },fieldsSection: {marginBottom: 20,},@@ -443,6 +734,49 @@ const styles = StyleSheet.create({fontSize: 18,fontWeight: "600",},+ customFieldRow: {+ flexDirection: "row",+ alignItems: "center",+ gap: 8,+ paddingVertical: 8,+ },+ customFieldInput: {+ flex: 1,+ borderWidth: 1.5,+ paddingHorizontal: 10,+ paddingVertical: 8,+ borderRadius: 8,+ fontSize: 14,+ fontFamily: "monospace",+ },+ removeButton: {+ width: 32,+ height: 32,+ borderRadius: 16,+ justifyContent: "center",+ alignItems: "center",+ },+ removeButtonText: {+ fontSize: 13,+ fontWeight: "700",+ },+ addButton: {+ paddingVertical: 12,+ alignItems: "center",+ borderRadius: 10,+ borderWidth: 1.5,+ borderStyle: "dashed",+ marginTop: 8,+ },+ addButtonText: {+ fontSize: 14,+ fontWeight: "600",+ },+ emptyHint: {+ fontSize: 13,+ textAlign: "center",+ paddingVertical: 8,+ },exampleSection: {marginBottom: 20,},diff --git a/src/services/SettingsService.ts b/src/services/SettingsService.tsindex e5ee1150..253a303f 100644--- a/src/services/SettingsService.ts+++ b/src/services/SettingsService.ts@@ -26,6 +26,7 @@ export const SettingsService = {break;case "fieldMap":+ case "customFields":// Object → JSON stringstringValue = JSON.stringify(value);break;diff --git a/src/types/global.ts b/src/types/global.tsindex e3334c25..c9115aac 100644--- a/src/types/global.ts+++ b/src/types/global.ts@@ -143,6 +143,81 @@ export const DEFAULT_FIELD_MAP: FieldMap = {bear: "bear",} as const;+export interface CustomField {+ key: string;+ value: string;+}++export type ApiTemplateName = "custom" | "dawarich" | "owntracks" | "reitti";++export interface ApiTemplate {+ name: ApiTemplateName;+ label: string;+ description: string;+ fieldMap: FieldMap;+ customFields: CustomField[];+}++export const API_TEMPLATES: Record<+ Exclude<ApiTemplateName, "custom">,+ ApiTemplate+> = {+ dawarich: {+ name: "dawarich",+ label: "Dawarich",+ description: "OwnTracks-compatible format for Dawarich",+ fieldMap: {+ lat: "lat",+ lon: "lon",+ acc: "acc",+ alt: "alt",+ vel: "vel",+ batt: "batt",+ bs: "bs",+ tst: "tst",+ bear: "cog",+ },+ customFields: [{ key: "_type", value: "location" }],+ },+ owntracks: {+ name: "owntracks",+ label: "OwnTracks",+ description: "Standard OwnTracks HTTP format",+ fieldMap: {+ lat: "lat",+ lon: "lon",+ acc: "acc",+ alt: "alt",+ vel: "vel",+ batt: "batt",+ bs: "bs",+ tst: "tst",+ bear: "cog",+ },+ customFields: [+ { key: "_type", value: "location" },+ { key: "tid", value: "AA" },+ ],+ },+ reitti: {+ name: "reitti",+ label: "Reitti",+ description: "OwnTracks-compatible format for Reitti",+ fieldMap: {+ lat: "lat",+ lon: "lon",+ acc: "acc",+ alt: "alt",+ vel: "vel",+ batt: "batt",+ bs: "bs",+ tst: "tst",+ bear: "bear",+ },+ customFields: [{ key: "_type", value: "location" }],+ },+};+// ============================================================================// PRESETS// ============================================================================@@ -210,6 +285,8 @@ export interface Settings {// Endpoint & Mappingendpoint: string;fieldMap: FieldMap;+ customFields: CustomField[];+ apiTemplate: ApiTemplateName;// Sync & UploadsyncInterval: number;@@ -226,6 +303,8 @@ export const DEFAULT_SETTINGS: Settings = {distance: TRACKING_PRESETS.instant.distance,endpoint: "",fieldMap: DEFAULT_FIELD_MAP,+ customFields: [],+ apiTemplate: "custom",syncInterval: TRACKING_PRESETS.instant.syncInterval,retryInterval: TRACKING_PRESETS.instant.retryInterval,filterInaccurateLocations: false,