This commit is contained in:
Ren Juan 2021-08-30 21:05:06 +00:00
parent a763ef9d5f
commit a8bd22c0a3
4 changed files with 25 additions and 31 deletions

View File

@ -4,7 +4,7 @@ import { Pressable } from 'react-native';
import { Text, View } from './components/Themed.tsx'; import { Text, View } from './components/Themed.tsx';
import * as TaskManager from 'expo-task-manager'; import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location'; import * as Location from 'expo-location';
import { Trips, setBgOps } from './GT2'; import { bgOps, Trips, setBgOps } from './GT2';
const LOCATION_TASK_NAME = 'background-location-task'; const LOCATION_TASK_NAME = 'background-location-task';
@ -26,12 +26,20 @@ const LOCATION_TASK_NAME = 'background-location-task';
}; };
export default function PermissionsButton() { export default function PermissionsButton() {
if (!bgOps)
return( return(
<View style={styles.container} lightColor="lime" darkColor="forestgreen"> <View style={styles.container} lightColor="lime" darkColor="forestgreen">
<Pressable style={styles.button} onPress={requestPermissions}> <Pressable style={styles.button} onPress={requestPermissions}>
<Text style={styles.text}>{'Enable background operations'}</Text> <Text style={styles.text}>{'Enable background operations'}</Text>
<Text style={styles.text2}>{' (Only used during a trip)'}</Text>
</Pressable> </Pressable>
</View>); </View>);
else
return(
<View style={styles.container} lightColor="lime" darkColor="forestgreen">
<Text style={styles.text}>{'Trips can run in background.'}</Text>
</View>);
} }
TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => { TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
@ -50,12 +58,20 @@ TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
marginVertical: 20, marginVertical: 2,
marginBottom: -30, marginTop: -40,
marginBottom: 25,
alignItems: 'center', alignItems: 'center',
}, },
button: { button: {
fontSize: 10, fontSize: 10,
backgroundColor: 'lime', backgroundColor: 'lime',
}, },
text: {
color: "blue",
},
text2: {
fontSize: 8,
color: "navy",
}
}); });

View File

@ -35,7 +35,8 @@
"permissions": [ "permissions": [
"ACCESS_COARSE_LOCATION", "ACCESS_COARSE_LOCATION",
"ACCESS_FINE_LOCATION", "ACCESS_FINE_LOCATION",
"FOREGROUND_SERVICE" "FOREGROUND_SERVICE",
"ACCESS_BACKGROUND_LOCATION"
], ],
"adaptiveIcon": { "adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png", "foregroundImage": "./assets/images/adaptive-icon.png",

View File

@ -2,8 +2,7 @@ import React from 'react';
import { StyleSheet, TouchableOpacity } from 'react-native'; import { StyleSheet, TouchableOpacity } from 'react-native';
import { Text, View } from './Themed'; import { Text, View } from './Themed';
import * as Device from 'expo-device'; import * as Device from 'expo-device';
import { bgOps, ver } from '../GT2'; import { ver } from '../GT2';
import PermissionsButton from '../BGEO';
export default function ScreenInfo() { export default function ScreenInfo() {
return ( return (
@ -56,7 +55,6 @@ export function ScreenInfo5() {
} }
export function ScreenInfo3() { export function ScreenInfo3() {
if (bgOps)
return ( return (
<View style={styles.splashContainer}> <View style={styles.splashContainer}>
<Text <Text
@ -79,30 +77,6 @@ export function ScreenInfo3() {
</Text> </Text>
</View> </View>
); );
else
return (
<View style={styles.splashContainer}>
<Text
style={styles.titleText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
{'Green Travel Calculator v. ' + ver }
</Text>
<Text
style={styles.versionText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
expo {Device.osName == 'iOS' ? 'iOS ' : 'android '} version
</Text>
<PermissionsButton />
<Text
style={styles.cautionText}
lightColor="rgba(0,0,0,0.8)"
darkColor="rgba(255,255,255,0.8)">
{'\nNote: accuracy depends on sensitivity setting, your device, and carrier.'}
</Text>
</View>
);
} }
const styles = StyleSheet.create({ const styles = StyleSheet.create({

View File

@ -6,6 +6,7 @@ import { ScreenInfo2 } from '../components/ScreenInfo';
import { bgOps, TripDisplay, LastTrip, Trips, setEndIsLast } from '../GT2'; import { bgOps, TripDisplay, LastTrip, Trips, setEndIsLast } from '../GT2';
import { RootTabScreenProps } from '../types'; import { RootTabScreenProps } from '../types';
import * as Device from 'expo-device'; import * as Device from 'expo-device';
import PermissionsButton from '../BGEO';
var debug:number = 0; var debug:number = 0;
@ -65,6 +66,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
if (Trips.nTrips < 1) if (Trips.nTrips < 1)
return ( return (
<View style={styles.container}> <View style={styles.container}>
<PermissionsButton />
<Text style={styles.title}>Trip Control</Text> <Text style={styles.title}>Trip Control</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<ScreenInfo2 /> <ScreenInfo2 />
@ -91,6 +93,7 @@ export default function TripScreen( { navigation }: RootTabScreenProps<'Trip'>)
else else
return ( return (
<View style={styles.container}> <View style={styles.container}>
<PermissionsButton />
<Text style={styles.title}>Trip Control</Text> <Text style={styles.title}>Trip Control</Text>
<View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" /> <View style={styles.separator} lightColor="#eee" darkColor="rgba(255,255,255,0.1)" />
<ScreenInfo2 /> <ScreenInfo2 />