Show a summary of the day's biking stats when there is one

This commit is contained in:
Savanni D'Gerinel 2024-01-21 10:50:18 -05:00
parent 2fb8728856
commit ecdd38ebbc
4 changed files with 42 additions and 13 deletions

View File

@ -17,10 +17,13 @@ You should have received a copy of the GNU General Public License along with Fit
// use chrono::NaiveDate;
// use ft_core::TraxRecord;
use crate::{
components::{steps_editor, weight_field, ActionGroup, Steps, WeightLabel},
components::{
steps_editor, time_distance_summary, weight_field, ActionGroup, Steps, WeightLabel,
},
types::WeightFormatter,
view_models::DayDetailViewModel,
};
use ft_core::TimeDistanceActivity;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell;
@ -97,8 +100,12 @@ impl DaySummary {
label.set_label(&format!("{} steps", s));
}
row.append(&label);
self.append(&row);
let biking_summary = view_model.time_distance_summary(TimeDistanceActivity::BikeRide);
if let Some(label) = time_distance_summary(biking_summary.0, biking_summary.1) {
self.append(&label);
}
}
}

View File

@ -30,7 +30,7 @@ mod text_entry;
pub use text_entry::{weight_field, TextEntry};
mod time_distance;
pub use time_distance::TimeDistanceView;
pub use time_distance::{time_distance_summary, TimeDistanceView};
mod weight;
pub use weight::WeightLabel;

View File

@ -17,11 +17,33 @@ You should have received a copy of the GNU General Public License along with Fit
// use crate::components::{EditView, ParseError, TextEntry};
// use chrono::{Local, NaiveDate};
// use dimensioned::si;
use dimensioned::si;
use ft_core::TimeDistance;
use glib::Object;
use gtk::{prelude::*, subclass::prelude::*};
use std::cell::RefCell;
pub fn time_distance_summary(
distance: si::Meter<f64>,
duration: si::Second<f64>,
) -> Option<gtk::Label> {
let text = match (distance > si::M, duration > si::S) {
(true, true) => Some(format!(
"{} kilometers of biking in {} minutes",
distance.value_unsafe / 1000.,
duration.value_unsafe / 60.
)),
(true, false) => Some(format!(
"{} kilometers of biking",
distance.value_unsafe / 1000.
)),
(false, true) => Some(format!("{} seconds of biking", duration.value_unsafe / 60.)),
(false, false) => None,
};
text.map(|text| gtk::Label::new(Some(&text)))
}
#[derive(Default)]
pub struct TimeDistanceViewPrivate {
#[allow(unused)]

View File

@ -36,16 +36,6 @@ enum RecordState<T: Clone + Recordable> {
}
impl<T: Clone + emseries::Recordable> RecordState<T> {
#[allow(unused)]
fn id(&self) -> Option<&RecordId> {
match self {
RecordState::Original(ref r) => Some(&r.id),
RecordState::New(ref r) => None,
RecordState::Updated(ref r) => Some(&r.id),
RecordState::Deleted(ref r) => Some(&r.id),
}
}
fn exists(&self) -> bool {
match self {
RecordState::Original(_) => true,
@ -55,6 +45,16 @@ impl<T: Clone + emseries::Recordable> RecordState<T> {
}
}
#[allow(unused)]
fn data(&self) -> Option<&Record<T>> {
match self {
RecordState::Original(ref r) => Some(r),
RecordState::New(ref r) => None,
RecordState::Updated(ref r) => Some(r),
RecordState::Deleted(ref r) => Some(r),
}
}
fn set_value(&mut self, value: T) {
*self = match self {
RecordState::Original(r) => RecordState::Updated(Record {