This commit is contained in:
Ren Juan 2021-08-28 16:33:29 +00:00
parent cb5076fd0f
commit 81ff54af6b
3 changed files with 69 additions and 6 deletions

View File

@ -5,6 +5,7 @@ import { StyleSheet } from 'react-native';
import * as geolib from 'geolib';
var debug:number = 0;
var endIsNigh:boolean = false;
var testCount = 0;
var bgEnabled:boolean = false;
var expoGeoState:any = null;
@ -16,6 +17,9 @@ export var locEnabled:boolean = false;
const geoLibAccuracy:number = 0.1;
const minExpoAccuracy:number = 10;
export function getEndIsLast() : boolean { return endIsNigh; }
export function setEndIsLast(value:boolean) { endIsNigh = value; }
const styles = StyleSheet.create({
tripText: {
marginHorizontal: -10,
@ -211,6 +215,19 @@ export class GT2 {
}
public from(last:GT2) {
this.startPoint = last.startPoint;
this.trip.loc = last.trip.loc;
this.elapsed = last.elapsed;
this.endPoint = last.endPoint;
this.CO2Effect = last.CO2Effect;
this.co2Rate = last.co2Rate;
this.units = last.units;
this.sensitivity = last.sensitivity;
}
public setLocEnabled(value:boolean) { locEnabled = value}
public pause() {
@ -255,8 +272,8 @@ export class GT2 {
return (
'Elapsed - ' + this.trip.elapsed + '\n' +
'Origin: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
'Origin: ' + 'lat: ' + this.startPoint.mLatitude.toFixed(8) +
' long: ' + this.startPoint.mLongitude.toFixed(8) + '\n' +
'Destination: ' + 'lat: ' + this.trip.loc.mLatitude.toFixed(8) +
' long: ' + this.trip.loc.mLongitude.toFixed(8) + '\n' +
'CO2: ' + this.trip.CO2.toFixed(1) + ' grams ' + this.CO2Effect + '\n\n' +
@ -339,6 +356,16 @@ export class TripSummary extends React.Component {
render() {
if (endIsNigh) {
setEndIsLast(false);
return(
<View>
<Text style={styles.tripText}>
{LastTrip.getTripSummary() }
</Text>
</View> );
} else
return(
<View>
<Text style={styles.tripText}>
@ -350,4 +377,5 @@ export class TripSummary extends React.Component {
}
export var Trips:GT2 = new GT2();
export var Trips:GT2 = new GT2();
export var LastTrip:GT2 = new GT2();

View File

@ -21,6 +21,7 @@
],
"ios": {
"supportsTablet": true,
"buildNumber": "2",
"infoPlist": {
"UIBackgroundModes": [
"location",

View File

@ -3,7 +3,7 @@ import { useState } from 'react';
import { Alert, BackHandler, Button, StyleSheet } from 'react-native';
import { Text, View } from '../components/Themed';
import { ScreenInfo2 } from '../components/ScreenInfo';
import { locEnabled, TripDisplay, Trips } from '../GT2';
import { locEnabled, TripDisplay, LastTrip, Trips } from '../GT2';
import { RootTabScreenProps } from '../types';
import { getAdvised, setAdvised } from './ModalScreen';
@ -61,6 +61,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
const [sButtonText, setSButtonText] = useState("Start");
const [pButtonText, setPButtonText] = useState("Pause");
if (Trips.nTrips < 1)
return (
<View style={styles.container}>
<Text style={styles.title}>Trip Control</Text>
@ -71,7 +72,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
title={sButtonText}
onPress={() => {
if (!getAdvised()) {
Alert.alert("Note: GT2 2.0.n doesn't run in background.");
Alert.alert("Note:GT2 2.0.n doesn't run in background.");
setAdvised();
}
if (!Trips.inProgress) {startTrip();
@ -90,6 +91,39 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
<TripDisplay></TripDisplay>
</View>
);
else;
return (
<View style={styles.container}>
<Text style={styles.title}>Trip Control</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<ScreenInfo2 />
<View style={styles.controls} >
<Button
title={sButtonText}
onPress={() => {
if (!getAdvised()) {
Alert.alert("Note:GT2 2.0.n doesn't run in background.");
setAdvised();
}
if (!Trips.inProgress) {startTrip();
if (Trips.inProgress) { setSButtonText("End"); setPButtonText('Pause');}}
else {setSButtonText('Start'); endTrip(); LastTrip.from(Trips); navigation.push('Modal'); }}
}
/>
<Button
title={pButtonText}
onPress={() => { if (!Trips.inProgress) Alert.alert("No trip in progress!"); else {
if (!Trips.paused) {setPButtonText("Resume");pauseTrip();}
else {setPButtonText('Pause');pauseTrip();}}}
}
/>
</View>
<TripDisplay></TripDisplay>
<View>
<Button title={'Show Last Trip'} onPress={() => { navigation.push('Modal'); } } />
</View>
</View>
);
}