Open and style the day detail view and add it to the navigation stack

This commit is contained in:
Savanni D'Gerinel 2023-12-25 00:36:13 -05:00
parent 5cd0e822c6
commit 721ba09bb9
6 changed files with 153 additions and 31 deletions

View File

@ -2,32 +2,33 @@
margin: 64px; margin: 64px;
} }
.welcome-title { .welcome__title {
font-size: larger; font-size: larger;
padding: 8px; padding: 8px;
} }
.welcome-content { .welcome__content {
padding: 8px; padding: 8px;
} }
.welcome-footer { .welcome__footer {
} }
.dialog-row { .historical {
margin: 8px 0px 8px 0px; margin: 32px;
border-radius: 8px;
}
.day-summary {
padding: 8px; padding: 8px;
} }
.daysummary { .day-summary__date {
padding: 8px;
}
.daysummary-date {
font-size: larger; font-size: larger;
margin-bottom: 8px; margin-bottom: 8px;
} }
.daysummary-weight { .day-summary__weight {
margin: 4px; margin: 4px;
} }

View File

@ -16,12 +16,12 @@ You should have received a copy of the GNU General Public License along with Fit
use crate::{ use crate::{
app::{AppInvocation, AppResponse}, app::{AppInvocation, AppResponse},
components::DayDetail,
views::{HistoricalView, PlaceholderView, View, ViewName, WelcomeView}, views::{HistoricalView, PlaceholderView, View, ViewName, WelcomeView},
}; };
use adw::prelude::*; use adw::prelude::*;
use async_channel::Sender; use async_channel::Sender;
use chrono::{NaiveDate, TimeZone}; use chrono::{FixedOffset, NaiveDate, TimeZone};
use chrono_tz::America::Anchorage;
use dimensioned::si::{KG, M, S}; use dimensioned::si::{KG, M, S};
use ft_core::{Steps, TimeDistance, TraxRecord, Weight}; use ft_core::{Steps, TimeDistance, TraxRecord, Weight};
use gio::resources_lookup_data; use gio::resources_lookup_data;
@ -85,7 +85,6 @@ impl AppWindow {
let initial_view = View::Placeholder(PlaceholderView::new().upcast()); let initial_view = View::Placeholder(PlaceholderView::new().upcast());
// layout.append(&header);
layout.append(&initial_view.widget()); layout.append(&initial_view.widget());
let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0); let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
@ -102,6 +101,10 @@ impl AppWindow {
window.set_content(Some(&navigation)); window.set_content(Some(&navigation));
window.present(); window.present();
let gesture = gtk::GestureClick::new();
gesture.connect_released(|_, _, _, _| println!("detected gesture"));
layout.add_controller(gesture);
let s = Self { let s = Self {
app_tx, app_tx,
layout, layout,
@ -159,7 +162,56 @@ impl AppWindow {
}) })
.upcast(), .upcast(),
), ),
ViewName::Historical => View::Historical(HistoricalView::new(vec![]).upcast()), ViewName::Historical => View::Historical(
HistoricalView::new(
vec![
TraxRecord::Steps(Steps {
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
count: 1500,
}),
TraxRecord::Weight(Weight {
date: NaiveDate::from_ymd_opt(2023, 10, 13).unwrap(),
weight: 85. * KG,
}),
TraxRecord::Weight(Weight {
date: NaiveDate::from_ymd_opt(2023, 10, 14).unwrap(),
weight: 86. * KG,
}),
TraxRecord::BikeRide(TimeDistance {
datetime: FixedOffset::west_opt(10 * 60 * 60)
.unwrap()
.with_ymd_and_hms(2019, 6, 15, 12, 0, 0)
.unwrap(),
distance: Some(1000. * M),
duration: Some(150. * S),
comments: Some("Test Comments".to_owned()),
}),
TraxRecord::BikeRide(TimeDistance {
datetime: FixedOffset::west_opt(10 * 60 * 60)
.unwrap()
.with_ymd_and_hms(2019, 6, 15, 23, 0, 0)
.unwrap(),
distance: Some(1000. * M),
duration: Some(150. * S),
comments: Some("Test Comments".to_owned()),
}),
],
{
let s = self.clone();
Rc::new(move |date, records| {
let layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
layout.append(&adw::HeaderBar::new());
layout.append(&DayDetail::new(date, records));
let page = &adw::NavigationPage::builder()
.title(date.format("%Y-%m-%d").to_string())
.child(&layout)
.build();
s.navigation.push(page);
})
},
)
.upcast(),
),
} }
} }
} }

View File

