From 470c2316955df718439d20057f3d53423dc329bb Mon Sep 17 00:00:00 2001 From: Ren Juan Date: Mon, 30 Aug 2021 00:19:58 +0000 Subject: [PATCH] stub 2.0.8 --- Ejectable/App.tsx | 21 ++++++++++++--------- Ejectable/GT2.tsx | 11 ++++++----- Ejectable/app.json | 4 ++-- Ejectable/components/ScreenInfo.tsx | 28 +++++++++++++++++++++++++++- Ejectable/screens/TripScreen.tsx | 23 ++++++++--------------- Ejectable/tsconfig.json | 2 +- 6 files changed, 56 insertions(+), 33 deletions(-) diff --git a/Ejectable/App.tsx b/Ejectable/App.tsx index d30b4a49..c162a88d 100644 --- a/Ejectable/App.tsx +++ b/Ejectable/App.tsx @@ -20,12 +20,15 @@ export function setAdvised() : void { advised = true; } export default function App() { const isLoadingComplete = useCachedResources(); const colorScheme = useColorScheme(); + const [isKM, setIsKM] = useState(false); const toggleUnits = () => setIsKM(previousState => !previousState); - const [location, setLocation] = useState(Object); - const [errorMsg, setErrorMsg] = useState(""); + + + const [location, setLocation] = useState(Object); + const [errorMsg, setErrorMsg] = useState(""); - useEffect(() => { + useEffect(() => { (async () => { let { status } = await Location.requestForegroundPermissionsAsync(); if (status !== 'granted') { @@ -41,15 +44,15 @@ export default function App() { Trips.deltaLoc(location); } })(); - }, []); + }, []); - expoGeoState = 'Waiting..'; - if (errorMsg) { + expoGeoState = 'Waiting..'; + if (errorMsg) { expoGeoState = errorMsg; - } else if (location) { + } else if (location) { expoGeoState = JSON.stringify(location); - } - + } + if (!isLoadingComplete) { return null; diff --git a/Ejectable/GT2.tsx b/Ejectable/GT2.tsx index 420e02f6..6ee7d5e7 100644 --- a/Ejectable/GT2.tsx +++ b/Ejectable/GT2.tsx @@ -4,11 +4,11 @@ import { Text, View } from './components/Themed'; import { StyleSheet } from 'react-native'; import * as geolib from 'geolib'; -export const ver:string = "2.0.7" +export const ver:string = "2.0.8" var debug:number = 0; var endIsNigh:boolean = false; var testCount = 0; - var bgEnabled:boolean = false; +export var bgOps:boolean = false; var expoGeoState:any = null; export var locEnabled:boolean = false; @@ -20,7 +20,8 @@ export var locEnabled:boolean = false; const minExpoAccuracy:number = 5; export function getEndIsLast() : boolean { return endIsNigh; } -export function setEndIsLast(value:boolean) { endIsNigh = value; } +export function setBgOps(value:boolean) { bgOps = value; } +export function setEndIsLast(value:boolean) { endIsNigh = value; } const styles = StyleSheet.create({ tripText: { @@ -133,7 +134,7 @@ class Trip { } public start() { this.interval = setInterval(() => this.tick(), heartbeat); - if (!bgEnabled) startTracking(this); + if (!bgOps) startTracking(this); } public resume() { this.lastFix.mLatitude = 0.0; @@ -143,7 +144,7 @@ class Trip { public stop() { Trips.distance += this.ds; this.ds = 0.0; clearInterval(this.interval); - if (!bgEnabled) stopTracking(this); + if (!bgOps) stopTracking(this); } } diff --git a/Ejectable/app.json b/Ejectable/app.json index 4f74adc8..762b8189 100644 --- a/Ejectable/app.json +++ b/Ejectable/app.json @@ -2,7 +2,7 @@ "expo": { "name": "GT2 Green Travel Carbon App", "slug": "GT2standalone", - "version": "2.0.7", + "version": "2.0.8", "orientation": "default", "description": "Travel Carbon Footprint (simplified version)", "icon": "./assets/images/icon.png", @@ -22,7 +22,7 @@ "ios": { "supportsTablet": true, "bundleIdentifier": "app.greentravel.gt2", - "buildNumber": "3", + "buildNumber": "4", "infoPlist": { "UIBackgroundModes": [ "location", diff --git a/Ejectable/components/ScreenInfo.tsx b/Ejectable/components/ScreenInfo.tsx index d3d52023..02951de0 100644 --- a/Ejectable/components/ScreenInfo.tsx +++ b/Ejectable/components/ScreenInfo.tsx @@ -2,7 +2,8 @@ import React from 'react'; import { StyleSheet, TouchableOpacity } from 'react-native'; import { Text, View } from './Themed'; import * as Device from 'expo-device'; -import { ver } from '../GT2'; +import { bgOps, ver } from '../GT2'; +import PermissionsButton from '../BGEO'; export default function ScreenInfo() { return ( @@ -55,6 +56,7 @@ export function ScreenInfo5() { } export function ScreenInfo3() { + if (bgOps) return ( ); + else + return ( + + + {'Green Travel Calculator v. ' + ver } + + + expo {Device.osName == 'iOS' ? 'iOS ' : 'android '} version + + + + {'\nNote: accuracy depends on sensitivity setting, your device, and carrier.'} + + + ); } const styles = StyleSheet.create({ diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx index 0174ce4c..616e830b 100644 --- a/Ejectable/screens/TripScreen.tsx +++ b/Ejectable/screens/TripScreen.tsx @@ -1,11 +1,11 @@ import * as React from 'react'; import { useState } from 'react'; -import { Alert, BackHandler, Button, StyleSheet } from 'react-native'; +import { Alert, Button, StyleSheet } from 'react-native'; import { Text, View } from '../components/Themed'; import { ScreenInfo2 } from '../components/ScreenInfo'; -import { ver, locEnabled, TripDisplay, LastTrip, Trips, setEndIsLast } from '../GT2'; +import { bgOps, TripDisplay, LastTrip, Trips, setEndIsLast } from '../GT2'; import { RootTabScreenProps } from '../types'; -import { getAdvised, setAdvised } from './ModalScreen'; +import * as Device from 'expo-device'; var debug:number = 0; @@ -32,11 +32,12 @@ const styles = StyleSheet.create({ }); -function startTrip() { +function startTrip() { - if (!locEnabled) { - Alert.alert("Location services unavailable can't start trip."); - return; + if (!bgOps) { + if (Device.osName === 'iOS') + Alert.alert("Background location not enabled. Must be in foreground and awake during trip!"); + else Alert.alert('Stay in foreground, awake during trip!'); } Trips.start(); @@ -71,10 +72,6 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)