Showing
7 changed files
with
109 additions
and
44 deletions
... | @@ -26,7 +26,8 @@ | ... | @@ -26,7 +26,8 @@ |
26 | "react-navigation": "^4.0.10", | 26 | "react-navigation": "^4.0.10", |
27 | "react-navigation-drawer": "^2.3.3", | 27 | "react-navigation-drawer": "^2.3.3", |
28 | "react-navigation-stack": "^1.10.3", | 28 | "react-navigation-stack": "^1.10.3", |
29 | - "react-navigation-tabs": "^2.5.6" | 29 | + "react-navigation-tabs": "^2.5.6", |
30 | + "realm": "^3.6.0" | ||
30 | }, | 31 | }, |
31 | "devDependencies": { | 32 | "devDependencies": { |
32 | "@babel/core": "^7.7.2", | 33 | "@babel/core": "^7.7.2", | ... | ... |
... | @@ -104,6 +104,9 @@ export default class HomeTab extends Component { | ... | @@ -104,6 +104,9 @@ export default class HomeTab extends Component { |
104 | /> | 104 | /> |
105 | } | 105 | } |
106 | > | 106 | > |
107 | + <View style={style.header}> | ||
108 | + <Text style={style.tabName}>History </Text> | ||
109 | + </View> | ||
107 | <Text>{this.state.title}</Text> | 110 | <Text>{this.state.title}</Text> |
108 | <SegmentedControlTab | 111 | <SegmentedControlTab |
109 | values={["Week", "Month", "Year"]} | 112 | values={["Week", "Month", "Year"]} |
... | @@ -121,5 +124,16 @@ const style = StyleSheet.create({ | ... | @@ -121,5 +124,16 @@ const style = StyleSheet.create({ |
121 | flex: 1, | 124 | flex: 1, |
122 | alignItems: 'center', | 125 | alignItems: 'center', |
123 | justifyContent: 'center', | 126 | justifyContent: 'center', |
127 | + }, | ||
128 | + header: { | ||
129 | + flex :1, | ||
130 | + justifyContent : 'center', | ||
131 | + }, | ||
132 | + tabName:{ | ||
133 | + marginStart : 10, | ||
134 | + textAlignVertical : 'center', | ||
135 | + fontSize : 20, | ||
136 | + color : "#0066cc", | ||
137 | + fontWeight: 'bold', | ||
124 | } | 138 | } |
125 | }) | 139 | }) |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | import React, { Component } from 'react'; | 1 | import React, { Component } from 'react'; |
2 | import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native'; | 2 | import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native'; |
3 | -import WasteDetail from '../WasteDetail' | ||
4 | import Circle from '../component/circle_component' | 3 | import Circle from '../component/circle_component' |
5 | import {Table, TableWrapper, Row,Rows} from 'react-native-table-component' | 4 | import {Table, TableWrapper, Row,Rows} from 'react-native-table-component' |
5 | +import {get_now_weight} from'../component/DBhelper.js'; | ||
6 | + | ||
6 | var date = new Date(); | 7 | var date = new Date(); |
7 | date.setHours(date.getHours()+9); | 8 | date.setHours(date.getHours()+9); |
8 | var month = date.getMonth()+1; | 9 | var month = date.getMonth()+1; |
... | @@ -16,7 +17,7 @@ export default class HomeTab extends Component { | ... | @@ -16,7 +17,7 @@ export default class HomeTab extends Component { |
16 | this.state = { | 17 | this.state = { |
17 | ID : this.props.navigation.getParam('id','pi1'), | 18 | ID : this.props.navigation.getParam('id','pi1'), |
18 | today : date.getFullYear() + "." + month + "." + date.getDate(), | 19 | today : date.getFullYear() + "." + month + "." + date.getDate(), |
19 | - current_weight : 0, | 20 | + current_weight : get_now_weight() , |
20 | table_contents : [['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','4:27:52', '+0.12kg', 'Total : 1.38kg'], | 21 | table_contents : [['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','4:27:52', '+0.12kg', 'Total : 1.38kg'], |
21 | ['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'], | 22 | ['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'], |
22 | ['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'], | 23 | ['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'], |
... | @@ -63,9 +64,9 @@ export default class HomeTab extends Component { | ... | @@ -63,9 +64,9 @@ export default class HomeTab extends Component { |
63 | <Text style ={style.date_text}>{this.state.today}</Text> | 64 | <Text style ={style.date_text}>{this.state.today}</Text> |
64 | </View> | 65 | </View> |
65 | </View> | 66 | </View> |
66 | - <View style={style.current_state}> | 67 | + <View style={this.state.current_weight}> |
67 | <Circle | 68 | <Circle |
68 | - title={"3.6"} | 69 | + title={this.state.current_weight} |
69 | onPress={()=>{this.get_diff_data()}}> | 70 | onPress={()=>{this.get_diff_data()}}> |
70 | </Circle> | 71 | </Circle> |
71 | </View> | 72 | </View> | ... | ... |
1 | import React, { Component } from 'react'; | 1 | import React, { Component } from 'react'; |
2 | import { StyleSheet, Text, View, TextInput, Image} from 'react-native'; | 2 | import { StyleSheet, Text, View, TextInput, Image} from 'react-native'; |
3 | import LoginButton from './component/LoginButton'; | 3 | import LoginButton from './component/LoginButton'; |
4 | +import {add_data} from'./component/DBhelper.js'; | ||
4 | 5 | ||
5 | export default class Login extends Component { | 6 | export default class Login extends Component { |
6 | 7 | ||
... | @@ -8,30 +9,24 @@ export default class Login extends Component { | ... | @@ -8,30 +9,24 @@ export default class Login extends Component { |
8 | super(props); | 9 | super(props); |
9 | this.state = { | 10 | this.state = { |
10 | ID: '', | 11 | ID: '', |
11 | - }; | 12 | + } |
12 | } | 13 | } |
13 | static navigationOptions = { | 14 | static navigationOptions = { |
14 | title: 'Login', | 15 | title: 'Login', |
15 | }; | 16 | }; |
16 | 17 | ||
17 | - /*handlePress = async () => { | 18 | + getdata() { |
18 | - fetch('http://localhost:3000/app/get_data/'+this.state.ID, { | 19 | + return fetch('http://10.0.2.2:3000/app/get_data/uid1') |
19 | - method: 'GET', | 20 | + .then((response) => response.json()) |
20 | - headers: { | 21 | + .then((responseJson) => { |
21 | - 'Content-Type': 'application/json', | 22 | + // alert(responseJson[0].ras_id.S); |
22 | - }, | 23 | + //alert(responseJson.length) |
23 | - }) | 24 | + add_data(responseJson); |
24 | - .then((response) => response.json()) | 25 | + }) |
25 | - .then((responseJson) => { | 26 | + .catch((error) => { |
26 | - Alert.alert("Author name at 0th index: " + responseJson[0].name); | 27 | + console.error(error); |
27 | - }) | 28 | + }); |
28 | - .catch((error) => { | 29 | + } |
29 | - console.error(error); | ||
30 | - }); | ||
31 | - } | ||
32 | - */ | ||
33 | - | ||
34 | - | ||
35 | 30 | ||
36 | render() { | 31 | render() { |
37 | return ( | 32 | return ( |
... | @@ -60,7 +55,8 @@ export default class Login extends Component { | ... | @@ -60,7 +55,8 @@ export default class Login extends Component { |
60 | onChangeText={(text) => {this.setState({ID:text})}} | 55 | onChangeText={(text) => {this.setState({ID:text})}} |
61 | /> | 56 | /> |
62 | <LoginButton | 57 | <LoginButton |
63 | - onPress={() =>{ this.props.navigation.navigate('MainScreen', { ID: this.state.ID }) }} | 58 | + // onPress={()=>getdata} |
59 | + onPress={() =>{ this.getdata().then(this.props.navigation.navigate('MainScreen', { ID: this.state.ID })) }} | ||
64 | /> | 60 | /> |
65 | </View> | 61 | </View> |
66 | </View> | 62 | </View> | ... | ... |
source/WasteDetail.js
deleted
100644 → 0
1 | -import React, { Component } from 'react'; | ||
2 | -import { View, Text, StyleSheet } from 'react-native'; | ||
3 | - | ||
4 | -export default class HomeTab extends Component { | ||
5 | - render() { | ||
6 | - return ( | ||
7 | - <View style={style.container}> | ||
8 | - <Text>총 3.8kg 추가</Text> | ||
9 | - </View> | ||
10 | - ); | ||
11 | - } | ||
12 | -} | ||
13 | - | ||
14 | -const style = StyleSheet.create({ | ||
15 | - container: { | ||
16 | - flex: 1, | ||
17 | - backgroundColor: "rgba(230,230,230,0.5)" | ||
18 | - } | ||
19 | -}); |
source/component/DBhelper.js
0 → 100644
1 | +// Define your models and their properties | ||
2 | +import Realm from 'realm' | ||
3 | + | ||
4 | +class Waste {} | ||
5 | +Waste.schema = { | ||
6 | + name: 'Waste', | ||
7 | + properties: { | ||
8 | + weight: 'int', | ||
9 | + diff: 'int', | ||
10 | + date: 'float', | ||
11 | + } | ||
12 | +}; | ||
13 | + | ||
14 | +// Get the default Realm with support for our objects | ||
15 | +let realm = new Realm({schema: [Waste]}); | ||
16 | + | ||
17 | +// // Create Realm objects and write to local storage | ||
18 | +// realm.write(() => { | ||
19 | +// let myWaste = realm.create('Waste', { | ||
20 | +// weight: 1655, | ||
21 | +// diff: 500, | ||
22 | +// date: '1576236841329.253', | ||
23 | +// }); | ||
24 | +// // myWaste.miles += 2SS0; // Update a property value | ||
25 | +// }); | ||
26 | + | ||
27 | +// // Query Realm for all cars with a high mileage | ||
28 | +// let wastes = realm.objects('Waste').filtered('weight > 1000'); | ||
29 | + | ||
30 | +// // Will return a Results object with our 1 car | ||
31 | +// cars.length // => 1 | ||
32 | + | ||
33 | +// // Add another car | ||
34 | +// realm.write(() => { | ||
35 | +// let myCar = realm.create('Car', { | ||
36 | +// make: 'Ford', | ||
37 | +// model: 'Focus', | ||
38 | +// miles: 2000, | ||
39 | +// }); | ||
40 | +// }); | ||
41 | +// // Query results are updated in realtime | ||
42 | +// cars.length // => 2 | ||
43 | + | ||
44 | +export function add_data(responseJson){ | ||
45 | + for(i = 0; i < responseJson.length; i++){ | ||
46 | + realm.write(() => { | ||
47 | + // responseJson[0].ras_id.S | ||
48 | + let myWaste = realm.create('Waste', { | ||
49 | + weight: Number(responseJson[i].weight.N), | ||
50 | + diff: Number(responseJson[i].diff.N), | ||
51 | + date: Number(responseJson[i].save_date.S), | ||
52 | + }); | ||
53 | + }); | ||
54 | + } | ||
55 | + | ||
56 | + return responseJson.length; | ||
57 | +} | ||
58 | + | ||
59 | +export function get_now_weight(){ | ||
60 | + let wastes = realm.objects('Waste'); | ||
61 | + let recent = realm.objects('Waste').max('date').date; | ||
62 | + let recentWeight = wastes.filtered('date = 1576223063238.5166'); | ||
63 | + | ||
64 | + return recentWeight[0].weight; | ||
65 | + | ||
66 | + // return "3.8" | ||
67 | +} | ||
68 | + | ||
69 | +export function get_recent_date(){ | ||
70 | + | ||
71 | + return realm.objects('Waste').max("date"); | ||
72 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment