Skip to content

Commit 9a579de

Browse files
committed
finishes refactoring in separate android views
2 parents 5bb4b56 + a4280c8 commit 9a579de

File tree

6 files changed

+320
-378
lines changed

6 files changed

+320
-378
lines changed

index.android.js

Lines changed: 51 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
* https://HelperNet.github.io
44
*/
55

6-
var React = require('react-native');
7-
var _ = require('lodash');
8-
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
9-
var Subscribable = require('Subscribable');
6+
var React = require('react-native')
7+
var _ = require('lodash')
8+
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter')
9+
var Subscribable = require('Subscribable')
10+
var styles = require('./stylesheet')
1011

1112
var {
1213
AppRegistry,
13-
StyleSheet,
1414
Text,
1515
TextInput,
1616
View,
@@ -51,16 +51,16 @@ var HelperNet = React.createClass({
5151

5252
componentWillMount() {
5353
if (this.state.enabled) {
54-
NativeModules.P2PKit.enable();
54+
NativeModules.P2PKit.enable()
5555
}
5656

5757
this.addListenerOn(RCTDeviceEventEmitter,
5858
'aroundCountChanged',
59-
this.handleAroundChange);
59+
this.handleAroundChange)
6060

6161
this.addListenerOn(RCTDeviceEventEmitter,
6262
'emergencyReceived',
63-
this.handleEmergencyReceived);
63+
this.handleEmergencyReceived)
6464

6565
this.addListenerOn(RCTDeviceEventEmitter,
6666
'location',
@@ -76,10 +76,10 @@ var HelperNet = React.createClass({
7676
},
7777

7878
componentDidMount() {
79-
_.forEach(_.keys(this.state), (key) => {
80-
AsyncStorage.getItem(key)
81-
.then((value) => {console.log("load key, value: ", key, value); this.setState({key: value})})
82-
});
79+
// _.forEach(_.keys(this.state), (key) => {
80+
// AsyncStorage.getItem(key)
81+
// .then((value) => {console.log("load key, value: ", key, value); this.setState({key: value})})
82+
// });
8383
},
8484

8585
componentDidUpdate(prevProps, prevState) {
@@ -92,22 +92,23 @@ var HelperNet = React.createClass({
9292
},
9393

9494
getLocation() {
95+
// TODO: where does navigator come from?
9596
navigator.geolocation.getCurrentPosition(
9697
(initialPosition) => this.setState({location: initialPosition}),
9798
(error) => alert(error.message),
9899
{enableHighAccuracy: true, timeout: 20000, maximumAge: 1000}
99-
);
100+
)
100101
},
101102

102103
handleAroundChange(event) {
103-
this.setState({aroundCount: event.newCount});
104+
this.setState({aroundCount: event.newCount})
104105
},
105106

106107
handleEmergencyReceived(event) {
107108
this.setState({
108109
receivedEmergency: true,
109110
receivedEmergencyText: event.message
110-
});
111+
})
111112
},
112113

113114
handleLocationReceived(event) {
@@ -116,7 +117,7 @@ var HelperNet = React.createClass({
116117
lat: event.lat,
117118
lng: event.lng
118119
}
119-
});
120+
})
120121
},
121122