@ -21,7 +21,6 @@ use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell; use std::cell::RefCell;
#[derive(Default)]
pub struct DaySummaryPrivate { pub struct DaySummaryPrivate {
date: gtk::Label, date: gtk::Label,
weight: RefCell<Option<gtk::Label>>, weight: RefCell<Option<gtk::Label>>,
@ -35,7 +34,7 @@ impl ObjectSubclass for DaySummaryPrivate {
fn new() -> Self { fn new() -> Self {
let date = gtk::Label::builder() let date = gtk::Label::builder()
.css_classes(["daysummary-date"]) .css_classes(["day-summary__date"])
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.build(); .build();
Self { Self {
@ -59,7 +58,7 @@ impl DaySummary {
pub fn new() -> Self { pub fn new() -> Self {
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical); s.set_orientation(gtk::Orientation::Vertical);
s.set_css_classes(&["daysummary"]); s.set_css_classes(&["day-summary"]);
s.append(&s.imp().date); s.append(&s.imp().date);
@ -81,10 +80,74 @@ impl DaySummary {
let label = gtk::Label::builder() let label = gtk::Label::builder()
.halign(gtk::Align::Start) .halign(gtk::Align::Start)
.label(&format!("{}", weight_record.weight)) .label(&format!("{}", weight_record.weight))
.css_classes(["daysummary-weight"]) .css_classes(["day-summary__weight"])
.build(); .build();
self.append(&label); self.append(&label);
*self.imp().weight.borrow_mut() = Some(label); *self.imp().weight.borrow_mut() = Some(label);
} }
self.append(
&gtk::Label::builder()
.halign(gtk::Align::Start)
.label("15km of biking in 60 minutes")
.build(),
);
}
}
pub struct DayDetailPrivate {
date: gtk::Label,
weight: RefCell<Option<gtk::Label>>,
}
#[glib::object_subclass]
impl ObjectSubclass for DayDetailPrivate {
const NAME: &'static str = "DayDetail";
type Type = DayDetail;
type ParentType = gtk::Box;
fn new() -> Self {
let date = gtk::Label::builder()
.css_classes(["daysummary-date"])
.halign(gtk::Align::Start)
.build();
Self {
date,
weight: RefCell::new(None),
}
}
}
impl ObjectImpl for DayDetailPrivate {}
impl WidgetImpl for DayDetailPrivate {}
impl BoxImpl for DayDetailPrivate {}
glib::wrapper! {
pub struct DayDetail(ObjectSubclass<DayDetailPrivate>) @extends gtk::Box, gtk::Widget, @implements gtk::Orientable;
}
impl DayDetail {
pub fn new(date: chrono::NaiveDate, records: Vec<TraxRecord>) -> Self {
let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical);
records.into_iter().for_each(|record| {
let record_view = match record {
TraxRecord::BikeRide(_) => gtk::Label::new(Some("BikeRide")),
TraxRecord::Row(_) => gtk::Label::new(Some("Row")),
TraxRecord::Run(_) => gtk::Label::new(Some("Run")),
TraxRecord::Steps(_) => gtk::Label::new(Some("Steps")),
TraxRecord::Swim(_) => gtk::Label::new(Some("Swim")),
TraxRecord::Walk(_) => gtk::Label::new(Some("Walk")),
TraxRecord::Weight(_) => gtk::Label::new(Some("Weight")),
};
record_view.add_css_class("day-detail");
record_view.set_halign(gtk::Align::Start);
s.append(&record_view);
});
s
} }
} }

View File

@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with Fit
*/ */
mod day; mod day;
pub use day::{DayDetail, DaySummary};
pub use day::DaySummary;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, path::PathBuf, rc::Rc}; use std::{cell::RefCell, path::PathBuf, rc::Rc};

View File

@ -19,7 +19,7 @@ use emseries::{Recordable, Timestamp};
use ft_core::TraxRecord; use ft_core::TraxRecord;
use glib::Object; use glib::Object;
use gtk::{prelude::*, subclass::prelude::*}; use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, collections::HashMap}; use std::{cell::RefCell, collections::HashMap, rc::Rc};
/// The historical view will show a window into the main database. It will show some version of /// The historical view will show a window into the main database. It will show some version of
/// daily summaries, daily details, and will provide all functions the user may need for editing /// daily summaries, daily details, and will provide all functions the user may need for editing
@ -46,9 +46,13 @@ glib::wrapper! {
} }
impl HistoricalView { impl HistoricalView {
pub fn new(records: Vec<TraxRecord>) -> Self { pub fn new<SelectFn>(records: Vec<TraxRecord>, on_select_day: Rc<SelectFn>) -> Self
where
SelectFn: Fn(chrono::NaiveDate, Vec<TraxRecord>) + 'static,
{
let s: Self = Object::builder().build(); let s: Self = Object::builder().build();
s.set_orientation(gtk::Orientation::Vertical); s.set_orientation(gtk::Orientation::Vertical);
s.set_css_classes(&["historical"]);
let day_records: GroupedRecords = GroupedRecords::from(records); let day_records: GroupedRecords = GroupedRecords::from(records);
@ -86,13 +90,16 @@ impl HistoricalView {
.factory(&factory) .factory(&factory)
.single_click_activate(true) .single_click_activate(true)
.build(); .build();
lst.connect_activate(|s, idx| { lst.connect_activate({
// This gets triggered whenever the user clicks on an item on the list. What we let on_select_day = on_select_day.clone();
// actually want to do here is to open a modal dialog that shows all of the details of move |s, idx| {
// the day and which allows the user to edit items within that dialog. // This gets triggered whenever the user clicks on an item on the list. What we
let item = s.model().unwrap().item(idx).unwrap(); // actually want to do here is to open a modal dialog that shows all of the details of
let records = item.downcast_ref::<DayRecords>().unwrap(); // the day and which allows the user to edit items within that dialog.
println!("list item activated: [{:?}] {:?}", idx, records.date()); let item = s.model().unwrap().item(idx).unwrap();
let records = item.downcast_ref::<DayRecords>().unwrap();
on_select_day(records.date(), records.records());
}
}); });
s.append(&lst); s.append(&lst);

View File

@ -55,11 +55,10 @@ impl WelcomeView {
// branch. // branch.
let title = gtk::Label::builder() let title = gtk::Label::builder()
.label("Welcome to FitnessTrax") .label("Welcome to FitnessTrax")
.css_classes(["welcome-title"]) .css_classes(["welcome__title"])
.build(); .build();
let content = gtk::Box::builder() let content = gtk::Box::builder()
.css_classes(["model-content"])
.orientation(gtk::Orientation::Vertical) .orientation(gtk::Orientation::Vertical)
.vexpand(true) .vexpand(true)
.build(); .build();