Showing
4 changed files
with
53 additions
and
8 deletions
... | @@ -5,6 +5,7 @@ import { createStackNavigator } from 'react-navigation-stack' | ... | @@ -5,6 +5,7 @@ import { createStackNavigator } from 'react-navigation-stack' |
5 | // import MainScreen from './components/MainScreen'; | 5 | // import MainScreen from './components/MainScreen'; |
6 | import Login from './source/Login'; | 6 | import Login from './source/Login'; |
7 | import MainScreen from './source/MainScreen'; | 7 | import MainScreen from './source/MainScreen'; |
8 | +import {getId} from './source/component/DBhelper' | ||
8 | 9 | ||
9 | // const AppStackNavigator = createStackNavigator({ | 10 | // const AppStackNavigator = createStackNavigator({ |
10 | // Main:{ | 11 | // Main:{ |
... | @@ -14,11 +15,18 @@ import MainScreen from './source/MainScreen'; | ... | @@ -14,11 +15,18 @@ import MainScreen from './source/MainScreen'; |
14 | 15 | ||
15 | // export default createAppContainer(AppStackNavigator); | 16 | // export default createAppContainer(AppStackNavigator); |
16 | 17 | ||
18 | +var initialName = '' | ||
19 | + | ||
20 | +if(getId() == true){ | ||
21 | + initialName = 'MainScreen' | ||
22 | +} | ||
23 | +else initialName = 'Login' | ||
24 | + | ||
17 | const MainNavigator = createStackNavigator({ | 25 | const MainNavigator = createStackNavigator({ |
18 | Login : {screen: Login}, | 26 | Login : {screen: Login}, |
19 | MainScreen : {screen:MainScreen}, | 27 | MainScreen : {screen:MainScreen}, |
20 | }, | 28 | }, |
21 | - {initialRouteName: 'Login',headerMode:'none'} | 29 | + {initialRouteName: initialName,headerMode:'none'} |
22 | ); | 30 | ); |
23 | 31 | ||
24 | const App = createAppContainer(MainNavigator); | 32 | const App = createAppContainer(MainNavigator); | ... | ... |
1 | import React, { Component } from 'react'; | 1 | import React, { Component } from 'react'; |
2 | import { View, Text, StyleSheet, TextInput, TouchableOpacity, Image } from 'react-native'; | 2 | import { View, Text, StyleSheet, TextInput, TouchableOpacity, Image } from 'react-native'; |
3 | import AddButton from '../component/AddButton' | 3 | import AddButton from '../component/AddButton' |
4 | -import {delete_all_data} from '../component/DBhelper' | 4 | +import {delete_all_data, deleteId} from '../component/DBhelper' |
5 | 5 | ||
6 | var date = new Date(); | 6 | var date = new Date(); |
7 | date.setHours(date.getHours()+9); | 7 | date.setHours(date.getHours()+9); |
... | @@ -40,7 +40,9 @@ export default class SettingTab extends Component { | ... | @@ -40,7 +40,9 @@ export default class SettingTab extends Component { |
40 | delete_id(){ | 40 | delete_id(){ |
41 | this.setState({ID: ''}) | 41 | this.setState({ID: ''}) |
42 | //save_app_data() | 42 | //save_app_data() |
43 | - delete_all_data() | 43 | + //delete_all_data() |
44 | + deleteId() | ||
45 | + this.props.navigation.navigate('Login'); | ||
44 | } | 46 | } |
45 | render() { | 47 | render() { |
46 | return ( | 48 | return ( | ... | ... |
... | @@ -5,6 +5,7 @@ import { createMaterialTopTabNavigator } from 'react-navigation-tabs' | ... | @@ -5,6 +5,7 @@ import { createMaterialTopTabNavigator } from 'react-navigation-tabs' |
5 | import HomeTab from './AppTabNavigator/HomeTab' | 5 | import HomeTab from './AppTabNavigator/HomeTab' |
6 | import HistoryTab from './AppTabNavigator/HistoryTab' | 6 | import HistoryTab from './AppTabNavigator/HistoryTab' |
7 | import SettingTab from './AppTabNavigator/SettingTab' | 7 | import SettingTab from './AppTabNavigator/SettingTab' |
8 | +import {registerID} from '../source/component/DBhelper' | ||
8 | 9 | ||
9 | // 하단 탭 네비게이터 생성 | 10 | // 하단 탭 네비게이터 생성 |
10 | const AppTabNavigator = createMaterialTopTabNavigator({ | 11 | const AppTabNavigator = createMaterialTopTabNavigator({ |
... | @@ -39,14 +40,14 @@ export default class MainScreen extends Component { | ... | @@ -39,14 +40,14 @@ export default class MainScreen extends Component { |
39 | constructor(props) { | 40 | constructor(props) { |
40 | super(props); | 41 | super(props); |
41 | this.state = { | 42 | this.state = { |
42 | - ID: this.props.navigation.getParam('ID'), | 43 | + ID: this.props.navigation.getParam('ID',''), |
43 | }; | 44 | }; |
44 | } | 45 | } |
45 | - | ||
46 | static navigationOptions = { | 46 | static navigationOptions = { |
47 | title: 'FW IOT' } | 47 | title: 'FW IOT' } |
48 | 48 | ||
49 | render() { | 49 | render() { |
50 | + //registerID(this.state.ID); | ||
50 | return <AppTabContainet/>; // AppTabContainet 컴포넌트를 리턴한다. | 51 | return <AppTabContainet/>; // AppTabContainet 컴포넌트를 리턴한다. |
51 | } | 52 | } |
52 | } | 53 | } | ... | ... |
... | @@ -11,9 +11,41 @@ Waste.schema = { | ... | @@ -11,9 +11,41 @@ Waste.schema = { |
11 | } | 11 | } |
12 | }; | 12 | }; |
13 | 13 | ||
14 | -// Get the default Realm with support for our objects | 14 | +class ID {} |
15 | -let realm = new Realm({schema: [Waste]}); | 15 | +ID.schema={ |
16 | + name:'ID', | ||
17 | + properties:{ | ||
18 | + id : 'string', | ||
19 | + } | ||
20 | +}; | ||
16 | 21 | ||
22 | +export function registerID(_id){ | ||
23 | + if(_id != ''){ | ||
24 | + realm.write(()=>{ | ||
25 | + let user = realm.create('ID',{id:_id}); | ||
26 | + console.log('success') | ||
27 | + }); | ||
28 | + } | ||
29 | +} | ||
30 | + | ||
31 | +export function getId(){ | ||
32 | + let user = realm.objects('ID'); | ||
33 | + console.log(user.length); | ||
34 | + if(user.length>0) | ||
35 | + return true; | ||
36 | + return false; | ||
37 | +} | ||
38 | + | ||
39 | +export function deleteId(){ | ||
40 | + let user = realm.objects('ID'); | ||
41 | + realm.write(()=>{ | ||
42 | + realm.delete(user); | ||
43 | + console.log('success') | ||
44 | + }) | ||
45 | +} | ||
46 | + | ||
47 | +// Get the default Realm with support for our objects | ||
48 | +let realm = new Realm({schema: [Waste, ID]}); | ||
17 | export function add_data(responseJson){ | 49 | export function add_data(responseJson){ |
18 | for(i = 0; i < responseJson.length; i++){ | 50 | for(i = 0; i < responseJson.length; i++){ |
19 | realm.write(() => { | 51 | realm.write(() => { |
... | @@ -36,7 +68,9 @@ export function get_now_weight(){ | ... | @@ -36,7 +68,9 @@ export function get_now_weight(){ |
36 | 68 | ||
37 | var recentWeight = wastes.filtered('date = $0', recent); | 69 | var recentWeight = wastes.filtered('date = $0', recent); |
38 | console.log("now_weight",recentWeight) | 70 | console.log("now_weight",recentWeight) |
39 | - return recentWeight[0].weight; | 71 | + if(recentWeight.length != 0) |
72 | + return recentWeight[0].weight; | ||
73 | + else return 0; | ||
40 | } | 74 | } |
41 | 75 | ||
42 | export function get_last_update(){ | 76 | export function get_last_update(){ | ... | ... |
-
Please register or login to post a comment