Skip to content

Commit a4280c8

Browse files
committed
Conflicts: index.android.js
2 parents 40e38a6 + a2afb10 commit a4280c8

File tree

11 files changed

+59
-36
lines changed

11 files changed

+59
-36
lines changed

android/.gradle/2.4/taskArtifacts/cache.properties

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.
-127 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

android/app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ android {
2424

2525
dependencies {
2626
compile fileTree(dir: 'libs', include: ['*.jar'])
27-
compile 'com.android.support:appcompat-v7:23.0.0'
28-
compile 'com.facebook.react:react-native:0.11.+'
27+
compile 'com.android.support:appcompat-v7:23.0.1'
28+
compile 'com.facebook.react:react-native:0.13.+'
2929
compile 'ch.uepaa.p2p:p2pkit-android:1.0.3'
3030
}

android/app/src/main/java/com/helpernet/MainActivity.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ public boolean onKeyUp(int keyCode, KeyEvent event) {
8989
return super.onKeyUp(keyCode, event);
9090
}
9191

92+
@Override
93+
public void onBackPressed() {
94+
if (mReactInstanceManager != null) {
95+
mReactInstanceManager.onBackPressed();
96+
} else {
97+
super.onBackPressed();
98+
}
99+
}
100+
92101
@Override
93102
public void invokeDefaultOnBackPressed() {
94103
super.onBackPressed();

android/app/src/main/java/com/helpernet/P2PKitService.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ private void handleMessage(String message, String id) {
186186
mainActivity.getEventEmitter().emitLocation(lat, lng, id, mainActivity.getReactContext());
187187
} else if (prefix.equals("OK")) {
188188
Log.d(TAG, "standard message");
189-
pushNotification(Topic.MISC, "OK");
189+
// pushNotification(Topic.MISC, "OK");
190190
} else {
191-
throw new IllegalArgumentException("unsupported prefix");
191+
// throw new IllegalArgumentException("unsupported prefix");
192+
Log.e(TAG, "unsupported prefix: " + prefix);
192193
}
193194
}
194195
}

index.android.js

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,31 @@ var {
2020
SwitchAndroid,
2121
AsyncStorage,
2222
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+
};
2541

2642
var HelperNet = React.createClass({
2743

2844
mixins: [Subscribable.Mixin],
2945

3046
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;
4548
},
4649

4750
componentWillMount() {
@@ -59,22 +62,29 @@ var HelperNet = React.createClass({
5962

6063
this.addListenerOn(RCTDeviceEventEmitter,
6164
'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+
});
6374
},
6475

6576
componentDidMount() {
6677
_.forEach(_.keys(this.state), (key) => {
6778
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+
});
7081
},
7182

7283
componentDidUpdate(prevProps, prevState) {
7384
_.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);
7888
}
7989
})
8090
},
@@ -110,11 +120,10 @@ var HelperNet = React.createClass({
110120

111121
sendMessage() {
112122
// 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`);
118127
},
119128

120129
resetMessage() {
@@ -160,6 +169,11 @@ var HelperNet = React.createClass({
160169
this.setState({receivedEmergency: false})
161170
},
162171

172+
accept() {
173+
this.directTo();
174+
NativeModules.P2PKit.setMessage(`OT`);
175+
},
176+
163177
render() {
164178

165179
const settings = (
@@ -213,7 +227,7 @@ var HelperNet = React.createClass({
213227

214228
<View style={styles.aroundCountContainer}>
215229
<Text style={styles.copyrightText}>
216-
&copy 2015 Nerdish by Nature
230+
&copy; 2015 Nerdish by Nature
217231
</Text>
218232
</View>
219233
</ScrollView>
@@ -229,7 +243,7 @@ var HelperNet = React.createClass({
229243
<View style={styles.buttonGroup}>
230244
<TouchableHighlight
231245
style={styles.emergencyReceivedButton}
232-
onPress={this.directTo}
246+
onPress={this.accept}
233247
underlayColor='#ff0000'>
234248
<Text style={styles.emergencyReceivedButtonText}>Route there</Text>
235249
</TouchableHighlight>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"dependencies": {
99
"lodash": "^3.10.1",
10-
"react-native": "^0.11.4",
10+
"react-native": "^0.13.0-rc",
1111
"redux": "^3.0.2",
1212
"redux-actions": "^0.8.0"
1313
}

0 commit comments

Comments
 (0)