diff --git a/data/ui/main.blp b/data/ui/main.blp
index 679bd6e..46ae1e9 100644
--- a/data/ui/main.blp
+++ b/data/ui/main.blp
@@ -5,7 +5,7 @@ using Shumate 1.0;
Adw.ApplicationWindow mainWindow {
title: "Wince";
default-width: 700;
- default-height: 500;
+ default-height: 700;
Gtk.Box {
orientation: vertical;
@@ -48,97 +48,102 @@ Adw.ApplicationWindow mainWindow {
can-navigate-back: true;
visible: false;
- Gtk.ScrolledWindow scrollWindow {
+ Gtk.ScrolledWindow resultsScroll {
vexpand: true;
width-request: 300;
Gtk.ListBox searchResults {}
}
- Adw.Clamp detailsClamp {
- width-request: 300;
- maximum-size: 450;
- tightening-threshold: 400;
+ Gtk.ScrolledWindow detailsScroll {
+ vexpand: true;
- Gtk.Box detailsBox {
- orientation: vertical;
- visible: false;
- margin-start: 14;
- margin-end: 14;
+ Adw.Clamp {
+ width-request: 300;
+ maximum-size: 450;
+ margin-end: 12;
+ tightening-threshold: 400;
- Gtk.Button detailsBack {
+ Gtk.Box detailsBox {
+ orientation: vertical;
visible: false;
- hexpand: false;
- label: "Back to results";
- margin-bottom: 8;
- }
+ margin-start: 14;
- Gtk.Label detailsTitle {
- halign: start;
- styles ["title-1"]
- }
-
- Gtk.Box {
- orientation: horizontal;
- spacing: 12;
-
- Gtk.Label detailsIsOpen {
- halign: start;
+ Gtk.Button detailsBack {
+ visible: false;
+ hexpand: false;
+ label: "Back to results";
+ margin-bottom: 8;
}
- Gtk.Label detailsCurrentHours {
+ Gtk.Label detailsTitle {
halign: start;
+ styles ["title-1"]
}
- Gtk.Label detailsPricing {
- halign: start;
- }
- }
+ Gtk.Box {
+ orientation: horizontal;
+ spacing: 12;
- Gtk.ListBox {
- styles ["boxed-list"]
- selection-mode: none;
- margin-top: 8;
- hexpand: true;
-
- Gtk.ListBoxRow {
- Gtk.Label detailsAddress {
+ Gtk.Label detailsIsOpen {
halign: start;
- margin-start: 12;
- margin-top: 12;
- margin-bottom: 12;
}
- }
- Gtk.ListBoxRow {
- Gtk.Label detailsPhone {
+ Gtk.Label detailsCurrentHours {
halign: start;
- margin-start: 12;
- margin-top: 12;
- margin-bottom: 12;
}
- }
- Gtk.ListBoxRow {
- Gtk.LinkButton detailsUrl {
- label: "View on yelp";
+ Gtk.Label detailsPricing {
halign: start;
}
}
- }
- Gtk.Label {
- styles ["heading"]
- halign: start;
- label: "Hours";
- margin-top: 16;
- }
+ Gtk.ListBox {
+ styles ["boxed-list"]
+ selection-mode: none;
+ margin-top: 8;
+ hexpand: true;
- Gtk.ListBox detailsHoursBox {
- styles ["boxed-list"]
- selection-mode: none;
- margin-top: 8;
- hexpand: true;
+ Gtk.ListBoxRow {
+ Gtk.Label detailsAddress {
+ halign: start;
+ margin-start: 12;
+ margin-top: 12;
+ margin-bottom: 12;
+ }
+ }
+
+ Gtk.ListBoxRow {
+ Gtk.Label detailsPhone {
+ halign: start;
+ margin-start: 12;
+ margin-top: 12;
+ margin-bottom: 12;
+ }
+ }
+
+ Gtk.ListBoxRow {
+ Gtk.LinkButton detailsUrl {
+ label: "View on yelp";
+ halign: start;
+ }
+ }
+ }
+
+ Gtk.Label {
+ styles ["heading"]
+ halign: start;
+ label: "Hours";
+ margin-top: 16;
+ }
+
+ Gtk.ListBox detailsHoursBox {
+ styles ["boxed-list"]
+ selection-mode: none;
+ margin-top: 8;
+ margin-bottom: 8;
+ hexpand: true;
+ }
}
}
}
diff --git a/data/ui/templates.blp b/data/ui/templates/businessrow.blp
similarity index 99%
rename from data/ui/templates.blp
rename to data/ui/templates/businessrow.blp
index 429325c..4896c11 100644
--- a/data/ui/templates.blp
+++ b/data/ui/templates/businessrow.blp
@@ -24,4 +24,4 @@ template Wince-BusinessRow : Gtk.ListBoxRow {
}
}
}
-}
\ No newline at end of file
+}
diff --git a/data/ui/templates/hourrow.blp b/data/ui/templates/hourrow.blp
new file mode 100644
index 0000000..63853f4
--- /dev/null
+++ b/data/ui/templates/hourrow.blp
@@ -0,0 +1,22 @@
+using Gtk 4.0;
+using Adw 1;
+
+template Wince-HourRow : Gtk.ListBoxRow {
+ Gtk.Box {
+ orientation: horizontal;
+ margin-start: 12;
+ margin-end: 12;
+ margin-top: 12;
+ margin-bottom: 12;
+ hexpand: true;
+
+ Gtk.Label dayOfWeek {
+ halign: start;
+ }
+
+ Gtk.Label hours {
+ halign: end;
+ hexpand: true;
+ }
+ }
+}
diff --git a/data/wince.gresource.xml b/data/wince.gresource.xml
index 1bfd975..7a0cec0 100644
--- a/data/wince.gresource.xml
+++ b/data/wince.gresource.xml
@@ -2,6 +2,7 @@
ui/compiled/main.ui
- ui/compiled/templates.ui
+ ui/compiled/templates/businessrow.ui
+ ui/compiled/templates/hourrow.ui
diff --git a/src/bindings/geoclue/binding.yml b/src/bindings/geoclue/binding.yml
new file mode 100644
index 0000000..8bf86b8
--- /dev/null
+++ b/src/bindings/geoclue/binding.yml
@@ -0,0 +1,2 @@
+namespace: Geoclue
+version: "2.0"
diff --git a/src/bindings/libshumate/binding.yml b/src/bindings/libshumate/binding.yml
new file mode 100644
index 0000000..a572301
--- /dev/null
+++ b/src/bindings/libshumate/binding.yml
@@ -0,0 +1,2 @@
+namespace: Shumate
+version: "1.0"
diff --git a/src/modules/prerequisites.cr b/src/modules/prerequisites.cr
index a49cf30..992d59a 100644
--- a/src/modules/prerequisites.cr
+++ b/src/modules/prerequisites.cr
@@ -3,7 +3,7 @@ module Wince
VERSION = {{read_file("./shard.yml").split("version: ")[1].split("\n")[0]}}
{%
- `blueprint-compiler batch-compile ./data/ui/compiled ./data/ui/ ./data/ui/*.blp`
+ `blueprint-compiler batch-compile ./data/ui/compiled ./data/ui/ ./data/ui/templates/*.blp ./data/ui/*.blp`
%}
Gio.register_resource("data/wince.gresource.xml", "data")
end
diff --git a/src/modules/templates/businessrow.cr b/src/modules/templates/businessrow.cr
index bb9a47f..272c9f5 100644
--- a/src/modules/templates/businessrow.cr
+++ b/src/modules/templates/businessrow.cr
@@ -1,5 +1,6 @@
module Wince
- @[Gtk::UiTemplate(resource: "/wince/ui/compiled/templates.ui", children: %w(businessName businessRating businessDistance))]
+ @[Gtk::UiTemplate(resource: "/wince/ui/compiled/templates/businessrow.ui",
+ children: %w(businessName businessRating businessDistance))]
class BusinessRow < Gtk::ListBoxRow
include Gtk::WidgetTemplate
diff --git a/src/modules/templates/hourrow.cr b/src/modules/templates/hourrow.cr
new file mode 100644
index 0000000..2d96211
--- /dev/null
+++ b/src/modules/templates/hourrow.cr
@@ -0,0 +1,24 @@
+module Wince
+ @[Gtk::UiTemplate(resource: "/wince/ui/compiled/templates/hourrow.ui",
+ children: %w(dayOfWeek hours))]
+ class HourRow < Gtk::ListBoxRow
+ include Gtk::WidgetTemplate
+
+ @dayOfWeekLabel : Gtk::Label
+ @hoursLabel : Gtk::Label
+
+ def initialize(dayOfWeek : Time::DayOfWeek, hours : String)
+ super()
+
+ @dayOfWeekLabel = Gtk::Label.cast(template_child("dayOfWeek"))
+ @hoursLabel = Gtk::Label.cast(template_child("hours"))
+
+ @dayOfWeekLabel.text = dayOfWeek.to_s
+ if hours.empty?
+ @hoursLabel.text = "closed"
+ else
+ @hoursLabel.markup = hours
+ end
+ end
+ end
+end
\ No newline at end of file
diff --git a/src/modules/utils/utils.cr b/src/modules/utils/utils.cr
index eded762..20cd7ac 100644
--- a/src/modules/utils/utils.cr
+++ b/src/modules/utils/utils.cr
@@ -3,7 +3,7 @@ require "time" # yeah me too
module Wince::Utils
extend self
- def hours_for_day(hours_json : JSON::Any, day : Time::DayOfWeek)
+ def hours_for_day(hours_json : JSON::Any, day : Time::DayOfWeek, seperator : String)
open = hours_json[0]["open"].as_a
day_number = day_of_week_to_int(day)
@@ -12,7 +12,7 @@ module Wince::Utils
end_hour = hour["end"].as_s
"#{start_hour.insert(2, ":")}-#{end_hour.insert(2, ":")}"
- }.join(", ")
+ }.join(seperator)
end
def day_of_week_to_int(day : Time::DayOfWeek)
diff --git a/src/modules/views/main.cr b/src/modules/views/main.cr
index 070e13d..823c301 100644
--- a/src/modules/views/main.cr
+++ b/src/modules/views/main.cr
@@ -2,12 +2,14 @@ require "json"
require "time"
require "../templates/businessrow.cr"
+require "../templates/hourrow.cr"
require "../api/yelp.cr"
require "../utils/utils.cr"
module Wince
@@main_window_id = 0_u32
@@business_rows = [] of BusinessRow
+ @@hour_rows = [] of HourRow
@@business_ids = [] of String
def activate(app : Adw::Application)
@@ -21,7 +23,7 @@ module Wince
DETAILS_BACK.clicked_signal.connect do
BUSINESS_LIST.unselect_all
- LEAFLET.visible_child = SCROLL_VIEW
+ LEAFLET.visible_child = RESULTS_SCROLL
end
SEARCH_BUTTON.clicked_signal.connect do
@@ -61,6 +63,10 @@ module Wince
@@business_rows.each { |row| BUSINESS_LIST.remove(row) }
end
+ def clear_hour_rows
+ @@hour_rows.each { |row| DETAILS_HOURS_BOX.remove(row) }
+ end
+
def handle_search
search = SEARCH_ENTRY.buffer.text
location = LOCATION_ENTRY.buffer.text
@@ -116,11 +122,15 @@ module Wince
DETAILS_IS_OPEN.markup = "closed"
end
- DETAILS_CURRENT_HOURS.text = Utils.hours_for_day(response_json["hours"], Time.local.day_of_week)
+ DETAILS_CURRENT_HOURS.text = Utils.hours_for_day(response_json["hours"], Time.local.day_of_week, ", ")
DETAILS_PRICING.text = response_json["price"].as_s? || ""
DETAILS_ADDRESS.markup = Utils.format_address(response_json["location"]["display_address"])
DETAILS_PHONE.text = response_json["display_phone"].as_s? || "no phone number"
DETAILS_URL.uri = response_json["url"].as_s? || ""
+
+ clear_hour_rows()
+ @@hour_rows = format_hours(response_json["hours"])
+ @@hour_rows.each { |hour_row| DETAILS_HOURS_BOX.append(hour_row) }
# If we're in the small layout we want to show the back button
if LEAFLET.folded
@@ -130,9 +140,16 @@ module Wince
end
DETAILS_BOX.visible = true
- LEAFLET.visible_child = DETAILS_CLAMP
+ LEAFLET.visible_child = DETAILS_SCROLL
+ end
+
+ def format_hours(hours_json : JSON::Any)
+ Time::DayOfWeek.values.map do |day|
+ hours = Utils.hours_for_day(hours_json, day, "\n")
+ HourRow.new(day, hours)
+ end
end
APP.activate_signal.connect(->activate(Adw::Application))
exit(APP.run(ARGV))
-end
\ No newline at end of file
+end
diff --git a/src/wince.cr b/src/wince.cr
index 633fcad..1609931 100644
--- a/src/wince.cr
+++ b/src/wince.cr
@@ -12,7 +12,8 @@ module Wince
SEARCH_BUTTON = Gtk::Button.cast(B_UI["searchButton"])
BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"])
POWERD_BY_TEXT = Gtk::Label.cast(B_UI["poweredByText"])
- SCROLL_VIEW = Gtk::ScrolledWindow.cast(B_UI["scrollWindow"])
+ RESULTS_SCROLL = Gtk::ScrolledWindow.cast(B_UI["resultsScroll"])
+ DETAILS_SCROLL = Gtk::ScrolledWindow.cast(B_UI["detailsScroll"])
LEAFLET = Adw::Leaflet.cast(B_UI["leaflet"])
DETAILS_BOX = Gtk::Box.cast(B_UI["detailsBox"])
DETAILS_TITLE = Gtk::Label.cast(B_UI["detailsTitle"])
@@ -22,8 +23,8 @@ module Wince
DETAILS_ADDRESS = Gtk::Label.cast(B_UI["detailsAddress"])
DETAILS_PHONE = Gtk::Label.cast(B_UI["detailsPhone"])
DETAILS_URL = Gtk::LinkButton.cast(B_UI["detailsUrl"])
- DETAILS_CLAMP = Adw::Clamp.cast(B_UI["detailsClamp"])
DETAILS_BACK = Gtk::Button.cast(B_UI["detailsBack"])
+ DETAILS_HOURS_BOX = Gtk::ListBox.cast(B_UI["detailsHoursBox"])
APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None)
end