From e41593805afd85a3945eaff678794c63aae697fa Mon Sep 17 00:00:00 2001 From: StackOverflowIsBetterThanAnyAI Date: Fri, 20 Nov 2026 13:08:09 +0100 Subject: [PATCH 1/2] v1.2.1 --- app.json | 2 +- package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app.json b/app.json index 2be3c65..edd6c15 100644 --- a/app.json +++ b/app.json @@ -2,7 +2,7 @@ "expo": { "name": "Security Application", "slug": "security-app", - "version": "1.2.0", + "version": "1.2.1", "orientation": "portrait", "icon": "./assets/images/icon.png", "scheme": "securityapp", diff --git a/package-lock.json b/package-lock.json index c08be60..3902948 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "security-app", - "version": "1.2.0", + "version": "1.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "security-app", - "version": "1.2.0", + "version": "1.2.1", "dependencies": { "@expo/vector-icons": "^15.1.1", "@react-native-async-storage/async-storage": "^2.2.0", diff --git a/package.json b/package.json index 950658f..5f4618c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "security-app", "main": "expo-router/entry", - "version": "1.2.0", + "version": "1.2.1", "scripts": { "start": "expo start --go", "android": "expo start --android", From 39e97dcf43c634ea96cc731cc893b2fea4383171 Mon Sep 17 00:00:00 2001 From: StackOverflowIsBetterThanAnyAI Date: Fri, 20 Nov 2026 13:13:36 +0100 Subject: [PATCH 2/2] timelapse for each day --- app/(tabs)/gallery.tsx | 10 ++ components/icon-symbol.tsx | 2 + components/timelapse-player.tsx | 303 ++++++++++++++++++++++++++++++++ 3 files changed, 315 insertions(+) create mode 100644 components/timelapse-player.tsx diff --git a/app/(tabs)/gallery.tsx b/app/(tabs)/gallery.tsx index eff5657..ceb094e 100644 --- a/app/(tabs)/gallery.tsx +++ b/app/(tabs)/gallery.tsx @@ -19,6 +19,7 @@ import ImageGrid from '@/components/image-grid' import MainView from '@/components/main-view' import Pagination from '@/components/pagination' import ThemedText from '@/components/themed-text' +import TimelapsePlayer from '@/components/timelapse-player' import { ITEMS_PER_PAGE } from '@/constants/api' import { ContextError } from '@/context/ContextError' import { ContextImageRotation } from '@/context/ContextImageRotation' @@ -247,6 +248,15 @@ const GalleryScreen = () => { ) : selectedDay && images ? ( <> + day.date === selectedDay) + ?.thumbnail + } + userToken={userToken} + /> {actions} { + const match = /_(\d{2})-(\d{2})-\d{2}\.jpg$/.exec(uri) + return match ? `${match[1]}:${match[2]}` : '' +} + +const fetchDayImages = async (day: string, headers: Record) => { + const paths: string[] = [] + let page = 1 + let total = Infinity + + while (paths.length < total) { + const controller = new AbortController() + const timeoutId = setTimeout(() => controller.abort(), API_TIMEOUT_MS) + try { + const response = await fetch( + `${URL}/images?day=${day}&page=${page}`, + { headers, signal: controller.signal } + ) + if (!response.ok) { + throw new Error(`Error ${response.status}`) + } + const data: { images: string[]; total_images: number } = + await response.json() + total = data.total_images + if (!data.images.length) { + break + } + paths.push(...data.images) + page++ + } finally { + clearTimeout(timeoutId) + } + } + + return paths.map((path) => `${URL}${encodeURI(path)}`) +} + +const TimelapsePlayer = ({ + day, + thumbnail, + userToken, +}: TimelapsePlayerProps) => { + const contextImageRotation = useContext(ContextImageRotation) + if (!contextImageRotation) { + throw new Error( + 'TimelapsePlayer must be used within a ContextImageRotation.Provider' + ) + } + const { imageRotation } = contextImageRotation + + const barColor = useThemeColor( + { light: Colors.dark.highlight }, + 'highlight' + ) + const barTextColor = useThemeColor({}, 'textLight') + const borderColor = useThemeColor({}, 'border') + const highlightColor = useThemeColor({}, 'highlight') + + const headers = useMemo( + () => ({ Authorization: `Bearer ${userToken}` }), + [userToken] + ) + + const [frames, setFrames] = useState([]) + const [index, setIndex] = useState(0) + const [loaded, setLoaded] = useState(0) + const [status, setStatus] = useState('idle') + const [thumbnailFailed, setThumbnailFailed] = useState(false) + + const isMounted = useRef(true) + const loadedRef = useRef(0) + + useEffect(() => { + isMounted.current = true + return () => { + isMounted.current = false + } + }, []) + + const loadFrames = async () => { + setStatus('loading') + setFrames([]) + setIndex(0) + setLoaded(0) + loadedRef.current = 0 + + try { + const uris = await fetchDayImages(day, headers) + if (!isMounted.current) { + return + } + if (!uris.length) { + throw new Error('No images') + } + setFrames(uris) + + const done = new Array(uris.length).fill(false) + let next = 0 + let contiguous = 0 + + const worker = async () => { + while (isMounted.current && next < uris.length) { + const current = next++ + await Image.prefetch(uris[current], { + cachePolicy: 'memory-disk', + headers, + }).catch(() => false) + done[current] = true + while (contiguous < uris.length && done[contiguous]) { + contiguous++ + } + if (isMounted.current) { + loadedRef.current = contiguous + setLoaded(contiguous) + if ( + contiguous >= + Math.min(FRAMES_BEFORE_START, uris.length) + ) { + setStatus((status) => + status === 'loading' ? 'playing' : status + ) + } + } + } + } + + await Promise.all( + Array.from({ length: PREFETCH_CONCURRENCY }, worker) + ) + } catch { + if (isMounted.current) { + setStatus('error') + } + } + } + + useEffect(() => { + if (status !== 'playing' || !frames.length) { + return + } + const interval = setInterval(() => { + setIndex((current) => { + const next = (current + 1) % frames.length + return next !== 0 && next >= loadedRef.current ? current : next + }) + }, 1000 / FRAMES_PER_SECOND) + return () => clearInterval(interval) + }, [frames.length, status]) + + useFocusEffect( + useCallback(() => { + return () => { + setStatus((current) => + current === 'playing' ? 'paused' : current + ) + } + }, []) + ) + + const handlePress = () => { + if (status === 'idle' || status === 'error') { + loadFrames() + } else if (status === 'playing') { + setStatus('paused') + } else if (status === 'paused') { + setStatus('playing') + } + } + + const showFrames = frames.length > 0 && status !== 'error' + const imageSource = showFrames + ? { uri: frames[index], headers } + : thumbnail && !thumbnailFailed + ? { uri: `${URL}${encodeURI(thumbnail)}`, headers } + : errorImageSource + + const isBuffering = + status === 'playing' && loaded < frames.length && index + 1 >= loaded + + const label = + status === 'loading' + ? `Loading ${loaded} / ${frames.length || '…'}` + : status === 'error' + ? 'Timelapse unavailable, tap to retry' + : status === 'idle' + ? 'Timelapse' + : frameTime(frames[index]) + + const accessibilityLabel = + status === 'playing' + ? 'Pause Timelapse' + : status === 'paused' + ? `Resume Timelapse, paused at ${frameTime(frames[index])}` + : status === 'loading' + ? 'Loading Timelapse' + : `Play Timelapse of ${formatDay(day)}` + + const styles = StyleSheet.create({ + bar: { + alignItems: 'center', + backgroundColor: barColor, + bottom: 0, + flexDirection: 'row', + gap: 8, + left: 0, + paddingHorizontal: 12, + paddingVertical: 6, + position: 'absolute', + right: 0, + }, + image: { + aspectRatio: 16 / 9, + backgroundColor: highlightColor, + transform: [{ rotate: `${imageRotation}deg` }], + width: '100%', + }, + label: { + color: barTextColor, + flex: 1, + }, + wrapper: { + borderColor, + borderRadius: 12, + borderWidth: 2, + overflow: 'hidden', + }, + }) + + return ( + [ + styles.wrapper, + { opacity: pressed ? 0.75 : 1 }, + ]} + > + {`Timelapse { + if (!showFrames) { + setThumbnailFailed(true) + } + }} + source={imageSource} + style={styles.image} + /> + + {status === 'loading' || isBuffering ? ( + + ) : ( + + )} + {label} + + + ) +} + +export default TimelapsePlayer