Colota - Android GPS Location tracker
feat(history): show and copy a point's coordinates, zoom closer on the map (#949)
Max Dietrich18cd365524af
diff --git a/apps/mobile/src/components/features/inspector/PointCard.tsx b/apps/mobile/src/components/features/inspector/PointCard.tsxindex 67c4f7d3..99a7c6ec 100644--- a/apps/mobile/src/components/features/inspector/PointCard.tsx+++ b/apps/mobile/src/components/features/inspector/PointCard.tsx@@ -4,12 +4,25 @@*/import React from "react"-import { StyleSheet, Text, View } from "react-native"-import { Clock, CloudUpload, Crosshair, Gauge, Mountain, NotebookPen, Split, Trash2, X } from "lucide-react-native"+import { Pressable, StyleSheet, Text, View } from "react-native"+import {+ Clock,+ CloudUpload,+ Crosshair,+ Gauge,+ MapPin,+ Mountain,+ NotebookPen,+ Split,+ Trash2,+ X+} from "lucide-react-native"import { useTheme } from "../../../hooks/useTheme"+import NativeLocationService from "../../../services/NativeLocationService"import { showPrompt } from "../../../services/modalService"+import { logger } from "../../../utils/logger"import { fontSizes, fonts } from "../../../styles/typography"-import { size, space } from "../../../constants"+import { HIT_SLOP_SM, size, space, STATE_LAYER_ALPHA } from "../../../constants"import { formatSpeed, formatTime, metersToInput, shortDistanceUnit } from "../../../utils/geo"import type { LocationCoords } from "../../../types/global"import { Divider } from "../../ui/Divider"@@ -45,6 +58,13 @@ export function PointCard({ point, note, hasEndpoint, onSplit, onDelete, onCloseif (next !== null) onSaveNote(next ? next : null)}+ const coordinates = `${point.latitude.toFixed(5)}, ${point.longitude.toFixed(5)}`+ const copyCoordinates = () => {+ NativeLocationService.copyToClipboard(coordinates, t("point.coordinates")).catch((err) =>+ logger.warn("[PointCard] Copy failed:", err)+ )+ }+return (<View testID="point-card"><View style={styles.header}>@@ -68,6 +88,19 @@ export function PointCard({ point, note, hasEndpoint, onSplit, onDelete, onClose)}<IconButton icon={X} accessibilityLabel={t("common.close")} onPress={onClose} testID="point-close" /></View>+ <Divider tight inset />+ <Pressable+ testID="point-coordinates"+ accessibilityRole="button"+ accessibilityLabel={`${t("point.coordinates")}, ${coordinates}`}+ accessibilityHint={t("point.copyCoordinates")}+ android_ripple={{ color: colors.text + STATE_LAYER_ALPHA }}+ hitSlop={HIT_SLOP_SM}+ onPress={copyCoordinates}+ style={styles.pressable}+ >+ <StatRow icon={MapPin} label={t("point.coordinates")} value={coordinates} />+ </Pressable>{point.speed !== undefined && (<><Divider tight inset />@@ -131,6 +164,10 @@ const styles = StyleSheet.create({width: size.icon.md,alignItems: "center"},+ pressable: {+ marginHorizontal: -space.lg,+ paddingHorizontal: space.lg+ },time: {flex: 1,fontSize: fontSizes.label,diff --git a/apps/mobile/src/components/features/inspector/TrackMap.tsx b/apps/mobile/src/components/features/inspector/TrackMap.tsxindex c6db5972..a32eaa44 100644--- a/apps/mobile/src/components/features/inspector/TrackMap.tsx+++ b/apps/mobile/src/components/features/inspector/TrackMap.tsx@@ -48,6 +48,9 @@ const trackPointStyle: any = {type Bounds = NonNullable<ReturnType<typeof computeTrackBounds>>+// A degree of longitude is equally wide on screen at every latitude, so this span caps a fit near z18 on a phone.+const FIT_MIN_LON_SPAN = 0.001+interface Props {locations: TrackLocation[]colors: ThemeColors@@ -114,7 +117,10 @@ export function TrackMap({duration: MAP_ANIMATION_DURATION_MS})} else {- camera.fitBounds([bounds.sw[0], bounds.sw[1], bounds.ne[0], bounds.ne[1]], {+ let [west, east] = [bounds.sw[0], bounds.ne[0]]+ const widen = (FIT_MIN_LON_SPAN - (east - west)) / 2+ if (widen > 0) [west, east] = [west - widen, east + widen]+ camera.fitBounds([west, bounds.sw[1], east, bounds.ne[1]], {padding: cameraPadding,duration: MAP_ANIMATION_DURATION_MS})diff --git a/apps/mobile/src/components/features/inspector/__tests__/PointCard.test.tsx b/apps/mobile/src/components/features/inspector/__tests__/PointCard.test.tsxindex f7acea93..c55a9e19 100644--- a/apps/mobile/src/components/features/inspector/__tests__/PointCard.test.tsx+++ b/apps/mobile/src/components/features/inspector/__tests__/PointCard.test.tsx@@ -2,7 +2,7 @@ import React from "react"import { render, fireEvent, waitFor } from "@testing-library/react-native"import { StyleSheet } from "react-native"import { lightColors } from "@colota/shared"-import { size, space } from "../../../../constants"+import { HIT_SLOP_SM, size, space } from "../../../../constants"import { Divider } from "../../../ui/Divider"import { PointCard } from "../PointCard"@@ -11,6 +11,12 @@ jest.mock("../../../../services/modalService", () => ({showPrompt: (...args: unknown[]) => mockShowPrompt(...args)}))+const mockCopy = jest.fn()+jest.mock("../../../../services/NativeLocationService", () => ({+ __esModule: true,+ default: { copyToClipboard: (...args: unknown[]) => mockCopy(...args) }+}))+jest.mock("../../../../hooks/useTheme", () => ({useTheme: () => ({ colors: require("@colota/shared").lightColors })}))@@ -87,16 +93,17 @@ describe("PointCard", () => {}})- it("lists speed, accuracy, altitude and sync with a seam before each, and the note row last", () => {- const { getByLabelText, UNSAFE_getAllByType } = renderCard()+ it("lists coordinates, speed, accuracy, altitude and sync with a seam before each, and the note row last", () => {+ const { getByLabelText, getByTestId, UNSAFE_getAllByType } = renderCard()+ expect(getByTestId("point-coordinates").props.accessibilityLabel).toBe("Coordinates, 48.10000, 11.50000")expect(getByLabelText("Speed, 18.0 km/h")).toBeTruthy()expect(getByLabelText("Accuracy, ±8 m")).toBeTruthy()expect(getByLabelText("Altitude, 412 m")).toBeTruthy()expect(getByLabelText("Sync, Sent")).toBeTruthy()expect(getByLabelText("Note, Add a note").props.accessibilityRole).toBe("button")const dividers = UNSAFE_getAllByType(Divider)- expect(dividers).toHaveLength(5)+ expect(dividers).toHaveLength(6)for (const divider of dividers) {expect(divider.props.tight).toBe(true)expect(divider.props.inset).toBe(true)@@ -111,7 +118,23 @@ describe("PointCard", () => {expect(queryByLabelText(/^Speed/)).toBeNull()expect(queryByLabelText(/^Altitude/)).toBeNull()expect(getByLabelText("Accuracy, ±8 m")).toBeTruthy()- expect(UNSAFE_getAllByType(Divider)).toHaveLength(3)+ expect(UNSAFE_getAllByType(Divider)).toHaveLength(4)+ })++ // Finding where you were at a given time ends in pasting the position somewhere else.+ it("copies the coordinates as one lat, lon string a map app or search box accepts", () => {+ mockCopy.mockResolvedValueOnce(undefined)+ const { getByTestId } = renderCard({ point: { ...point, latitude: 48.137154, longitude: -11.575382 } })++ fireEvent.press(getByTestId("point-coordinates"))++ expect(mockCopy).toHaveBeenCalledWith("48.13715, -11.57538", "Coordinates")+ })++ it("keeps the copy row as short as the stat rows but widens its touch area past them", () => {+ const { getByTestId } = renderCard()++ expect(getByTestId("point-coordinates").props.hitSlop).toEqual(HIT_SLOP_SM)})it("hides the sync row without an endpoint, since nothing is queued anywhere", () => {diff --git a/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsxindex 86d6626c..ef6acb61 100644--- a/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx+++ b/apps/mobile/src/components/features/inspector/__tests__/TrackMap.test.tsx@@ -431,6 +431,16 @@ describe("TrackMap camera", () => {expect(mockFitBounds).toHaveBeenCalledTimes(2)})+ // Points logged in one spot sit metres apart; fitting them exactly would open the day at building level with no streets.+ it("widens a few-metre cluster to street level before fitting, around the same centre", () => {+ renderMap({ locations: [loc(52.5, 13.4), loc(52.50003, 13.40004)], fitVersion: 1 })++ const [[west, south, east, north]] = mockFitBounds.mock.calls[0]+ expect(east - west).toBeCloseTo(0.001, 6)+ expect((east + west) / 2).toBeCloseTo(13.40002, 6)+ expect([south, north]).toEqual([52.5, 52.50003])+ })+it("centres a lone point at a fixed zoom instead of fitting a zero-extent box", () => {renderMap({ locations: [loc(52.5, 13.4)], fitVersion: 1 })diff --git a/apps/mobile/src/components/features/map/__tests__/ColotaMapView.test.tsx b/apps/mobile/src/components/features/map/__tests__/ColotaMapView.test.tsxindex 5f976968..01536045 100644--- a/apps/mobile/src/components/features/map/__tests__/ColotaMapView.test.tsx+++ b/apps/mobile/src/components/features/map/__tests__/ColotaMapView.test.tsx@@ -71,6 +71,13 @@ describe("ColotaMapView camera padding", () => {mockCameraProps.mockClear()})+ // Points logged while standing still sit a few metres apart and only separate past street level.+ it("lets the camera zoom past street level so bunched points can be told apart", () => {+ render(<ColotaMapView initialCenter={center} />)++ expect(mockCameraProps.mock.calls[0][0].maxZoom).toBeGreaterThanOrEqual(20)+ })+it("frames the first camera inside the padding so the dock never covers the position dot", () => {render(<ColotaMapView initialCenter={center} cameraPadding={padding} />)diff --git a/apps/mobile/src/constants/index.ts b/apps/mobile/src/constants/index.tsindex d5778ee8..74cafacf 100644--- a/apps/mobile/src/constants/index.ts+++ b/apps/mobile/src/constants/index.ts@@ -77,7 +77,7 @@ export const elevation = {export const DEFAULT_MAP_ZOOM = 15export const WORLD_MAP_ZOOM = 2-export const MAX_MAP_ZOOM = 18+export const MAX_MAP_ZOOM = 22export const GEOFENCE_ZOOM_PADDING = [80, 80, 80, 80] as constexport const MAP_ANIMATION_DURATION_MS = 400export const LOADING_INDICATOR_DELAY_MS = 200diff --git a/apps/mobile/src/i18n/locales/en.json b/apps/mobile/src/i18n/locales/en.jsonindex 5ec464a5..ebd47fa6 100644--- a/apps/mobile/src/i18n/locales/en.json+++ b/apps/mobile/src/i18n/locales/en.json@@ -706,6 +706,8 @@"point.accuracy": "Accuracy","point.addNote": "Add a note","point.altitude": "Altitude",+ "point.coordinates": "Coordinates",+ "point.copyCoordinates": "Copies the coordinates","point.delete": "Delete point","point.note": "Note","point.queued": "Queued",diff --git a/apps/mobile/src/i18n/locales/es.json b/apps/mobile/src/i18n/locales/es.jsonindex 34ca2f0d..9fcc7c19 100644--- a/apps/mobile/src/i18n/locales/es.json+++ b/apps/mobile/src/i18n/locales/es.json@@ -706,6 +706,8 @@"point.accuracy": "Precisión","point.addNote": "Agregar una nota","point.altitude": "Altitud",+ "point.coordinates": "Coordenadas",+ "point.copyCoordinates": "Copia las coordenadas","point.delete": "Eliminar punto","point.note": "Nota","point.queued": "En cola",diff --git a/apps/mobile/src/i18n/locales/zh.json b/apps/mobile/src/i18n/locales/zh.jsonindex 6becda85..be1b16a3 100644--- a/apps/mobile/src/i18n/locales/zh.json+++ b/apps/mobile/src/i18n/locales/zh.json@@ -698,6 +698,8 @@"point.accuracy": "精度","point.addNote": "添加备注","point.altitude": "海拔",+ "point.coordinates": "坐标",+ "point.copyCoordinates": "复制坐标","point.delete": "删除点","point.note": "备注","point.queued": "已排队",diff --git a/fastlane/metadata/android/en-US/changelogs/52.txt b/fastlane/metadata/android/en-US/changelogs/52.txtindex 80d20319..c2e8c587 100644--- a/fastlane/metadata/android/en-US/changelogs/52.txt+++ b/fastlane/metadata/android/en-US/changelogs/52.txt@@ -5,5 +5,7 @@- A setup link applied while tracking now takes effect at once instead of after the next start- After a rate limit, sync waits as long as the server asks and Sync now says so- Tracking profiles can switch on Wi-Fi, either any network or one you name+- A selected point shows its coordinates; tap them to copy+- Maps zoom in further, so bunched points can be told apart- The profile editor no longer warns about a Stationary interval above 60 seconds- No more lost points after a Wi-Fi drop at home