-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomePage.js
182 lines (156 loc) · 4.89 KB
/
HomePage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import React, { Component } from 'react';
import {StyleSheet, Text, View, TouchableHighlight, TouchableOpacity,
TouchableWithoutFeedback,
StatusBar,
AsyncStorage
} from 'react-native';
import Icon from 'react-native-vector-icons/Octicons';
import SettingsPage from './SettingsPage';
// import BackgroundTask from 'react-native-background-task'
// BackgroundTask.define(async () => {
// // Fetch some data over the network which we want the user to have an up-to-
// // date copy of, even if they have no network when using the app
// const response = await fetch('https://pestoapp.herokuapp.com/')
// const text = await response.text()
// // Data persisted to AsyncStorage can later be accessed by the foreground app
// // Remember to call finish()
// BackgroundTask.finish()
// })
let INCIDENT_1 = "Tap here to "
let INCIDENT_2 = "Report\n"
let INCIDENT_3 = " an incident"
let LIVE_1 = "Otherwise tap here for\n"
let LIVE_2 = "LIVE"
let LIVE_3 = " map streaming"
class HomePageRow extends Component {
render() {
return (
<TouchableWithoutFeedback onPress={this.props.onPress}>
<View style={this.props.style}>
<Text>
<Text style={this.props.textStyle1}>{this.props.text1}</Text>
<Text style={this.props.textStyle2}>{this.props.text2}</Text>
<Text style={this.props.textStyle1}>{this.props.text3}</Text>
</Text>
</View>
</TouchableWithoutFeedback>
);
}
}
export default class HomePage extends Component {
constructor(props) {
super(props);
this.state = {
jsona: '',
key1: null
};
}
componentDidMount() {
AsyncStorage.getItem('@MySuperStore:key').then((token) => {
this.setState({key1 : token})
})
// BackgroundTask.schedule({
// period: 10, // Aim to run every 30 mins - more conservative on battery
// })
// // Optional: Check if the device is blocking background tasks or not
// this.checkStatus()
}
_LiveMaps = async () => {
var a;
await fetch('https://pestoapp.herokuapp.com/pin/', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
Authorization: 'Token '+this.state.key1
},
})
.then((response) => response.json())
.then((response) => {
console.log("Feedback",response)
this.state.jsona = JSON.stringify(response)
})
try {
await AsyncStorage.setItem('@MySuperStore:pins', this.state.jsona);
} catch (error) {
console.log("Error saving data" + error);
}
this.props.navigation.navigate('LiveMaps')
}
static navigationOptions = { header: null };
render () {
return (
<View style={styles.HomeStyle} >
<StatusBar hidden={true}/>
<HomePageRow style={styles.HomePageIncident} textStyle1={[styles.StyleText1, {color: '#FFFFFF'}]}
textStyle2={[styles.StyleText2, {color: '#FFFFFF'}]} text1={INCIDENT_1} text2={INCIDENT_2} text3={INCIDENT_3} onPress={() =>this.props.navigation.navigate('feltUncomfortable')}/>
<HomePageRow style={styles.HomePageLive} textStyle1={[styles.StyleText1, {color: '#000000'}]}
textStyle2={[styles.StyleText2, {color: '#000000'}]} text1={LIVE_1} text2={LIVE_2} text3={LIVE_3} onPress={() =>this._LiveMaps()} />
<Settings SettingsButton={() =>this.props.navigation.navigate('SettingsPage')}/>
</View>
)
}
}
class Settings extends Component {
render() {
const buttonStyles = StyleSheet.create({
CircleContainer: {
position: 'absolute',
top: 0, left: 0, right: 0, bottom: 0,
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
},
Circle: {
backgroundColor: '#444444',
width: 45,
height: 45,
borderRadius: 45/2,
justifyContent: 'center',
alignItems: 'center'
},
}
);
return (
<View style={buttonStyles.CircleContainer}>
<View style={buttonStyles.Circle}>
<TouchableOpacity activeOpacity={0.4} onPress={this.props.SettingsButton} style={buttonStyles.CircleContainer}>
<Icon name={"pin"} size={30} color="#888888" />
</TouchableOpacity>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
HomeStyle: {
flexDirection: 'column',
flex:1,
// justifyContent: 'space-evenly'
},
StyleText1: {
// color:'#ffffff',
fontSize:22,
textAlign: 'center'
},
StyleText2: {
// color:'#ffffff',
fontSize:32,
textAlign: 'center'
},
HomePageIncident: {
flex:1,
backgroundColor: '#99004d' ,
// backgroundColor: '#b30047',
justifyContent: 'center',
alignItems: 'center',
},
HomePageLive: {
flex:1,
// backgroundColor: '#00ff99',
backgroundColor: '#1affff',
// backgroundColor: '#d2ff4d',
justifyContent: 'center',
alignItems: 'center',
},
});