Compare commits

...

2 Commits

Author SHA1 Message Date
a768f4732e Added a back button for mobile 2022-12-21 20:17:04 -08:00
bf6dfd1919 Added clamp to make larger windows look better 2022-12-21 18:58:25 -08:00
4 changed files with 109 additions and 45 deletions

View File

@@ -1,5 +1,6 @@
using Gtk 4.0; using Gtk 4.0;
using Adw 1; using Adw 1;
using Shumate 1.0;
Adw.ApplicationWindow mainWindow { Adw.ApplicationWindow mainWindow {
title: "Wince"; title: "Wince";
@@ -27,6 +28,9 @@ Adw.ApplicationWindow mainWindow {
Gtk.Entry locationEntry { Gtk.Entry locationEntry {
placeholder-text: "Location"; placeholder-text: "Location";
} }
Gtk.Button geolocateButton {
icon-name: "find-location";
}
Gtk.Button searchButton { Gtk.Button searchButton {
icon-name: "edit-find"; icon-name: "edit-find";
} }
@@ -51,63 +55,90 @@ Adw.ApplicationWindow mainWindow {
Gtk.ListBox searchResults {} Gtk.ListBox searchResults {}
} }
Gtk.Box detailsBox { Adw.Clamp detailsClamp {
orientation: vertical; width-request: 300;
visible: false; maximum-size: 450;
margin-start: 14; tightening-threshold: 400;
margin-end: 14;
Gtk.Label detailsTitle { Gtk.Box detailsBox {
halign: start; orientation: vertical;
styles ["title-1"] visible: false;
} margin-start: 14;
margin-end: 14;
Gtk.Box { Gtk.Button detailsBack {
orientation: horizontal; visible: false;
spacing: 12; hexpand: false;
label: "Back to results";
Gtk.Label detailsIsOpen { margin-bottom: 8;
halign: start;
} }
Gtk.Label detailsCurrentHours { Gtk.Label detailsTitle {
halign: start; halign: start;
styles ["title-1"]
} }
Gtk.Label detailsPricing { Gtk.Box {
halign: start; orientation: horizontal;
} spacing: 12;
}
Gtk.ListBox { Gtk.Label detailsIsOpen {
styles ["boxed-list"]
selection-mode: none;
margin-top: 8;
hexpand: true;
Gtk.ListBoxRow {
Gtk.Label detailsAddress {
halign: start; halign: start;
margin-start: 12; }
margin-top: 12;
margin-bottom: 12; Gtk.Label detailsCurrentHours {
halign: start;
}
Gtk.Label detailsPricing {
halign: start;
}
}
Gtk.ListBox {
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.ListBoxRow { Gtk.Label {
Gtk.Label detailsPhone { styles ["heading"]
halign: start; halign: start;
margin-start: 12; label: "Hours";
margin-top: 12; margin-top: 16;
margin-bottom: 12;
}
} }
Gtk.ListBoxRow { Gtk.ListBox detailsHoursBox {
Gtk.LinkButton detailsUrl { styles ["boxed-list"]
label: "View on yelp"; selection-mode: none;
halign: start; margin-top: 8;
} hexpand: true;
} }
} }
} }

View File

@@ -0,0 +1,10 @@
module Wince::Location
extend self
client = Geoclue::Simple.new()
def find_location()
location = client.location
[location.latitude, location.longitude]
end
end

View File

@@ -19,10 +19,19 @@ module Wince
@@main_window_id = window.id @@main_window_id = window.id
DETAILS_BACK.clicked_signal.connect do
BUSINESS_LIST.unselect_all
LEAFLET.visible_child = SCROLL_VIEW
end
SEARCH_BUTTON.clicked_signal.connect do SEARCH_BUTTON.clicked_signal.connect do
handle_search handle_search
end end
GEOLOCATE_BUTTON.clicked_signal.connect do
handle_geolocate
end
BUSINESS_LIST.row_selected_signal.connect do BUSINESS_LIST.row_selected_signal.connect do
handle_business_select handle_business_select
end end
@@ -30,6 +39,10 @@ module Wince
window.present window.present
end end
def handle_geolocate
puts "no, not yet"
end
def yelp_response_to_business_ids(response : JSON::Any) def yelp_response_to_business_ids(response : JSON::Any)
response["businesses"].as_a.map { |b| b["id"].as_s } response["businesses"].as_a.map { |b| b["id"].as_s }
end end
@@ -106,11 +119,18 @@ module Wince
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_PRICING.text = response_json["price"].as_s? || ""
DETAILS_ADDRESS.markup = Utils.format_address(response_json["location"]["display_address"]) DETAILS_ADDRESS.markup = Utils.format_address(response_json["location"]["display_address"])
DETAILS_PHONE.text = response_json["display_phone"].as_s? || "" DETAILS_PHONE.text = response_json["display_phone"].as_s? || "no phone number"
DETAILS_URL.uri = response_json["url"].as_s? || "" DETAILS_URL.uri = response_json["url"].as_s? || ""
# If we're in the small layout we want to show the back button
if LEAFLET.folded
DETAILS_BACK.visible = true
else
DETAILS_BACK.visible = false
end
DETAILS_BOX.visible = true DETAILS_BOX.visible = true
LEAFLET.visible_child = DETAILS_BOX LEAFLET.visible_child = DETAILS_CLAMP
end end
APP.activate_signal.connect(->activate(Adw::Application)) APP.activate_signal.connect(->activate(Adw::Application))

View File

@@ -8,6 +8,7 @@ module Wince
SEARCH_ENTRY = Gtk::Entry.cast(B_UI["searchEntry"]) SEARCH_ENTRY = Gtk::Entry.cast(B_UI["searchEntry"])
LOCATION_ENTRY = Gtk::Entry.cast(B_UI["locationEntry"]) LOCATION_ENTRY = Gtk::Entry.cast(B_UI["locationEntry"])
GEOLOCATE_BUTTON = Gtk::Button.cast(B_UI["geolocateButton"])
SEARCH_BUTTON = Gtk::Button.cast(B_UI["searchButton"]) SEARCH_BUTTON = Gtk::Button.cast(B_UI["searchButton"])
BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"]) BUSINESS_LIST = Gtk::ListBox.cast(B_UI["searchResults"])
POWERD_BY_TEXT = Gtk::Label.cast(B_UI["poweredByText"]) POWERD_BY_TEXT = Gtk::Label.cast(B_UI["poweredByText"])
@@ -21,6 +22,8 @@ module Wince
DETAILS_ADDRESS = Gtk::Label.cast(B_UI["detailsAddress"]) DETAILS_ADDRESS = Gtk::Label.cast(B_UI["detailsAddress"])
DETAILS_PHONE = Gtk::Label.cast(B_UI["detailsPhone"]) DETAILS_PHONE = Gtk::Label.cast(B_UI["detailsPhone"])
DETAILS_URL = Gtk::LinkButton.cast(B_UI["detailsUrl"]) DETAILS_URL = Gtk::LinkButton.cast(B_UI["detailsUrl"])
DETAILS_CLAMP = Adw::Clamp.cast(B_UI["detailsClamp"])
DETAILS_BACK = Gtk::Button.cast(B_UI["detailsBack"])
APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None) APP = Adw::Application.new("dev.wince", Gio::ApplicationFlags::None)
end end