benitlux: move manual checkin feature to its own module
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 2 Jan 2017 19:28:08 +0000 (14:28 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Mon, 2 Jan 2017 19:45:03 +0000 (14:45 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/benitlux/src/client/features/manual_checkins.nit [new file with mode: 0644]
contrib/benitlux/src/client/ios.nit

diff --git a/contrib/benitlux/src/client/features/manual_checkins.nit b/contrib/benitlux/src/client/features/manual_checkins.nit
new file mode 100644 (file)
index 0000000..946b667
--- /dev/null
@@ -0,0 +1,74 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Variation adding a button to manually check in and out
+module manual_checkins
+
+import checkins
+
+redef class HomeWindow
+
+       redef fun refresh
+       do
+               super
+               update_checkin_text
+       end
+
+       private var checkin_button = new Button(parent=layout_user, align=0.0)
+
+       redef fun on_event(event)
+       do
+               super
+
+               if event isa ButtonPressEvent then
+                       var sender = event.sender
+                       if sender == checkin_button then
+                               if app.currently_on_location then
+                                       app.on_check_out
+                               else app.on_check_in
+                       end
+               end
+       end
+
+       private fun update_checkin_text
+       do
+               if app.user != null then
+                       if app.currently_on_location then
+                               checkin_button.text = "Leaving? Check out".t
+                       else
+                               checkin_button.text = "On location? Check in".t
+                       end
+                       checkin_button.enabled = true
+               else
+                       checkin_button.text = "Login to check in".t
+                       checkin_button.enabled = false
+               end
+       end
+end
+
+redef class App
+       redef fun on_check_in
+       do
+               super
+               var window = window
+               if window isa HomeWindow then window.update_checkin_text
+       end
+
+       redef fun on_check_out
+       do
+               super
+               var window = window
+               if window isa HomeWindow then window.update_checkin_text
+       end
+end
index 194ab9b..5462cc2 100644 (file)
@@ -21,6 +21,7 @@ intrude import app::ui
 import client
 import push
 import checkins
+import manual_checkins
 intrude import user_views
 
 redef class HomeWindow
@@ -30,34 +31,6 @@ redef class HomeWindow
 
                # Force equal height for `news_header`
                var b = new Button(text="", parent=news_header)
-               update_checkin_text
-       end
-
-       private var checkin_button = new Button(parent=layout_user, align=0.0)
-
-       redef fun on_event(event)
-       do
-               super
-
-               if event isa ButtonPressEvent then
-                       var sender = event.sender
-                       if sender == checkin_button then
-                               if app.currently_on_location then
-                                       app.on_check_out
-                               else app.on_check_in
-                       end
-               end
-       end
-
-       private fun update_checkin_text
-       do
-               if app.currently_on_location then
-                       checkin_label.text = "Leaving?".t
-                       checkin_button.text = "Check out".t
-               else
-                       checkin_label.text = "On location?".t
-                       checkin_button.text = "Check in".t
-               end
        end
 end
 
@@ -81,20 +54,6 @@ redef class SignupWindow
 end
 
 redef class App
-       redef fun on_check_in
-       do
-               super
-               var window = window
-               if window isa HomeWindow then window.update_checkin_text
-       end
-
-       redef fun on_check_out
-       do
-               super
-               var window = window
-               if window isa HomeWindow then window.update_checkin_text
-       end
-
        redef fun did_finish_launching_with_options
        do
                ui_application.register_user_notification_settings