122123
sendMessage() {
@@ -128,49 +129,49 @@ var HelperNet = React.createClass({
128129
},
129130

130131
resetMessage() {
131-
NativeModules.P2PKit.resetMessage();
132+
NativeModules.P2PKit.resetMessage()
132133
},
133134

134135
directTo() {
135-
const {lat, lng } = this.state.location;
136-
NativeModules.P2PKit.directTo(47.3897774,8.5164106,lat,lng);
136+
const {lat, lng } = this.state.location
137+
NativeModules.P2PKit.directTo(47.3897774,8.5164106,lat,lng)
137138
},
138139
//
139140
// handleEnabledChanged(isEnabled) {
140-
// this.setState({isEnabled: isEnabled});
141+
// this.setState({isEnabled: isEnabled})
141142
// if (isEnabled) {
142-
// NativeModules.P2PKit.enable();
143+
// NativeModules.P2PKit.enable()
143144
// } else {
144-
// NativeModules.P2PKit.disable();
145+
// NativeModules.P2PKit.disable()
145146
// }
146147
// },
147148

148149
handleEmergencyClick() {
149150
if (this.state.emergency) {
150-
this.resetMessage();
151-
this.setState({emergency: false});
151+
this.resetMessage()
152+
this.setState({emergency: false})
152153
} else {
153154
if (this.state.callEmergencyAutomatically) {
154-
NativeModules.P2PKit.phoneCall(this.state.number);
155+
NativeModules.P2PKit.phoneCall(this.state.number)
155156
}
156-
this.sendMessage();
157-
this.setState({emergency: true});
157+
this.sendMessage()
158+
this.setState({emergency: true})
158159
}
159160
},
160161

161162
showSettings() {
162-
this.setState({showSettings: true});
163+
this.setState({showSettings: true})
163164
},
164165

165166
hideSettings() {
166-
this.setState({showSettings: false});
167+
this.setState({showSettings: false})
167168
},
168169

169170
dismissModal() {
170-
this.setState({receivedEmergency: false});
171+
this.setState({receivedEmergency: false})
171172
},
172173

173-
accept() {
174+
acceptEmergencyCall() {
174175
this.directTo();
175176
NativeModules.P2PKit.setMessage(`OT`);
176177
},
@@ -179,19 +180,28 @@ var HelperNet = React.createClass({
179180

180181
const settingsView =
181182
<SettingsView
182-
/>
183+
hideSettings={this.hideSettings}
184+
onChangeNumber={number => this.setState({number})}
185+
phoneNumber={this.state.number}
186+
shouldCallEmergencyAutomatically={this.state.callEmergencyAutomatically}
187+
onChangeShouldCallEmergencyAutomatically={callEmergencyAutomatically => this.setState({callEmergencyAutomatically})}
188+
emergencyText={this.state.emergencyText}
189+
onChangeEmergencyText={emergencyText => this.setState({emergencyText})} />
183190

184191
const emergencyView =
185192
<EmergencyView
186-
/>
187-
188-
return this.state.showSettings ? settingsView: emergencyView;
193+
showSettings={this.showSettings}
194+
isEmergency={this.state.emergency}
195+
receivedEmergency={this.state.receivedEmergency}
196+
aroundCount={this.state.aroundCount}
197+
handleEmergencyClick={this.handleEmergencyClick}
198+
receivedEmergencyText={this.state.receivedEmergencyText}
199+
onAcceptEmergencyCall={this.acceptEmergencyCall}
200+
onDismissEmergencyCall={this.dismissModal} />
201+
202+
return this.state.showSettings ? settingsView : emergencyView;
189203
}
190-
});
191-
192-
193-
194-
204+
})
195205

