diff --git a/BalancedBite/android/.project b/BalancedBite/android/.project
new file mode 100644
index 0000000..b23c840
--- /dev/null
+++ b/BalancedBite/android/.project
@@ -0,0 +1,17 @@
+
+
+ BalancedBite
+ Project android created by Buildship.
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectbuilder
+
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectnature
+
+
diff --git a/BalancedBite/android/.settings/org.eclipse.buildship.core.prefs b/BalancedBite/android/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..e889521
--- /dev/null
+++ b/BalancedBite/android/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=
+eclipse.preferences.version=1
diff --git a/BalancedBite/android/app/.classpath b/BalancedBite/android/app/.classpath
new file mode 100644
index 0000000..eb19361
--- /dev/null
+++ b/BalancedBite/android/app/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/BalancedBite/android/app/.project b/BalancedBite/android/app/.project
new file mode 100644
index 0000000..ac485d7
--- /dev/null
+++ b/BalancedBite/android/app/.project
@@ -0,0 +1,23 @@
+
+
+ app
+ Project app created by Buildship.
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.buildship.core.gradleprojectbuilder
+
+
+
+
+
+ org.eclipse.jdt.core.javanature
+ org.eclipse.buildship.core.gradleprojectnature
+
+
diff --git a/BalancedBite/android/app/.settings/org.eclipse.buildship.core.prefs b/BalancedBite/android/app/.settings/org.eclipse.buildship.core.prefs
new file mode 100644
index 0000000..b1886ad
--- /dev/null
+++ b/BalancedBite/android/app/.settings/org.eclipse.buildship.core.prefs
@@ -0,0 +1,2 @@
+connection.project.dir=..
+eclipse.preferences.version=1
diff --git a/new-gui/.expo/packager-info.json b/new-gui/.expo/packager-info.json
index ba74420..e63e1f9 100755
--- a/new-gui/.expo/packager-info.json
+++ b/new-gui/.expo/packager-info.json
@@ -1,10 +1,10 @@
{
- "expoServerNgrokUrl": "https://rp-cnx.anonymous.new-gui.exp.direct",
- "packagerNgrokUrl": "https://packager.rp-cnx.anonymous.new-gui.exp.direct",
- "ngrokPid": 19628,
- "packagerPort": 19001,
- "packagerPid": 8452,
+ "expoServerNgrokUrl": null,
+ "packagerNgrokUrl": null,
+ "ngrokPid": null,
+ "packagerPort": null,
+ "packagerPid": null,
"devToolsPort": 19002,
- "expoServerPort": 19000,
+ "expoServerPort": null,
"webpackServerPort": null
}
\ No newline at end of file
diff --git a/new-gui/.expo/settings.json b/new-gui/.expo/settings.json
index ad63e25..de4f26b 100755
--- a/new-gui/.expo/settings.json
+++ b/new-gui/.expo/settings.json
@@ -3,5 +3,5 @@
"lanType": "ip",
"dev": true,
"minify": false,
- "urlRandomness": "rp-cnx"
+ "urlRandomness": "c8-ats"
}
\ No newline at end of file
diff --git a/new-gui/src/commons/serverRequest/index.js b/new-gui/src/commons/serverRequest/index.js
index 6febc7d..c1e2222 100755
--- a/new-gui/src/commons/serverRequest/index.js
+++ b/new-gui/src/commons/serverRequest/index.js
@@ -1,2 +1,3 @@
-const HOST = "52.39.77.219";
+//const HOST = "52.39.77.219";
+const HOST = "174.77.40.238";
export const SERVER_URL = "http://" + HOST + ":8080";
\ No newline at end of file
diff --git a/new-gui/src/components/UserInformationPanel/index.js b/new-gui/src/components/UserInformationPanel/index.js
index 47e2313..52d28a7 100755
--- a/new-gui/src/components/UserInformationPanel/index.js
+++ b/new-gui/src/components/UserInformationPanel/index.js
@@ -1,11 +1,12 @@
import { mapDispatchToProps, mapStateToProps } from "../../commons/redux";
import React, { Component } from "react";
-import { Platform,StatusBar,View,SafeAreaView, Text, Button, SectionList, StyleSheet, TouchableHighlight,Image,TextInput,Dimensions,ImageBackground } from "react-native";
+import { Platform,StatusBar,View,SafeAreaView, Text,Alert, Button, SectionList, StyleSheet, TouchableHighlight,Image,TextInput,Dimensions,ImageBackground } from "react-native";
import { connect } from "react-redux";
import { withNavigation } from "react-navigation";
import { Ionicons } from '@expo/vector-icons';
import { SERVER_URL } from "../../commons/serverRequest";
-
+import Expo from "expo";
+import { Pedometer } from "expo";
import Svg from 'react-native-svg';
import { CheckBox,Input } from "react-native-elements";
@@ -22,33 +23,55 @@ class EditableLabel extends Component{
renderInput()
{
- if(typeof this.state.myText === "string" || typeof this.state.myText === "number")
+ if(this.props.type === "number" || this.props.type === "string")
{
return ( this._input = component}
textAlign="right"
+ keyboardType={this.props.type==="number"?"numeric":"default"}
style={styles.infoText}
onChangeText={(text) =>{this.setState({myText:text})}}
editable = {this.state.editable}
multiline = {false}
- onEndEditing={()=>{this.setState({editable:false}); this.props.receiver(this.props.fieldName,this.state.myText);}}
- value={this.state.myText.toString()}
+ onEndEditing={()=>{
+ this.setState({editable:false});
+ if(this.props.checker==null || this.props.checker(this.state.myText))
+ this.props.receiver(this.props.fieldName,this.props.type==="number"?parseInt(this.state.myText):this.state.myText);
+ else{
+ this.state.myText=this.props.value;
+ Alert.alert("Error", this.props.errorMessage, [{
+ text: "Okay"
+ }]);
+ }
+ }}
+ value={this.state.myText}
/>);
}
- else if(typeof this.state.myText === "boolean")
+ else if(this.props.type === "boolean")
{
return (
this._input = component}
right={true}
iconRight
- onPress={() => this.setState({myText: !this.state.myText,editable:false})}
+ onPress={()=>{
+ const val=!this.state.myText;
+ this.setState({editable:false,myText:!this.state.myText});
+ if(this.props.checker==null || this.props.checker(val))
+ this.props.receiver(this.props.fieldName,val);
+ else{
+ this.state.myText=this.props.value;
+ Alert.alert("Error", this.props.errorMessage, [{
+ text: "Okay"
+ }]);
+ }
+ }}
checked={this.state.myText}
disabled={!this.state.editable}
/>
);
}
- else if(Array.isArray(this.state.myText))
+ else if(this.props.type === "list")
{
return( this._input = component}
@@ -57,7 +80,17 @@ class EditableLabel extends Component{
onChangeText={(text) =>{this.setState({myText:text})}}
editable = {this.state.editable}
multiline = {false}
- onEndEditing={()=>{this.setState({editable:false}); console.warn(this.state.myText);this.props.receiver(this.props.fieldName,this.state.myText.split(",").filter(element => element.trim().length > 0));}}
+ onEndEditing={()=>{
+ this.setState({editable:false});
+ if(this.props.checker==null || this.props.checker(this.state.myText))
+ this.props.receiver(this.props.fieldName,this.state.myText.split(",").filter(element => element.trim().length > 0));
+ else{
+ this.state.myText=this.props.value;
+ Alert.alert("Error", this.props.errorMessage, [{
+ text: "Okay"
+ }]);
+ }
+ }}
value={this.state.myText}
/>);
}
@@ -85,26 +118,29 @@ class EditableLabel extends Component{
class UserInformationComponent extends Component {
-
- updateInformation(fieldName,fieldValue){
- fetch(UPDATE_URL, {
- method : "POST",
- body: JSON.stringify({token: this.props.currentToken, fieldName: fieldValue}),
- headers : {
- "Content-Type": "application/json"
- }
- })
- .then(res => res.json())
- .then(res => {
- console.warn(res);
- this.setState({userInfo:res},()=>{this.forceUpdate();});
- })
+
+ fetchStepCountThenGetInformation(){
+ const now = new Date();
+ const todayMidnight = new Date();
+ todayMidnight.setHours(0,0,0,0);
+ Pedometer.getStepCountAsync(todayMidnight,now).then(
+ result => {
+ this.setState({ pastStepCount: result.steps });
+ this.getInformation(result.steps);
+ },
+ error => {
+ this.setState({ pastStepCount: "N/A"});
+ this.getInformation(0);
+ }
+ );
}
- componentDidMount(){
+
+
+ getInformation(stepCount){
fetch(FETCH_URL, {
method: "POST",
- body: JSON.stringify({token: this.props.currentToken, distanceTraveled: 0.42, stepCount: 1055}),
+ body: JSON.stringify({token: this.props.currentToken, stepCount: stepCount}),
headers : {
"Content-Type" : "application/json"
}
@@ -123,17 +159,45 @@ class UserInformationComponent extends Component {
)
}
+ updateInformation(fieldName,fieldValue){
+ fetch(UPDATE_URL, {
+ method : "POST",
+ body: JSON.stringify({token: this.props.currentToken,fieldName:fieldName,fieldValue:fieldValue}),
+ headers : {
+ "Content-Type": "application/json"
+ }
+ })
+ .then(res => res.json())
+ .then(res => {
+ if(res.code==0){
+ console.warn("Fail to update");
+ }else{
+ this.fetchStepCountThenGetInformation();
+ }
+ })
+ }
+
+ componentWillMount(){
+ Pedometer.isAvailableAsync();
+ this.fetchStepCountThenGetInformation();
+ }
+
+ isNormalInteger(str) {
+ return /^\+?(0|[1-9]\d*)$/.test(str);
+ }
+
+
render() {
- if(this.state)
+ if(this.state && this.state.userInfo)
return (