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
24 import manual_checkins
25 intrude import user_views
27 redef class HomeWindow
32 # Force equal height for `news_header`
33 var b
= new Button(text
="", parent
=news_header
)
37 redef class SignupWindow
40 title
= "Login or Signup".t
41 txt_name
.native
.disable_autocorrect
42 txt_name
.placeholder
= "Name".t
43 txt_pass
.placeholder
= "Password".t
44 txt_pass2
.placeholder
= "Password".t
45 txt_email
.placeholder
= "example@example.com".t
46 lbl_feedback
.native
.text_color
= new UIColor.red_color
47 lbl_feedback
.align
= 0.5
49 for l
in [layout_login
, layout_signup
] do
50 l
.native
.spacing
= 8.0
51 l
.native
.set_layout_margins
(16.0, 8.0)
57 redef fun did_finish_launching_with_options
59 ui_application
.register_user_notification_settings
64 redef class UserWindow
66 title
= "Preferences".t
67 lbl_welcome
.align
= 0.5
71 redef class BeersWindow
72 init do title
= "Beers".t
75 redef class SocialWindow
78 txt_query
.placeholder
= "Name".t
80 txt_query
.native
.disable_autocorrect
85 init do native
.text_color
= new UIColor.dark_gray_color
88 redef class SectionTitle
90 native
.text_color
= new UIColor.init_with_white_alpha
(0.4, 1.0)
95 redef class SectionHeader
97 native
.layout_margins_relative_arrangement
= true
98 native
.set_layout_margins
(16.0, 4.0)
105 if native
isa UIStackView then
106 native
.set_layout_margins
(16.0, 2.0)
107 native
.layout_margins_relative_arrangement
= true
109 native
.background_color
= new UIColor.white_color
110 native
.set_white_background
118 native
.set_layout_margins
(16.0, 8.0)
122 redef class ListLayout
123 init do native
.background_color
= new UIColor.group_table_view_background_color
126 redef class CheckBox super ItemView end
132 private fun set_layout_margins
(margin
, margin_y
: Float)
134 self.layoutMargins = UIEdgeInsetsMake(margin_y, margin, margin_y, margin);
137 private fun set_white_background
139 UIView *colored_view = [[UIView alloc] initWithFrame:self.bounds];
140 colored_view.backgroundColor = [UIColor whiteColor];
141 colored_view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
142 [self insertSubview:colored_view atIndex:0];
144 [colored_view.layer setBorderColor: [[UIColor colorWithWhite:0.8 alpha:1.0] CGColor]];
145 [colored_view.layer setBorderWidth: 0.5];
149 redef class UITextField
150 private fun disable_autocorrect
152 self.autocorrectionType = UITextAutocorrectionTypeNo;
153 self.autocapitalizationType = UITextAutocapitalizationTypeNone;
160 redef fun notify
(title
, content
, id
)
161 do native_notify
(title
.to_nsstring
, content
.to_nsstring
)
163 private fun native_notify
(title
, content
: NSString) in "ObjC" `{
164 UILocalNotification* notif = [[UILocalNotification alloc] init];
165 notif.alertTitle = title;
166 notif.alertBody = content;
167 notif.timeZone = [NSTimeZone defaultTimeZone];
168 [[UIApplication sharedApplication] presentLocalNotificationNow: notif];
171 redef class UIApplication
173 # Register this app to display notifications
174 private fun register_user_notification_settings
176 if ([UIApplication instancesRespondToSelector:@selector(registerUserNotificationSettings:)]){
177 [self registerUserNotificationSettings:[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert|UIUserNotificationTypeBadge|UIUserNotificationTypeSound categories:nil]];