196206
// <View style={styles.switchContainer}>
197207
// <Text style={styles.label}>
@@ -206,182 +216,4 @@ var HelperNet = React.createClass({
206216
// tintColor='ff0000' />
207217
// </View>
208218

209-
210-
var styles = StyleSheet.create({
211-
rootContainer: {
212-
flex: 1
213-
},
214-
toolbar: {
215-
backgroundColor: '#303F9F',
216-
paddingTop: 10,
217-
paddingBottom: 10,
218-
// height: 50,
219-
flexDirection: 'row',
220-
justifyContent: 'space-between'
221-
},
222-
backButton: {
223-
height: 30,
224-
width: 30
225-
},
226-
backButtonTouch: {
227-
flex: 1
228-
},
229-
toolbarTitle: {
230-
width: 100,
231-
flex: 1,
232-
color: '#fff',
233-
textAlign: 'center',
234-
fontWeight: 'bold',
235-
fontSize: 20
236-
},
237-
spaceView: {
238-
flex: 1
239-
},
240-
scrollContainer: {
241-
padding: 20,
242-
backgroundColor: '#F5FCFF',
243-
},
244-
// emergencyReceivedContainer: {
245-
// marginBottom: 15,
246-
// borderColor: '#e70000',
247-
// borderWidth: 3,
248-
// borderRadius: 8,
249-
// padding: 10
250-
// },
251-
numberContainer: {
252-
// padding: 10
253-
},
254-
numberText: {
255-
fontSize: 20,
256-
marginTop: 10
257-
},
258-
switchContainer: {
259-
marginTop: 10,
260-
flexDirection: 'row',
261-
justifyContent: 'space-between'
262-
},
263-
label: {
264-
265-
},
266-
switch: {
267-
marginBottom: 10
268-
},
269-
button: {
270-
height: 65,
271-
// flex: 1,
272-
flexDirection: 'row',
273-
backgroundColor: '#e70000',
274-
borderColor: '#e70000',
275-
borderWidth: 1,
276-
borderRadius: 8,
277-
marginTop: 10,
278-
alignSelf: 'stretch',
279-
justifyContent: 'center'
280-
},
281-
buttonText: {
282-
color: '#fff',
283-
fontWeight: 'bold',
284-
fontSize: 20,
285-
marginTop: 17
286-
},
287-
aroundCountContainer: {
288-
padding: 20,
289-
justifyContent: 'center',
290-
flex: 1,
291-
alignItems: 'center',
292-
flexDirection: 'column',
293-
},
294-
aroundCountText: {
295-
flex: 1,
296-
textAlign: 'center',
297-
fontSize: 17,
298-
marginBottom: 110,
299-
color: '#fff',
300-
fontWeight: 'bold',
301-
},
302-
copyrightText: {
303-
flex: 1,
304-
marginBottom: 10
305-
},
306-
backgroundContainer: {
307-
backgroundColor: '#303F9F',
308-
flex: 1,
309-
},
310-
touchableSettingsIcon: {
311-
// position: 'absolute',
312-
// right: 10,
313-
// top: 10
314-
flex: 1
315-
},
316-
settingsIcon: {
317-
width: 40,
318-
height: 40,
319-
// position: 'relative',
320-
// right: 0
321-
alignSelf: 'flex-end',
322-
marginRight: 10
323-
324-
},
325-
emergencyReceivedContainer: {
326-
right: 0,
327-
left: 0,
328-
margin: 15,
329-
padding: 10,
330-
height: 170,
331-
position: 'absolute',
332-
marginTop: 150,
333-
borderRadius: 5,
334-
backgroundColor: '#f10000'
335-
},
336-
emergencyReceivedText: {
337-
fontSize: 20,
338-
color: '#fff'
339-
},
340-
emergencyReceivedButton: {
341-
padding: 5,
342-
backgroundColor: '#a90b1d',
343-
borderRadius: 3
344-
},
345-
emergencyReceivedButtonText: {
346-
fontSize: 20,
347-
color: '#fff'
348-
},
349-
buttonGroup: {
350-
flex: 1,
351-
flexDirection: 'row',
352-
marginTop: 10,
353-
justifyContent: 'space-between'
354-
},
355-
buttonWrapper: {
356-
flex: 1,
357-
justifyContent: 'center',
358-
flexDirection: 'row',
359-
marginTop: 110
360-
},
361-
emergencyButton: {
362-
width: 180,
363-
height: 180,
364-
borderRadius: 200,
365-
backgroundColor: '#F50057',
366-
justifyContent: 'center',
367-
flexDirection: 'column',
368-
},
369-
emergencyButtonText: {
370-
color: '#fff',
371-
fontSize: 25,
372-
textAlign: 'center',
373-
fontWeight: 'bold'
374-
},
375-
circlesWrapper: {
376-
justifyContent: 'center',
377-
},
378-
circles: {
379-
height: 550,
380-
width: 550,
381-
position: 'absolute',
382-
bottom: -160,
383-
right: -90
384-
}
385-
});
386-
387-
AppRegistry.registerComponent('HelperNet', () => HelperNet);
219+
AppRegistry.registerComponent('HelperNet', () => HelperNet)

0 commit comments

Comments
 (0)