@@ -20,28 +20,31 @@ var {
20
20
SwitchAndroid,
21
21
AsyncStorage,
22
22
Image,
23
- TouchableOpacity
24
- } = React
23
+ TouchableOpacity,
24
+ BackAndroid
25
+ } = React ;
26
+
27
+
28
+ const initialState = {
29
+ enabled : true ,
30
+ number : "+491736353009" ,
31
+ callEmergencyAutomatically : false ,
32
+ isEnabled : true ,
33
+ emergencyText : 'Please help me I have an emergency!' ,
34
+ aroundCount : 0 ,
35
+ emergency : false ,
36
+ receivedEmergency : false ,
37
+ receivedEmergencyText : '' ,
38
+ location : { } ,
39
+ showSettings : false
40
+ } ;
25
41
26
42
var HelperNet = React . createClass ( {
27
43
28
44
mixins : [ Subscribable . Mixin ] ,
29
45
30
46
getInitialState ( ) {
31
- return {
32
- counter : 0 ,
33
- enabled : true ,
34
- number : "+491736353009" ,
35
- callEmergencyAutomatically : false ,
36
- isEnabled : true ,
37
- emergencyText : 'Please help me I have an emergency!' ,
38
- aroundCount : 0 ,
39
- emergency : false ,
40
- receivedEmergency : true ,
41
- receivedEmergencyText : '' ,
42
- location : { } ,
43
- showSettings : false
44
- }
47
+ return initialState ;
45
48
} ,
46
49
47
50
componentWillMount ( ) {
@@ -59,22 +62,29 @@ var HelperNet = React.createClass({
59
62
60
63
this . addListenerOn ( RCTDeviceEventEmitter ,
61
64
'location' ,
62
- this . handleLocationReceived )
65
+ this . handleLocationReceived ) ;
66
+
67
+ BackAndroid . addEventListener ( 'hardwareBackPress' , ( ) => {
68
+ if ( this . state . showSettings ) {
69
+ this . hideSettings ( )
70
+ return true ;
71
+ }
72
+ return false ;
73
+ } ) ;
63
74
} ,
64
75
65
76
componentDidMount ( ) {
66
77
_ . forEach ( _ . keys ( this . state ) , ( key ) => {
67
78
AsyncStorage . getItem ( key )
68
- . then ( ( value ) => this . setState ( { key : value } ) )
69
- } )
79
+ . then ( ( value ) => { console . log ( "load key, value: " , key , value ) ; this . setState ( { key : value } ) } )
80
+ } ) ;
70
81
} ,
71
82
72
83
componentDidUpdate ( prevProps , prevState ) {
73
84
_ . forIn ( this . state , ( value , key ) => {
74
- if ( value != null && key != null && value != prevState [ key ] ) {
75
- console . log ( key , value )
76
- // TODO: why does async storage break?
77
- // AsyncStorage.setItem(key, value)
85
+ if ( value != null && key != null && value != initialState [ key ] && value != prevState [ key ] ) {
86
+ console . log ( "set key, value: " , key , value ) ;
87
+ AsyncStorage . setItem ( key , value ) ;
78
88
}
79
89
} )
80
90
} ,
@@ -110,11 +120,10 @@ var HelperNet = React.createClass({
110
120
111
121
sendMessage ( ) {
112
122
// this.getLocation().then((location) => {
113
- // const {latitude, longitude} = location.coords
114
- // NativeModules.P2PKit.setMessage(`no${this.state.emergencyText}|lo${latitude},${longitude}`)
115
- // })
116
- NativeModules . P2PKit . setMessage ( `NO${ this . state . emergencyText } |lo47.3897774,8.5164106` )
117
- // this.setState({counter: this.state.counter + 1})
123
+ // const {latitude, longitude} = location.coords;
124
+ // NativeModules.P2PKit.setMessage(`no${this.state.emergencyText}|lo${latitude},${longitude}`);
125
+ // });
126
+ NativeModules . P2PKit . setMessage ( `NO${ this . state . emergencyText } |lo47.3897774,8.5164106` ) ;
118
127
} ,
119
128
120
129
resetMessage ( ) {
@@ -160,6 +169,11 @@ var HelperNet = React.createClass({
160
169
this . setState ( { receivedEmergency : false } )
161
170
} ,
162
171
172
+ accept ( ) {
173
+ this . directTo ( ) ;
174
+ NativeModules . P2PKit . setMessage ( `OT` ) ;
175
+ } ,
176
+
163
177
render ( ) {
164
178
165
179
const settings = (
@@ -213,7 +227,7 @@ var HelperNet = React.createClass({
213
227
214
228
< View style = { styles . aroundCountContainer } >
215
229
< Text style = { styles . copyrightText } >
216
- & copy 2015 Nerdish by Nature
230
+ © 2015 Nerdish by Nature
217
231
</ Text >
218
232
</ View >
219
233
</ ScrollView >
@@ -229,7 +243,7 @@ var HelperNet = React.createClass({
229
243
< View style = { styles . buttonGroup } >
230
244
< TouchableHighlight
231
245
style = { styles . emergencyReceivedButton }
232
- onPress = { this . directTo }
246
+ onPress = { this . accept }
233
247
underlayColor = '#ff0000' >
234
248
< Text style = { styles . emergencyReceivedButtonText } > Route there</ Text >
235
249
</ TouchableHighlight >
0 commit comments