Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing notifications for Location Services #64

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 47 additions & 10 deletions app/services/LocationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
SetStoreData
} from '../helpers/General';
import BackgroundGeolocation from '@mauron85/react-native-background-geolocation';
import { Alert } from 'react-native';

var instanceCount = 0;
var lastPointCount = 0;
Expand Down Expand Up @@ -64,17 +65,17 @@ export default class LocationServices {
desiredAccuracy: BackgroundGeolocation.HIGH_ACCURACY,
stationaryRadius: 50,
distanceFilter: 50,
notificationTitle: 'PrivateKit Enabled',
notificationText: 'PrivateKit is recording path information on this device.',
notificationTitle: 'Private Kit Enabled',
notificationText: 'Private Kit is securely storing your GPS coordinates once every five minutes on this device.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might not say securely storing as we are not encrypting the coordinates, they are stored in raw format. However, no other app can access it so it is good as well.

debug: false, // when true, it beeps every time a loc is read
startOnBoot: false,
stopOnTerminate: false,
locationProvider: BackgroundGeolocation.ACTIVITY_PROVIDER,

// DEBUG: Use these to get a faster output
// interval: 2000,
// fastestInterval: 2000, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes
// activitiesInterval: 2000,
/*interval: 2000,
fastestInterval: 2000, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes
activitiesInterval: 2000,*/

interval: 20000,
fastestInterval: 60000 * 5, // Time (in milliseconds) between location information polls. E.g. 60000*5 = 5 minutes
Expand Down Expand Up @@ -120,7 +121,7 @@ export default class LocationServices {
BackgroundGeolocation.on('stationary', (stationaryLocation) => {
// handle stationary locations here
// Actions.sendLocation(stationaryLocation);
BackgroundGeolocation.startTask(taskKey => {
BackgroundGeolocation.startTask(taskKey => {
// execute long running task
// eg. ajax post location
// IMPORTANT: task has to be ended by endTask
Expand All @@ -144,10 +145,11 @@ export default class LocationServices {

BackgroundGeolocation.on('authorization', (status) => {
console.log('[INFO] BackgroundGeolocation authorization status: ' + status);

if (status !== BackgroundGeolocation.AUTHORIZED) {
// we need to set delay or otherwise alert may not be shown
setTimeout(() =>
Alert.alert('App requires location tracking permission', 'Would you like to open app settings?', [{
Alert.alert('Private Kit requires access to location information', 'Would you like to open app settings?', [{
text: 'Yes',
onPress: () => BackgroundGeolocation.showAppSettings()
},
Expand All @@ -158,6 +160,12 @@ export default class LocationServices {
}
]), 1000);
}
else {
BackgroundGeolocation.start(); //triggers start on start event

// TODO: We reach this point on Android when location services are toggled off/on.
// When this fires, check if they are off and show a Notification in the tray
}
});

BackgroundGeolocation.on('background', () => {
Expand Down Expand Up @@ -195,10 +203,39 @@ export default class LocationServices {
console.log('[INFO] BackgroundGeolocation services enabled', status.locationServicesEnabled);
console.log('[INFO] BackgroundGeolocation auth status: ' + status.authorization);

// you don't need to check status before start (this is just the example)
if (!status.isRunning) {
BackgroundGeolocation.start(); //triggers start on start event
BackgroundGeolocation.start(); //triggers start on start event

if (!status.locationServicesEnabled) {
// we need to set delay or otherwise alert may not be shown
setTimeout(() =>
Alert.alert('Private Kit requires location services to be enabled', 'Would you like to open location settings?', [{
text: 'Yes',
onPress: () => BackgroundGeolocation.showLocationSettings()
},
{
text: 'No',
onPress: () => console.log('No Pressed'),
style: 'cancel'
}
]), 1000);
}
else if (!status.authorization) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I don't authorize and press Yes for settings, then I end up at App settings which doesn't have location information anywhere.

// we need to set delay or otherwise alert may not be shown
setTimeout(() =>
Alert.alert('Private Kit requires access to location information', 'Would you like to open app settings?', [{
text: 'Yes',
onPress: () => BackgroundGeolocation.showAppSettings()
},
{
text: 'No',
onPress: () => console.log('No Pressed'),
style: 'cancel'
}
]), 1000);
}
else if (!status.isRunning) {
}

});

// you can also just start without checking for status
Expand Down
11 changes: 5 additions & 6 deletions app/views/Export.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
Linking,
View,
Text,
Alert,
Image
} from 'react-native';

Expand Down Expand Up @@ -46,10 +45,10 @@ class ExportScreen extends Component {

b64Data = base64.encode(JSON.stringify(locationData));
Share.open({
url: "data:string/txt;base64," + b64Data
}).then(res => {
console.log(res);
})
url: "data:string/txt;base64," + b64Data
}).then(res => {
console.log(res);
})
.catch(err => {
console.log(err.message, err.code);
})
Expand Down Expand Up @@ -79,7 +78,7 @@ class ExportScreen extends Component {
<View style={styles.block}>
<Button onPress={this.onShare} title="Share" />
</View>
<Text style={styles.mainText}>Points to be shared: { LocationServices.getPointCount() }</Text>
<Text style={styles.mainText}>Points to be shared: {LocationServices.getPointCount()}</Text>
</View>

</SafeAreaView>
Expand Down
18 changes: 9 additions & 9 deletions app/views/Import.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ import {
ScrollView,
Linking,
View,
Text,
Alert
Text
} from 'react-native';

import colors from "../constants/colors";
import WebView from 'react-native-webview';
import Button from "../components/Button";

import {SearchAndImport} from '../helpers/GoogleTakeOutAutoImport';
import {
SearchAndImport
} from '../helpers/GoogleTakeOutAutoImport';

class ImportScreen extends Component {
constructor(props) {
Expand All @@ -29,8 +30,7 @@ class ImportScreen extends Component {

}

componentWillUnmount() {
}
componentWillUnmount() { }

backToMain() {
this.props.navigation.navigate('LocationTrackingScreen', {})
Expand All @@ -47,13 +47,13 @@ class ImportScreen extends Component {

<View style={styles.main}>
<View style={styles.subHeaderTitle}>
<Text style={styles.sectionDescription, { fontSize: 18, marginTop: 8}}>1. Login to your Google Account and Download your Location History</Text>
<Text style={styles.sectionDescription, { fontSize: 18, marginTop: 8}}>2. After downloaded, open this screen again. The data will import automatically.</Text>
<Text style={styles.sectionDescription, { fontSize: 18, marginTop: 8 }}>1. Login to your Google Account and Download your Location History</Text>
<Text style={styles.sectionDescription, { fontSize: 18, marginTop: 8 }}>2. After downloaded, open this screen again. The data will import automatically.</Text>
</View>
<View style={styles.web}>
<WebView
source= {{ uri: 'https://takeout.google.com/settings/takeout/custom/location_history' }}
style= {{ marginTop: 15 }}
source={{ uri: 'https://takeout.google.com/settings/takeout/custom/location_history' }}
style={{ marginTop: 15 }}
/>
</View>
</View>
Expand Down
7 changes: 3 additions & 4 deletions app/views/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
ScrollView,
Linking,
View,
Text,
Alert
Text
} from 'react-native';

import colors from "../constants/colors";
Expand All @@ -35,8 +34,8 @@ class NewsScreen extends Component {
<Text style={styles.sectionDescription}>Latest News</Text>
</View>
<WebView
source= {{ uri: 'https://privatekit.mit.edu/views' }}
style= {{ marginTop: 15}}
source={{ uri: 'https://privatekit.mit.edu/views' }}
style={{ marginTop: 15 }}
/>
</SafeAreaView>
)
Expand Down