Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
pill_minder
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Phuengton Chummuel
pill_minder
Commits
85f3e6eb
Commit
85f3e6eb
authored
Feb 05, 2018
by
Phuengton Chummuel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
write & query reminder from database
parent
89ed8bd0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
181 additions
and
30 deletions
+181
-30
package-lock.json
package-lock.json
+0
-0
HomeScreen.js
src/screens/HomeScreen.js
+120
-4
MedicationsScreen.js
src/screens/MedicationsScreen.js
+61
-26
No files found.
package-lock.json
View file @
85f3e6eb
This diff is collapsed.
Click to expand it.
src/screens/HomeScreen.js
View file @
85f3e6eb
...
@@ -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
src/screens/MedicationsScreen.js
View file @
85f3e6eb
...
@@ -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
=
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment