Split template files. Added full hours support
This commit is contained in:
135
data/ui/main.blp
135
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,4 @@ template Wince-BusinessRow : Gtk.ListBoxRow {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
data/ui/templates/hourrow.blp
Normal file
22
data/ui/templates/hourrow.blp
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<gresources>
|
||||
<gresource prefix="/wince">
|
||||
<file compressed="true" preprocess="xml-stripblanks">ui/compiled/main.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">ui/compiled/templates.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">ui/compiled/templates/businessrow.ui</file>
|
||||
<file compressed="true" preprocess="xml-stripblanks">ui/compiled/templates/hourrow.ui</file>
|
||||
</gresource>
|
||||
</gresources>
|
||||
|
||||
2
src/bindings/geoclue/binding.yml
Normal file
2
src/bindings/geoclue/binding.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
namespace: Geoclue
|
||||
version: "2.0"
|
||||
2
src/bindings/libshumate/binding.yml
Normal file
2
src/bindings/libshumate/binding.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
namespace: Shumate
|
||||
version: "1.0"
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
24
src/modules/templates/hourrow.cr
Normal file
24
src/modules/templates/hourrow.cr
Normal file
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = "<span foreground=\"red\">closed</span>"
|
||||
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
|
||||
end
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user