Render and be able to edit bike rides (and sorta other time distance workouts) #169

Merged
savanni merged 13 commits from fitnesstrax/time-distance-workout into main 2024-02-09 00:05:26 +00:00
3 changed files with 26 additions and 21 deletions
Showing only changes of commit 9fc9d2b758 - Show all commits

View File

@ -20,7 +20,7 @@ use crate::{
components::{ components::{
steps_editor, time_distance_summary, weight_field, ActionGroup, Steps, WeightLabel, steps_editor, time_distance_summary, weight_field, ActionGroup, Steps, WeightLabel,
}, },
types::WeightFormatter, types::{DistanceFormatter, DurationFormatter, WeightFormatter},
view_models::DayDetailViewModel, view_models::DayDetailViewModel,
}; };
use emseries::{Record, RecordId}; use emseries::{Record, RecordId};
@ -106,7 +106,10 @@ impl DaySummary {
self.append(&row); self.append(&row);
let biking_summary = view_model.time_distance_summary(TimeDistanceActivity::BikeRide); let biking_summary = view_model.time_distance_summary(TimeDistanceActivity::BikeRide);
if let Some(label) = time_distance_summary(biking_summary.0, biking_summary.1) { if let Some(label) = time_distance_summary(
DistanceFormatter::from(biking_summary.0),
DurationFormatter::from(biking_summary.1),
) {
self.append(&label); self.append(&label);
} }
} }
@ -397,7 +400,7 @@ where
biking_button.connect_clicked({ biking_button.connect_clicked({
let view_model = view_model.clone(); let view_model = view_model.clone();
move |_| { move |_| {
let workout = view_model.new_time_distance(TimeDistanceActivity::Walking); let workout = view_model.new_time_distance(TimeDistanceActivity::BikeRide);
add_row(workout.map(TraxRecord::TimeDistance)); add_row(workout.map(TraxRecord::TimeDistance));
} }
}); });

View File

@ -19,7 +19,7 @@ You should have received a copy of the GNU General Public License along with Fit
// use dimensioned::si; // use dimensioned::si;
use crate::{ use crate::{
components::{distance_field, duration_field, time_field}, components::{distance_field, duration_field, time_field},
types::{DistanceFormatter, DurationFormatter, TimeFormatter}, types::{DistanceFormatter, DurationFormatter, FormatOption, TimeFormatter},
}; };
use dimensioned::si; use dimensioned::si;
use ft_core::{TimeDistance, TimeDistanceActivity}; use ft_core::{TimeDistance, TimeDistanceActivity};
@ -28,20 +28,17 @@ use gtk::{prelude::*, subclass::prelude::*};
use std::{cell::RefCell, rc::Rc}; use std::{cell::RefCell, rc::Rc};
pub fn time_distance_summary( pub fn time_distance_summary(
distance: si::Meter<f64>, distance: DistanceFormatter,
duration: si::Second<f64>, duration: DurationFormatter,
) -> Option<gtk::Label> { ) -> Option<gtk::Label> {
let text = match (distance > si::M, duration > si::S) { let text = match (*distance > si::M, *duration > si::S) {
(true, true) => Some(format!( (true, true) => Some(format!(
"{} kilometers of biking in {} minutes", "{} of biking in {}",
distance.value_unsafe / 1000., distance.format(FormatOption::Full),
duration.value_unsafe / 60. duration.format(FormatOption::Full)
)), )),
(true, false) => Some(format!( (true, false) => Some(format!("{} of biking", distance.format(FormatOption::Full))),
"{} kilometers of biking", (false, true) => Some(format!("{} of biking", duration.format(FormatOption::Full))),
distance.value_unsafe / 1000.
)),
(false, true) => Some(format!("{} seconds of biking", duration.value_unsafe / 60.)),
(false, false) => None, (false, false) => None,
}; };
@ -75,7 +72,7 @@ pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
.label( .label(
record record
.distance .distance
.map(|dist| format!("{}", dist)) .map(|dist| DistanceFormatter::from(dist).format(FormatOption::Abbreviated))
.unwrap_or("".to_owned()), .unwrap_or("".to_owned()),
) )
.build(), .build(),
@ -87,7 +84,9 @@ pub fn time_distance_detail(record: ft_core::TimeDistance) -> gtk::Box {
.label( .label(
record record
.duration .duration
.map(|duration| format!("{}", duration)) .map(|duration| {
DurationFormatter::from(duration).format(FormatOption::Abbreviated)
})
.unwrap_or("".to_owned()), .unwrap_or("".to_owned()),
) )
.build(), .build(),

View File

@ -14,10 +14,7 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>. You should have received a copy of the GNU General Public License along with FitnessTrax. If not, see <https://www.gnu.org/licenses/>.
*/ */
#[allow(unused_imports)] use crate::app::{ReadError, RecordProvider};
use crate::app::{ReadError, RecordProvider, WriteError};
#[allow(unused_imports)]
use chrono::NaiveDate;
use dimensioned::si; use dimensioned::si;
use emseries::{Record, RecordId, Recordable}; use emseries::{Record, RecordId, Recordable};
use ft_core::{TimeDistance, TimeDistanceActivity, TraxRecord}; use ft_core::{TimeDistance, TimeDistanceActivity, TraxRecord};
@ -27,6 +24,12 @@ use std::{
sync::{Arc, RwLock}, sync::{Arc, RwLock},
}; };
// These are actually a used imports. Clippy isn't detecting their use, probably because of complexity around the async trait macros.
#[allow(unused_imports)]
use crate::app::WriteError;
#[allow(unused_imports)]
use chrono::NaiveDate;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
enum RecordState<T: Clone + Recordable> { enum RecordState<T: Clone + Recordable> {
Original(Record<T>), Original(Record<T>),