Commit 85f3e6eb authored by Phuengton Chummuel's avatar Phuengton Chummuel

write & query reminder from database

parent 89ed8bd0
This diff is collapsed.
...@@ -12,20 +12,44 @@ import { ...@@ -12,20 +12,44 @@ import {
View, View,
Text Text
} from 'native-base'; } from 'native-base';
import {
Col,
Row,
Grid
} from 'react-native-easy-grid'
import AppHeader from './../components/Header'; import AppHeader from './../components/Header';
import Realm from 'realm';
let realm = new Realm({
schema: [{
name: 'Reminder',
properties: {
medName: 'string',
reminderTime: 'date'
}
}]
})
class HomeScreen extends Component { class HomeScreen extends Component {
constructor() { constructor() {
super(); super();
this.state = { this.state = {
active: false active: false,
today: this.formatDate(new Date(Date.now()))
}; };
} }
componentWillMount() {
let myReminder = realm.objects('Reminder')
ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.SHORT)
}
render() { render() {
var { containerStyle, timePeriodLeftStyle, timePeriodRightStyle, dateTitle } = styles;
return ( return (
<Container> <Container style={{ backgroundColor: 'white' }}>
<AppHeader <AppHeader
headerText={'Pill Minder'} headerText={'Pill Minder'}
headerLeft={ headerLeft={
...@@ -39,11 +63,50 @@ class HomeScreen extends Component { ...@@ -39,11 +63,50 @@ class HomeScreen extends Component {
</Button> </Button>
} }
/> />
<Content> <Content style={{ flex: 1 }}>
<Text style={dateTitle}>{this.state.today}</Text>
<Grid>
<Col>
<Row>
<View style={timePeriodLeftStyle}>
<Text>Morning</Text>
<View style={containerStyle}>
</View>
</View>
</Row>
<Row>
<View style={timePeriodLeftStyle}>
<Text>Afternoon</Text>
<View style={containerStyle}>
</View>
</View>
</Row>
</Col>
<Col>
<Row>
<View style={timePeriodRightStyle}>
<Text>Evening</Text>
<View style={containerStyle}>
</View>
</View>
</Row>
<Row>
<View style={timePeriodRightStyle}>
<Text>Night</Text>
<View style={containerStyle}>
</View>
</View>
</Row>
</Col>
</Grid>
</Content> </Content>
</Container> </Container >
) )
} }
onHomePressed() { onHomePressed() {
...@@ -61,6 +124,58 @@ class HomeScreen extends Component { ...@@ -61,6 +124,58 @@ class HomeScreen extends Component {
onMenuPressed() { onMenuPressed() {
this.props.navigation.navigate('DrawerToggle'); this.props.navigation.navigate('DrawerToggle');
} }
formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate();
var monthIndex = date.getMonth();
return 'Today, ' + day + ' ' + monthNames[monthIndex];
}
}
const styles = {
containerStyle: {
flex: 1,
backgroundColor: 'white',
borderWidth: 5,
borderRadius: 2,
borderColor: '#1686C4',
borderBottomWidth: 0,
elevation: 1,
padding: 10
},
timePeriodLeftStyle: {
flex: 1,
height: 200,
marginLeft: 20,
marginRight: 10,
marginTop: 20,
marginBottom: 20
},
timePeriodRightStyle: {
flex: 1,
height: 200,
marginLeft: 10,
marginRight: 20,
marginTop: 20,
marginBottom: 20
},
dateTitle: {
fontSize: 20,
textAlign: 'center',
marginTop: 20,
marginLeft: 20,
marginLeft: 20,
marginBottom: 10,
}
} }
export default HomeScreen; export default HomeScreen;
\ No newline at end of file
...@@ -16,9 +16,20 @@ import { ...@@ -16,9 +16,20 @@ import {
Radio, Radio,
Right Right
} from 'native-base'; } from 'native-base';
import DatePicker from 'react-native-datepicker' import DatePicker from 'react-native-datepicker';
import AppHeader from './../components/Header'; import AppHeader from './../components/Header';
import MedForm from '../components/MedForm'; import MedForm from '../components/MedForm';
import Realm from 'realm';
let realm = new Realm({
schema: [{
name: 'Reminder',
properties: {
medName: 'string',
reminderTime: 'date'
}
}]
})
class MedicationsScreen extends Component { class MedicationsScreen extends Component {
...@@ -27,17 +38,18 @@ class MedicationsScreen extends Component { ...@@ -27,17 +38,18 @@ class MedicationsScreen extends Component {
this.state = { this.state = {
text: "", text: "",
date: new Date(Date.now()).toISOString().split('T')[0], date: new Date(Date.now()).toISOString().split('T')[0],
reminderDate: new Date(Date.now()),
minDate: new Date(Date.now()).toISOString().split('T')[0], minDate: new Date(Date.now()).toISOString().split('T')[0],
hour: 0, morning: true,
minute: 0,
today: Date.now(),
morning: false,
lunch: false, lunch: false,
night: false night: false
}; };
} }
componentWillMount() { componentWillMount() {
this.init()
PushNotification.registerNotificationActions(['Yes', 'No']); PushNotification.registerNotificationActions(['Yes', 'No']);
DeviceEventEmitter.addListener('notificationActionReceived', function (action) { DeviceEventEmitter.addListener('notificationActionReceived', function (action) {
console.log('Notification action received: ' + action); console.log('Notification action received: ' + action);
...@@ -79,37 +91,24 @@ class MedicationsScreen extends Component { ...@@ -79,37 +91,24 @@ class MedicationsScreen extends Component {
</Form> </Form>
</MedForm> </MedForm>
{/* <MedForm titleText={"Reminder Time"}>
<DatePicker
style={timeStyle}
date={this.state.time}
mode="time"
format="HH:mm"
confirmBtnText="Confirm"
cancelBtnText="Cancel"
minuteInterval={10}
onDateChange={(time) => { this.setState({ time: time }); }}
/>
</MedForm> */}
<MedForm titleText={"Reminder Time"}> <MedForm titleText={"Reminder Time"}>
<Content> <Content>
<ListItem onPress={() => this._onReminderTimePresses("1")}> <ListItem onPress={() => this._onReminderTimePresses("1")}>
<Text>Morning</Text> <Text>Morning</Text>
<Right> <Right>
<Radio selected={this.state.morning} /> <Radio selected={this.state.morning} onPress={() => this._onReminderTimePresses("1")} />
</Right> </Right>
</ListItem> </ListItem>
<ListItem onPress={() => this._onReminderTimePresses("2")}> <ListItem onPress={() => this._onReminderTimePresses("2")}>
<Text>Lunch</Text> <Text>Lunch</Text>
<Right> <Right>
<Radio selected={this.state.lunch} /> <Radio selected={this.state.lunch} onPress={() => this._onReminderTimePresses("2")} />
</Right> </Right>
</ListItem> </ListItem>
<ListItem onPress={() => this._onReminderTimePresses("3")}> <ListItem onPress={() => this._onReminderTimePresses("3")}>
<Text>Night</Text> <Text>Night</Text>
<Right> <Right>
<Radio selected={this.state.night} /> <Radio selected={this.state.night} onPress={() => this._onReminderTimePresses("3")} />
</Right> </Right>
</ListItem> </ListItem>
</Content> </Content>
...@@ -130,7 +129,7 @@ class MedicationsScreen extends Component { ...@@ -130,7 +129,7 @@ class MedicationsScreen extends Component {
</MedForm> </MedForm>
<View> <View>
<Button style={btnAddNoti}> <Button style={btnAddNoti} onPress={() => this._onResetPressed()}>
<Text style={{ color: "#1686C4" }}>Reset</Text> <Text style={{ color: "#1686C4" }}>Reset</Text>
</Button> </Button>
...@@ -145,6 +144,28 @@ class MedicationsScreen extends Component { ...@@ -145,6 +144,28 @@ class MedicationsScreen extends Component {
) )
}; };
init() {
}
setReminderDate() {
var reminderDate = this.state.reminderDate
if (this.state.morning) {
reminderDate = new Date(this.state.date).setHours(8, 0, 0, 0)
} else if (this.state.lunch) {
reminderDate = new Date(this.state.date).setHours(12, 0, 0, 0)
} else if (this.state.night) {
reminderDate = new Date(this.state.date).setHours(21, 0, 0, 0)
}
reminderDate = new Date(reminderDate)
this.setState({ reminderDate })
}
_setNotification() { _setNotification() {
// if (this.state.text) { // if (this.state.text) {
// PushNotification.localNotificationSchedule({ // PushNotification.localNotificationSchedule({
...@@ -156,25 +177,33 @@ class MedicationsScreen extends Component { ...@@ -156,25 +177,33 @@ class MedicationsScreen extends Component {
// }) // })
// } // }
var reminderDate = new Date(this.state.date).setHours(0, 0, 0, 0) if (this.state.text) {
reminderDate = new Date(reminderDate) realm.write(() => {
realm.create('Reminder', {
medName: this.state.text,
reminderTime: this.state.reminderDate
})
})
}
ToastAndroid.show(this.state.reminderDate.toString(), ToastAndroid.SHORT)
this.setState({ date: reminderDate })
ToastAndroid.show(this.state.date.toString(), ToastAndroid.SHORT)
} }
_onReminderTimePresses(id) { _onReminderTimePresses(id) {
switch (id) { switch (id) {
case '1': case '1':
this.setState({ morning: !this.state.morning, lunch: false, night: false }) this.setState({ morning: !this.state.morning, lunch: false, night: false })
this.setReminderDate()
break break
case '2': case '2':
this.setState({ lunch: !this.state.lunch, morning: false, night: false }) this.setState({ lunch: !this.state.lunch, morning: false, night: false })
this.setReminderDate()
break break
case '3': case '3':
this.setState({ night: !this.state.night, morning: false, lunch: false }) this.setState({ night: !this.state.night, morning: false, lunch: false })
this.setReminderDate()
break break
} }
} }
...@@ -182,6 +211,12 @@ class MedicationsScreen extends Component { ...@@ -182,6 +211,12 @@ class MedicationsScreen extends Component {
_onMenuPressed() { _onMenuPressed() {
this.props.navigation.navigate("DrawerToggle"); this.props.navigation.navigate("DrawerToggle");
} }
_onResetPressed() {
let myReminder = realm.objects('Reminder')
ToastAndroid.show(JSON.stringify(myReminder), ToastAndroid.SHORT)
}
}; };
const styles = { const styles = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment