Open and style the day detail view and add it to the navigation stack
This commit is contained in:
parent
5cd0e822c6
commit
721ba09bb9
|
@ -2,32 +2,33 @@
|
|||
margin: 64px;
|
||||
}
|
||||
|
||||
.welcome-title {
|
||||
.welcome__title {
|
||||
font-size: larger;
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.welcome-content {
|
||||
.welcome__content {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.welcome-footer {
|
||||
.welcome__footer {
|
||||
}
|
||||
|
||||
.dialog-row {
|
||||
margin: 8px 0px 8px 0px;
|
||||
.historical {
|
||||
margin: 32px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.day-summary {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.daysummary {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.daysummary-date {
|
||||
.day-summary__date {
|
||||
font-size: larger;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.daysummary-weight {
|
||||
.day-summary__weight {
|
||||
margin: 4px;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,12 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
|
||||
use crate::{
|
||||
app::{AppInvocation, AppResponse},
|
||||
components::DayDetail,
|
||||
views::{HistoricalView, PlaceholderView, View, ViewName, WelcomeView},
|
||||
};
|
||||
use adw::prelude::*;
|
||||
use async_channel::Sender;
|
||||
use chrono::{NaiveDate, TimeZone};
|
||||
use chrono_tz::America::Anchorage;
|
||||
use chrono::{FixedOffset, NaiveDate, TimeZone};
|
||||
use dimensioned::si::{KG, M, S};
|
||||
use ft_core::{Steps, TimeDistance, TraxRecord, Weight};
|
||||
use gio::resources_lookup_data;
|
||||
|
@ -85,7 +85,6 @@ impl AppWindow {
|
|||
|
||||
let initial_view = View::Placeholder(PlaceholderView::new().upcast());
|
||||
|
||||
// layout.append(&header);
|
||||
layout.append(&initial_view.widget());
|
||||
|
||||
let nav_layout = gtk::Box::new(gtk::Orientation::Vertical, 0);
|
||||
|
@ -102,6 +101,10 @@ impl AppWindow {
|
|||
window.set_content(Some(&navigation));
|
||||
window.present();
|
||||
|
||||
let gesture = gtk::GestureClick::new();
|
||||
gesture.connect_released(|_, _, _, _| println!("detected gesture"));
|
||||
layout.add_controller(gesture);
|
||||
|
||||
let s = Self {
|
||||
app_tx,
|
||||
layout,
|
||||
|
@ -159,7 +162,56 @@ impl AppWindow {
|
|||
})
|
||||
.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(),
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ use glib::Object;
|
|||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DaySummaryPrivate {
|
||||
date: gtk::Label,
|
||||
weight: RefCell<Option<gtk::Label>>,
|
||||
|
@ -35,7 +34,7 @@ impl ObjectSubclass for DaySummaryPrivate {
|
|||
|
||||
fn new() -> Self {
|
||||
let date = gtk::Label::builder()
|
||||
.css_classes(["daysummary-date"])
|
||||
.css_classes(["day-summary__date"])
|
||||
.halign(gtk::Align::Start)
|
||||
.build();
|
||||
Self {
|
||||
|
@ -59,7 +58,7 @@ impl DaySummary {
|
|||
pub fn new() -> Self {
|
||||
let s: Self = Object::builder().build();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_css_classes(&["daysummary"]);
|
||||
s.set_css_classes(&["day-summary"]);
|
||||
|
||||
s.append(&s.imp().date);
|
||||
|
||||
|
@ -81,10 +80,74 @@ impl DaySummary {
|
|||
let label = gtk::Label::builder()
|
||||
.halign(gtk::Align::Start)
|
||||
.label(&format!("{}", weight_record.weight))
|
||||
.css_classes(["daysummary-weight"])
|
||||
.css_classes(["day-summary__weight"])
|
||||
.build();
|
||||
self.append(&label);
|
||||
*self.imp().weight.borrow_mut() = Some(label);
|
||||
}
|
||||
|
||||
self.append(
|
||||
>k::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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ You should have received a copy of the GNU General Public License along with Fit
|
|||
*/
|
||||
|
||||
mod day;
|
||||
pub use day::{DayDetail, DaySummary};
|
||||
|
||||
pub use day::DaySummary;
|
||||
use glib::Object;
|
||||
use gtk::{prelude::*, subclass::prelude::*};
|
||||
use std::{cell::RefCell, path::PathBuf, rc::Rc};
|
||||
|
|
|
@ -19,7 +19,7 @@ use emseries::{Recordable, Timestamp};
|
|||
use ft_core::TraxRecord;
|
||||
use glib::Object;
|
||||
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
|
||||
/// daily summaries, daily details, and will provide all functions the user may need for editing
|
||||
|
@ -46,9 +46,13 @@ glib::wrapper! {
|
|||
}
|
||||
|
||||
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();
|
||||
s.set_orientation(gtk::Orientation::Vertical);
|
||||
s.set_css_classes(&["historical"]);
|
||||
|
||||
let day_records: GroupedRecords = GroupedRecords::from(records);
|
||||
|
||||
|
@ -86,13 +90,16 @@ impl HistoricalView {
|
|||
.factory(&factory)
|
||||
.single_click_activate(true)
|
||||
.build();
|
||||
lst.connect_activate(|s, idx| {
|
||||
// This gets triggered whenever the user clicks on an item on the list. What we
|
||||
// actually want to do here is to open a modal dialog that shows all of the details of
|
||||
// the day and which allows the user to edit items within that dialog.
|
||||
let item = s.model().unwrap().item(idx).unwrap();
|
||||
let records = item.downcast_ref::<DayRecords>().unwrap();
|
||||
println!("list item activated: [{:?}] {:?}", idx, records.date());
|
||||
lst.connect_activate({
|
||||
let on_select_day = on_select_day.clone();
|
||||
move |s, idx| {
|
||||
// This gets triggered whenever the user clicks on an item on the list. What we
|
||||
// actually want to do here is to open a modal dialog that shows all of the details of
|
||||
// the day and which allows the user to edit items within that dialog.
|
||||
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);
|
||||
|
|
|
@ -55,11 +55,10 @@ impl WelcomeView {
|
|||
// branch.
|
||||
let title = gtk::Label::builder()
|
||||
.label("Welcome to FitnessTrax")
|
||||
.css_classes(["welcome-title"])
|
||||
.css_classes(["welcome__title"])
|
||||
.build();
|
||||
|
||||
let content = gtk::Box::builder()
|
||||
.css_classes(["model-content"])
|
||||
.orientation(gtk::Orientation::Vertical)
|
||||
.vexpand(true)
|
||||
.build();
|
||||
|
|
Loading…
Reference in New Issue