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
32 # TODO hide when not logged in
33 private var layout_login_checkin
= new HorizontalLayout(parent
=layout_user
)
34 private var checkin_label
= new Label(parent
=layout_login_checkin
)
35 private var checkin_button
= new Button(parent
=layout_login_checkin
)
37 redef fun on_event
(event
)
41 if event
isa ButtonPressEvent then
42 var sender
= event
.sender
43 if sender
== checkin_button
then
44 if app
.currently_on_location
then
51 private fun update_checkin_text
53 if app
.currently_on_location
then
54 checkin_label
.text
= "Leaving?".t
55 checkin_button
.text
= "Check out".t
57 checkin_label
.text
= "On location?".t
58 checkin_button
.text
= "Check in".t
68 if window
isa HomeWindow then window
.update_checkin_text
71 redef fun on_check_out
75 if window
isa HomeWindow then window
.update_checkin_text
78 redef fun did_finish_launching_with_options
80 ui_application
.register_user_notification_settings
85 redef class UserWindow
86 init do title
= "Preferences".t
89 redef class BeersWindow
90 init do title
= "Beers".t
93 redef class SocialWindow
94 init do title
= "People".t
99 redef fun notify
(title
, content
, id
)
100 do native_notify
(title
.to_nsstring
, content
.to_nsstring
)
102 private fun native_notify
(title
, content
: NSString) in "ObjC" `{
103 UILocalNotification* notif = [[UILocalNotification alloc] init];
104 notif.alertTitle = title;
105 notif.alertBody = content;
106 notif.timeZone = [NSTimeZone defaultTimeZone];
107 [[UIApplication sharedApplication] presentLocalNotificationNow: notif];
110 redef class UIApplication
112 # Register this app to display notifications
113 private fun register_user_notification_settings
115 if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
116 [self registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];
125 # Ellipsize `text` so it fits within `max_length` characters
127 # FIXME Remove this when labels are correctly ellipsized on iOS.
128 redef fun text
=(text
)
136 if parent
isa HorizontalLayout and parent
.parent
isa BeerView then
137 # This is the name of a beer, remember its a hack
141 if text
.length
> max_length
then
142 text
= text
.substring
(0, max_length
- 3).to_s
+ "..."