Skip to content

Commit

Permalink
Refactor deminsions and constant vars
Browse files Browse the repository at this point in the history
  • Loading branch information
denispapakul committed Apr 9, 2020
1 parent 802d916 commit 3f43089
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 53 deletions.
3 changes: 2 additions & 1 deletion app/Entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import AboutScreen from './views/About';
import ChooseProviderScreen from './views/ChooseProvider';

import { GetStoreData, SetStoreData } from './helpers/General';
import { PARTICIPATE } from './constants/storage';

const Stack = createStackNavigator();

Expand All @@ -36,7 +37,7 @@ class Entry extends Component {
}

componentDidMount() {
GetStoreData('PARTICIPATE')
GetStoreData(PARTICIPATE)
.then(isParticipating => {
console.log(isParticipating);
this.setState({
Expand Down
5 changes: 3 additions & 2 deletions app/components/ButtonWrapper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import { StyleSheet, Dimensions, View } from 'react-native';
import Button from './Button';
import PropTypes from 'prop-types';
import fontFamily from '../constants/fonts';
import { width } from '../helpers/Constants';

const width = Dimensions.get('window').width;

class ButtonWrapper extends React.Component {
render() {
Expand Down
6 changes: 6 additions & 0 deletions app/constants/storage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const LOCATION_DATA = 'LOCATION_DATA';
export const CONTACT_DATA = 'CONTACT_DATA';
export const PARTICIPATE = 'PARTICIPATE';
export const MY_UUIDs = 'MY_UUIDs';
export const CROSSED_PATHS = 'CROSSED_PATHS';
export const LANG_OVERRIDE = 'LANG_OVERRIDE';
3 changes: 0 additions & 3 deletions app/helpers/Constants.js

This file was deleted.

5 changes: 3 additions & 2 deletions app/helpers/GoogleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Import a Google JSon into the Database.
*/
import { GetStoreData, SetStoreData } from '../helpers/General';
import { LOCATION_DATA } from '../constants/storage';

function BuildLocalFormat(placeVisit) {
return (loc = {
Expand Down Expand Up @@ -52,7 +53,7 @@ function Merge(localDataJSON, googleDataJSON) {
}

export async function MergeJSONWithLocalData(googleDataJSON) {
GetStoreData('LOCATION_DATA').then(locationArray => {
GetStoreData(LOCATION_DATA).then(locationArray => {
let locationData;

if (locationArray !== null) {
Expand All @@ -64,6 +65,6 @@ export async function MergeJSONWithLocalData(googleDataJSON) {
Merge(locationData, googleDataJSON);

console.log('Saving on array');
SetStoreData('LOCATION_DATA', locationData);
SetStoreData(LOCATION_DATA, locationData);
});
}
5 changes: 3 additions & 2 deletions app/helpers/Intersect.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
*/

import { GetStoreData, SetStoreData } from '../helpers/General';
import { LOCATION_DATA, CROSSED_PATHS } from '../constants/storage';

export async function IntersectSet(concernLocationArray, completion) {
GetStoreData('LOCATION_DATA').then(locationArrayString => {
GetStoreData(LOCATION_DATA).then(locationArrayString => {
var locationArray;
if (locationArrayString !== null) {
locationArray = JSON.parse(locationArrayString);
Expand Down Expand Up @@ -95,7 +96,7 @@ export async function IntersectSet(concernLocationArray, completion) {

// TODO: Show in the UI!
console.log('Crossing results: ', dayBin);
SetStoreData('CROSSED_PATHS', dayBin); // TODO: Store per authority?
SetStoreData(CROSSED_PATHS, dayBin); // TODO: Store per authority?
completion(dayBin);
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/config.js → app/helpers/authorities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const public_data =
export const PUBLIC_DATA_URL =
'https://raw.githubusercontent.com/beoutbreakprepared/nCoV2019/master/latest_data/latestdata.csv';

export const authoritiesListURL =
export const AUTHORITIES_LIST_URL =
'https://raw.githubusercontent.com/tripleblindmarket/safe-places/develop/healthcare-authorities.yaml';
3 changes: 2 additions & 1 deletion app/locales/languages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import i18next from 'i18next';
import { getLanguages } from 'react-native-i18n';
import { GetStoreData } from '../helpers/General';
import { LANG_OVERRIDE } from '../constants/storage';

// Refer this for checking the codes and creating new folders https://developer.chrome.com/webstore/i18n
// Step 1 - Create index.js files for each language we want to have, in this file you can import all the json files (Step 4) and export them
Expand Down Expand Up @@ -36,7 +37,7 @@ export function findUserLang(callback) {
userLang = languages[0].split('-')[0]; // ['en-US' will become 'en']

// If the user specified a language override, use it instead
GetStoreData('LANG_OVERRIDE').then(res => {
GetStoreData(LANG_OVERRIDE).then(res => {
if (typeof res === 'string') {
console.log('Found user language override:');
console.log(res);
Expand Down
11 changes: 6 additions & 5 deletions app/services/BroadcastingService.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import UUIDGenerator from 'react-native-uuid-generator';
import AndroidBLEAdvertiserModule from 'react-native-ble-advertiser';
import { NativeEventEmitter, NativeModules } from 'react-native';
import { isPlatformAndroid, nowStr } from '../Util';
import { CONTACT_DATA, MY_UUIDs } from '../constants/storage';

var currentUUID = null;
var onDeviceFound = null;
Expand Down Expand Up @@ -52,7 +53,7 @@ function saveContact(contact) {
// Persist this contact data in our local storage of time/uuid values
//console.log('[Bluetooth]', nowStr(), currentUUID, 'New Device Found', contact['uuid']);
if (isNewContact(contact)) {
GetStoreData('CONTACT_DATA', false).then(contactArray => {
GetStoreData(CONTACT_DATA, false).then(contactArray => {
if (!contactArray) {
contactArray = [];
}
Expand All @@ -78,15 +79,15 @@ function saveContact(contact) {
curated.length,
);

SetStoreData('CONTACT_DATA', curated);
SetStoreData(CONTACT_DATA, curated);
});
}
}

function saveMyUUID(me) {
// Persist this contact data in our local storage of time/lat/lon values

GetStoreData('MY_UUIDs', false).then(myUUIDArray => {
GetStoreData(MY_UUIDs, false).then(myUUIDArray => {
if (!myUUIDArray) {
myUUIDArray = [];
}
Expand All @@ -113,12 +114,12 @@ function saveMyUUID(me) {
);
curated.push(uuid_time);

SetStoreData('MY_UUIDs', curated);
SetStoreData(MY_UUIDs, curated);
});
}

function loadLastUUIDAndBroadcast() {
GetStoreData('MY_UUIDs', false).then(myUUIDArray => {
GetStoreData(MY_UUIDs, false).then(myUUIDArray => {
if (!myUUIDArray) {
console.log(
'[Bluetooth]',
Expand Down
23 changes: 11 additions & 12 deletions app/services/LocationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PushNotificationIOS from '@react-native-community/push-notification-ios';
import PushNotification from 'react-native-push-notification';
import { isPlatformAndroid } from '../Util';
import languages from '../locales/languages';
import { LOCATION_DATA, PARTICIPATE } from '../constants/storage';

let hasBeenStarted = false;

Expand All @@ -17,12 +18,11 @@ export class LocationData {
this.minLocationSaveInterval = Math.floor(this.locationInterval * 0.8); // Minimum time between location information saves. 60000*4 = 4 minutes

// Maximum time that we will backfill for missing data
this.maxBackfillTime = 60000 * 60 * 8 // Time (in milliseconds). 60000 * 60 * 8 = 8 hours

this.maxBackfillTime = 60000 * 60 * 8; // Time (in milliseconds). 60000 * 60 * 8 = 8 hours
}

getLocationData() {
return GetStoreData('LOCATION_DATA').then(locationArrayString => {
return GetStoreData(LOCATION_DATA).then(locationArrayString => {
let locationArray = [];
if (locationArrayString !== null) {
locationArray = JSON.parse(locationArrayString);
Expand Down Expand Up @@ -55,7 +55,6 @@ export class LocationData {
saveLocation(location) {
// Persist this location data in our local storage of time/lat/lon values
this.getLocationData().then(locationArray => {

// Always work in UTC, not the local time in the locationData
let unixtimeUTC = Math.floor(location['time']);
let unixtimeUTC_28daysAgo = unixtimeUTC - 60 * 60 * 24 * 1000 * 28;
Expand All @@ -81,7 +80,7 @@ export class LocationData {

// Backfill the stationary points, if available
// The assumption is that if we see a gap in the data, the
// best guess is that the person was in that location for
// best guess is that the person was in that location for
// the entire time. This makes it easier for a health authority
// person to have a set of locations over time, and they can manually
// redact the time frames that aren't correct.
Expand All @@ -93,7 +92,7 @@ export class LocationData {
// To protect ourselves, we won't backfill more than the
// maxBackfillTime
let lastRecordedTime = lastLocationArray['time'];
if ((unixtimeUTC - lastRecordedTime) > this.maxBackfillTime) {
if (unixtimeUTC - lastRecordedTime > this.maxBackfillTime) {
lastRecordedTime = unixtimeUTC - this.maxBackfillTime;
}

Expand All @@ -105,9 +104,9 @@ export class LocationData {
let lat_lon_time = {
latitude: lastLocationArray['latitude'],
longitude: lastLocationArray['longitude'],
time: newTS
time: newTS,
};
console.log('[INFO] backfill location:',lat_lon_time);
console.log('[INFO] backfill location:', lat_lon_time);
curated.push(lat_lon_time);
}
}
Expand All @@ -117,12 +116,12 @@ export class LocationData {
let lat_lon_time = {
latitude: location['latitude'],
longitude: location['longitude'],
time: unixtimeUTC
time: unixtimeUTC,
};
curated.push(lat_lon_time);
console.log('[INFO] saved location:',lat_lon_time);
console.log('[INFO] saved location:', lat_lon_time);

SetStoreData('LOCATION_DATA', curated);
SetStoreData(LOCATION_DATA, curated);
});
}
}
Expand Down Expand Up @@ -354,7 +353,7 @@ export default class LocationServices {
BackgroundGeolocation.removeAllListeners();
BackgroundGeolocation.stop();
instanceCount -= 1;
SetStoreData('PARTICIPATE', 'false').then(() => {
SetStoreData(PARTICIPATE, 'false').then(() => {
// nav.navigate('LocationTrackingScreen', {});
});
}
Expand Down
8 changes: 5 additions & 3 deletions app/views/ChooseProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
FlatList,
Alert,
TextInput,
Dimensions,
} from 'react-native';
import Yaml from 'js-yaml';
import RNFetchBlob from 'rn-fetch-blob';
Expand All @@ -30,9 +31,10 @@ import backArrow from './../assets/images/backArrow.png';
import closeIcon from './../assets/images/closeIcon.png';
import saveIcon from './../assets/images/saveIcon.png';
import languages from '../locales/languages';
import { width } from '../helpers/Constants';
import NavigationBarWrapper from '../components/NavigationBarWrapper';
import { authoritiesListURL } from '../helpers/config';
import { AUTHORITIES_LIST_URL } from '../helpers/authorities';

const width = Dimensions.get('window').width;

class ChooseProviderScreen extends Component {
constructor(props) {
Expand Down Expand Up @@ -84,7 +86,7 @@ class ChooseProviderScreen extends Component {
// this is much more performant.
fileCache: true,
})
.fetch('GET', authoritiesListURL, {
.fetch('GET', AUTHORITIES_LIST_URL, {
//some headers ..
})
.then(result => {
Expand Down
4 changes: 3 additions & 1 deletion app/views/Import.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Image,
TouchableOpacity,
BackHandler,
Dimensions,
ActivityIndicator,
} from 'react-native';

Expand All @@ -16,7 +17,8 @@ import WebView from 'react-native-webview';
import backArrow from './../assets/images/backArrow.png';
import { SearchAndImport } from '../helpers/GoogleTakeOutAutoImport';
import languages from './../locales/languages';
import { width, height } from '../helpers/Constants';
const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

import NavigationBarWrapper from '../components/NavigationBarWrapper';

Expand Down
12 changes: 8 additions & 4 deletions app/views/LocationTracking.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
View,
Text,
TouchableOpacity,
Dimensions,
Image,
ScrollView,
BackHandler,
Expand Down Expand Up @@ -47,7 +48,7 @@ import StateNoContact from './../assets/svgs/stateNoContact';
import StateUnknown from './../assets/svgs/stateUnknown';
import SettingsGear from './../assets/svgs/settingsGear';
import fontFamily from '../constants/fonts';
import { width, height } from '../helpers/Constants';
import { PARTICIPATE, CROSSED_PATHS } from '../constants/storage';

const StateEnum = {
UNKNOWN: 0,
Expand All @@ -73,6 +74,9 @@ const StateIcon = ({ title, status, size, ...props }) => {
);
};

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

class LocationTracking extends Component {
constructor(props) {
super(props);
Expand Down Expand Up @@ -125,7 +129,7 @@ class LocationTracking extends Component {
// already set on 12h timer, but run when this screen opens too
this.intersect_tick();

GetStoreData('CROSSED_PATHS').then(dayBin => {
GetStoreData(CROSSED_PATHS).then(dayBin => {
if (dayBin === null) {
console.log("Can't find crossed paths");
this.setState({ currentState: StateEnum.NO_CONTACT });
Expand All @@ -140,7 +144,7 @@ class LocationTracking extends Component {
componentDidMount() {
AppState.addEventListener('change', this._handleAppStateChange);
BackHandler.addEventListener('hardwareBackPress', this.handleBackPress);
GetStoreData('PARTICIPATE')
GetStoreData(PARTICIPATE)
.then(isParticipating => {
if (isParticipating === 'true') {
this.setState({
Expand Down Expand Up @@ -289,7 +293,7 @@ class LocationTracking extends Component {
}

willParticipate = () => {
SetStoreData('PARTICIPATE', 'true').then(() => {
SetStoreData(PARTICIPATE, 'true').then(() => {
LocationServices.start();
// Turn of bluetooth for v1
//BroadcastingServices.start();
Expand Down
5 changes: 4 additions & 1 deletion app/views/News.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { Component } from 'react';
import {
StyleSheet,
BackHandler,
Dimensions,
ActivityIndicator,
ScrollView,
SafeAreaView,
Expand All @@ -21,7 +22,9 @@ import languages from './../locales/languages';
import fontFamily from '../constants/fonts';
import NavigationBarWrapper from '../components/NavigationBarWrapper';
import Colors from '../constants/colors';
import { width, height } from '../helpers/Constants';

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;

class NewsScreen extends Component {
constructor(props) {
Expand Down
7 changes: 5 additions & 2 deletions app/views/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
View,
Text,
Image,
Dimensions,
TouchableOpacity,
BackHandler,
ScrollView,
Expand All @@ -26,8 +27,10 @@ import {
} from 'victory-native';
import Colors from '../constants/colors';
import NavigationBarWrapper from '../components/NavigationBarWrapper';
import { width, height } from '../helpers/Constants';
import { CROSSED_PATHS } from '../constants/storage';

const width = Dimensions.get('window').width;
const height = Dimensions.get('window').height;
const max_exposure_window = 14; // Two weeks is the longest view that matters
const bin_duration = 5; // each bin count represents a 5 minute period

Expand Down Expand Up @@ -82,7 +85,7 @@ class NotificationScreen extends Component {
resetState() {}

getInitialState = async () => {
GetStoreData('CROSSED_PATHS').then(dayBin => {
GetStoreData(CROSSED_PATHS).then(dayBin => {
console.log(dayBin);

/* DEBUGGING TOOL -- handy for creating faux data
Expand Down
Loading

0 comments on commit 3f43089

Please sign in to comment.