diff --git a/Ejectable/BGEO.js b/Ejectable/BGEO.js index 935e595d..77a91a97 100644 --- a/Ejectable/BGEO.js +++ b/Ejectable/BGEO.js @@ -1,37 +1,40 @@ import React from 'react'; +import { useState } from 'react'; import { StyleSheet } from 'react-native'; -import { Pressable } from 'react-native'; +import { Alert, Pressable } from 'react-native'; import { Text, View } from './components/Themed.tsx'; import * as TaskManager from 'expo-task-manager'; import * as Location from 'expo-location'; import { bgOps, Trips, setBgOps } from './GT2'; -const LOCATION_TASK_NAME = 'background-location-task'; +const BACKGROUND_LOCATION_TRACKER = 'BACKGROUND_LOCATION_TRACKER' - const requestPermissions = async () => { - if (!locEnabled) { +const getUpdates = async () => { - const { status } = await Location.requestBackgroundPermissionsAsync(); - if (status === 'granted') { - await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, { - accuracy: Location.Accuracy.Balanced, + await Location.startLocationUpdatesAsync(BACKGROUND_LOCATION_TRACKER , { + accuracy: Location.Accuracy.Highest }); - setBgOps(true); - } - else setBgOps(false); - - } - + }; export default function PermissionsButton() { + + const [fuBgOps, setfuBgOps] = useState(0); + + const requestPermissions = async () => { + const { status } = await Location.requestBackgroundPermissionsAsync(); + setBgOps((status === 'granted')); + setfuBgOps(fuBgOps => fuBgOps + 1); + }; + if (!bgOps) return( - + {'Enable background operations'} - {' (Only used during a trip)'} + {' (Only used during a trip)'} ); else @@ -42,25 +45,26 @@ export default function PermissionsButton() { } -TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => { +TaskManager.defineTask(BACKGROUND_LOCATION_TRACKER , async ({ data, error }) => { if (error) { // Error occurred - check `error.message` for more details. console.log(error.message); return; } - if (data) { - const { locations } = data; - Trips.deltaLoc( locations ); - } + if (data) { + const { location } = data; + Trips.deltaLoc( location ); + } + }); const styles = StyleSheet.create({ container: { marginVertical: 2, - marginTop: -40, - marginBottom: 25, + marginTop: -20, + marginBottom: 15, alignItems: 'center', }, button: { @@ -68,10 +72,12 @@ const styles = StyleSheet.create({ backgroundColor: 'lime', }, text: { + fontSize: 14, + fontWeight: 'bold', color: "blue", }, text2: { - fontSize: 8, + fontSize: 10, color: "navy", } }); diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx index 4dcd5b32..8a571015 100644 --- a/Ejectable/screens/TripScreen.tsx +++ b/Ejectable/screens/TripScreen.tsx @@ -56,12 +56,13 @@ function pauseTrip() { } + function endTrip() { Trips.end(); } export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>) { - const [sButtonText, setSButtonText] = useState("Start"); - const [pButtonText, setPButtonText] = useState("Pause"); + const [sButtonText, setSButtonText] = useState("Start"); + const [pButtonText, setPButtonText] = useState("Pause"); if (Trips.nTrips < 1) return (