Turn lift date and time strings into struct Time
[beifahrer] / src / lift-list-window.vala
index ead447a..f932a7b 100644 (file)
@@ -95,14 +95,19 @@ public class LiftListWindow : StackableWindow {
 
                add (vbox);
 
+               vbox.show_all ();
+               no_lifts.hide ();
+               route_column.set_visible (!BeifahrerProgram.orientation.portrait);
+
                tree.row_activated.connect (this.on_row_activated);
                BeifahrerProgram.orientation.changed.connect (this.on_orientation_changed);
        }
 
-       public void find_lifts (string city_from, string city_to, Date date) {
+       public async void find_lifts (string city_from, string city_to, Date date, int tolerance = 0) {
                set_title ("%s - %s".printf (city_from, city_to));
+               Hildon.gtk_window_set_progress_indicator (this, 1);
 
-               var lift_list = adac.get_lift_list (city_from, city_to, date);
+               var lift_list = yield adac.get_lift_list (city_from, city_to, date, tolerance);
                foreach (Lift lift in lift_list) {
                        TreeIter iter;
                        string icon_name = null;
@@ -110,16 +115,20 @@ public class LiftListWindow : StackableWindow {
                                icon_name = "beifahrer_smoker";
                        else if (LiftFlags.NON_SMOKER in lift.flags)
                                icon_name = "beifahrer_non_smoker";
+                       string datetime = "%02d.%02d.%04d".printf (lift.time.day, lift.time.month, lift.time.year);
+                       if (lift.time.hour >= 0)
+                               datetime += ", %d:%02d".printf (lift.time.hour, lift.time.minute);
                        store.insert_with_values (out iter, -1, 0, lift.city_from + " - " + lift.city_to,
-                                                               1, (lift.time != null) ? (lift.date + ", " + lift.time) : lift.date,
+                                                               1, datetime,
                                                                2, _("%d pl.").printf (lift.places),
                                                                3, lift.price,
                                                                4, icon_name,
                                                                5, lift);
                        // (LiftFlags.WOMEN_ONLY,ADAC_MEMBER in lift.flags)
                }
-               if (lift_list.length () > 0)
-                       no_lifts.hide ();
+               if (lift_list.length () == 0)
+                       no_lifts.show ();
+               Hildon.gtk_window_set_progress_indicator (this, 0);
        }
 
        private void on_row_activated (TreeView tree, TreePath /*_*/path, TreeViewColumn column) {
@@ -130,25 +139,12 @@ public class LiftListWindow : StackableWindow {
                if (model.get_iter (out iter, path)) {
                        model.get (iter, 5, out lift);
 
-                       if (lift.description == null)
-                               Hildon.gtk_window_set_progress_indicator (this, 1);
                        var window = new LiftDetailWindow (adac, lift);
                        window.show_all ();
-
-                       // TODO - this should be async
-                       if (lift.description == null) {
-                               adac.update_lift_details (lift);
-                               window.update_lift_details ();
-                               Hildon.gtk_window_set_progress_indicator (this, 0);
-                       }
                }
        }
 
        private void on_orientation_changed () {
-               if (BeifahrerProgram.orientation.portrait) {
-                       route_column.set_visible (false);
-               } else {
-                       route_column.set_visible (true);
-               }
+               route_column.set_visible (!BeifahrerProgram.orientation.portrait);
        }
 }