1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # iOS variant using a button to check in/out and local notifications
19 intrude import app
::ui
25 redef class HomeWindow
30 checkin_button
.observers
.add
self
33 # TODO hide when not logged in
34 private var layout_login_checkin
= new HorizontalLayout(parent
=layout_user
)
35 private var checkin_label
= new Label(parent
=layout_login_checkin
)
36 private var checkin_button
= new Button(parent
=layout_login_checkin
)
38 redef fun on_event
(event
)
42 if event
isa ButtonPressEvent then
43 var sender
= event
.sender
44 if sender
== checkin_button
then
45 if app
.currently_on_location
then
52 private fun update_checkin_text
54 if app
.currently_on_location
then
55 checkin_label
.text
= "Leaving?".t
56 checkin_button
.text
= "Check out".t
58 checkin_label
.text
= "On location?".t
59 checkin_button
.text
= "Check in".t
69 if window
isa HomeWindow then window
.update_checkin_text
72 redef fun on_check_out
76 if window
isa HomeWindow then window
.update_checkin_text
79 redef fun did_finish_launching_with_options
81 ui_application
.register_user_notification_settings
86 redef class UserWindow
87 init do title
= "Preferences".t
90 redef class BeersWindow
91 init do title
= "Beers".t
94 redef class SocialWindow
95 init do title
= "People".t
100 redef fun notify
(title
, content
, id
)
101 do native_notify
(title
.to_nsstring
, content
.to_nsstring
)
103 private fun native_notify
(title
, content
: NSString) in "ObjC" `{
104 UILocalNotification* notif = [[UILocalNotification alloc] init];
105 notif.alertTitle = title;
106 notif.alertBody = content;
107 notif.timeZone = [NSTimeZone defaultTimeZone];
108 [[UIApplication sharedApplication] presentLocalNotificationNow: notif];
111 redef class UIApplication
113 # Register this app to display notifications
114 private fun register_user_notification_settings
116 if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
117 [self registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
126 # Ellipsize `text` so it fits within `max_length` characters
128 # FIXME Remove this when labels are correctly ellipsized on iOS.
129 redef fun text
=(text
)
137 if parent
isa HorizontalLayout and parent
.parent
isa BeerView then
138 # This is the name of a beer, remember its a hack
142 if text
.length
> max_length
then
143 text
= text
.substring
(0, max_length
- 3).to_s
+ "..."