Skip to content

Commit

Permalink
make information panel great again!
Browse files Browse the repository at this point in the history
  • Loading branch information
hiseen committed Mar 14, 2019
1 parent 8218777 commit 27a1b90
Show file tree
Hide file tree
Showing 16 changed files with 244 additions and 88 deletions.
17 changes: 17 additions & 0 deletions BalancedBite/android/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>BalancedBite</name>
<comment>Project android created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=
eclipse.preferences.version=1
6 changes: 6 additions & 0 deletions BalancedBite/android/app/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="output" path="bin/default"/>
</classpath>
23 changes: 23 additions & 0 deletions BalancedBite/android/app/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>app</name>
<comment>Project app created by Buildship.</comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
connection.project.dir=..
eclipse.preferences.version=1
12 changes: 6 additions & 6 deletions new-gui/.expo/packager-info.json
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion new-gui/.expo/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"lanType": "ip",
"dev": true,
"minify": false,
"urlRandomness": "rp-cnx"
"urlRandomness": "c8-ats"
}
3 changes: 2 additions & 1 deletion new-gui/src/commons/serverRequest/index.js
Original file line number Diff line number Diff line change
@@ -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";
169 changes: 126 additions & 43 deletions new-gui/src/components/UserInformationPanel/index.js
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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 (<TextInput
ref={component => 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 (<View style={{width:"40%"}}>
<CheckBox
ref={component => 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}
/></View>
);
}
else if(Array.isArray(this.state.myText))
else if(this.props.type === "list")
{
return(<TextInput
ref={component => this._input = component}
Expand All @@ -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}
/>);
}
Expand Down Expand Up @@ -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"
}
Expand All @@ -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 (
<SafeAreaView style={styles.container}>
<Svg alignSelf="center" width={300*scaleAvatar} height={486*scaleAvatar}>
<Svg.Rect
scale={scaleAvatar}
x={0}
y={2000/4200*486}
y={(this.state.userInfo.caloriesNeeded-this.state.userInfo.caloriesTakenCurrently)/this.state.userInfo.caloriesNeeded*486}
width={300}
height={2200/4200*486}
height={this.state.userInfo.caloriesTakenCurrently/this.state.userInfo.caloriesNeeded*486}
strokeWidth={0}
fill="#3CB371"
/>
Expand All @@ -144,27 +208,46 @@ class UserInformationComponent extends Component {
stickySectionHeadersEnabled={true}
renderItem={({item, index, section}) => {
if(section.title==="Health Infomation")
return (<View><View style={styles.sectionListItem}><Text style={{width:"40%"}} key={index}>{item[0]+": "}</Text><Text style={{width:"50%", textAlign:"right"}}>{item[1]+" "+item[2]}</Text></View><View style={styles.sectionPadding}></View></View>);
return (<View>
<View style={styles.sectionListItem}>
<Text style={{width:"40%"}} key={index}>{item[0]+": "}</Text>
<Text style={{width:"50%", textAlign:"right"}}>{item[1]+" "+item[2]}</Text>
</View>
<View style={styles.sectionPadding}></View>
</View>);
else
return (<View><EditableLabel title={item[0]} value={item[1]} unit={item[2]} fieldName={item[3]} receiver={(k,v)=>this.updateInformation(k,v)}></EditableLabel><View style={styles.sectionPadding}></View></View>);
return (<View>
<EditableLabel
title={item[0]}
value={item[1]}
unit={item[2]}
fieldName={item[3]}
checker={item[4]}
errorMessage={item[5]}
type={item[6]}
receiver={(k,v)=>this.updateInformation(k,v)}>
</EditableLabel>
<View style={styles.sectionPadding}></View>
</View>);
}}
renderSectionHeader={({section: {title}}) => (
<Text style={styles.sectionHeader}>{title}</Text>
)}
sections={[
{title: 'Health Infomation', data: [["BMI",this.state.userInfo.bmi.toFixed(2),""],
["Calories Needed",4200,"Cal"],
["Step Count",999,""],
["Distance Traveled",1253,"m"]]},
{title: 'User Infomation', data: [['Age',this.state.userInfo.age,'','age'],
['Weight',this.state.userInfo.weight,'kg','weight'],
['Height',this.state.userInfo.height,'cm','height'],
['HealthProblems',this.state.userInfo.healthProblems.join(),"","healthProblems"],
['DislikeFoods',this.state.userInfo.dislikeFoods.join(),"","dislikeFoods"],
['Allergies',this.state.userInfo.allergies.join(),"","alleriges"],
['Workout',this.state.userInfo.workoutBoolean,"","workoutBoolean"],
['WorkoutFrequency',this.state.userInfo.workoutFrequency,"","workoutFrequency"],
['WorkoutType',this.state.userInfo.workoutType,"","workoutType"]]},
{title: 'Health Infomation', data: [["BMI",this.state.userInfo.bmi?this.state.userInfo.bmi.toFixed(2):0,""],
["Calories Needed",this.state.userInfo.caloriesNeeded,"Cal(s)"],
["Calories Taken",this.state.userInfo.caloriesTakenCurrently,"Cal(s)"],
["Foods Eaten",this.state.userInfo.foodsEatenCurrently.join(),""],
["Step Count",this.state.pastStepCount,""]]},
{title: 'User Infomation', data: [['Age',this.state.userInfo.age.toString(),'','age',(x)=>this.isNormalInteger(x) && parseInt(x)<150,"Age is not valid(1-150)!","number"],
['Weight',this.state.userInfo.weight.toString(),'kg','weight',(x)=>this.isNormalInteger(x) && parseInt(x)<1000,"Weight is not valid(1-1000)!","number"],
['Height',this.state.userInfo.height.toString(),'cm','height',(x)=>this.isNormalInteger(x) && parseInt(x)<1000,"Height is not valid(1-1000)!","number"],
['HealthProblems',this.state.userInfo.healthProblems.join(),"","healthProblems",null,null,"list"],
['DislikeFoods',this.state.userInfo.dislikeFoods.join(),"","dislikeFoods",null,null,"list"],
['Allergies',this.state.userInfo.allergies.join(),"","alleriges",null,null,"list"],
['Workout',this.state.userInfo.workoutBoolean,"","workoutBoolean",null,null,"boolean"],
['WorkoutFrequency',this.state.userInfo.workoutFrequency.toString(),"","workoutFrequency",(x)=>this.isNormalInteger(x) && parseInt(x)<=7,"Workout Frequency should be an integer between 0 and 7!","number"],
['WorkoutType',this.state.userInfo.workoutType,"","workoutType",null,null,"string"]]},
]}
keyExtractor={(item, index) => item + index}
/>
Expand Down
2 changes: 1 addition & 1 deletion new-gui/src/components/UserSignupPanel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class UserSignupPanel extends Component {
}
);
} else {
Alert.alert("Error", "User was not added successfully", [{
Alert.alert("Error", "User already exists", [{
text: "Okay"
}])
}
Expand Down
Binary file added new-gui/src/images/person.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 27a1b90

Please sign in to comment.