Skip to content

Commit

Permalink
Support showing elapsed/moving time
Browse files Browse the repository at this point in the history
  • Loading branch information
dantleech committed Nov 21, 2024
1 parent 82f8d06 commit cf051a5
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Features:
- `q`: **Quit**: quit!
- `k`: **Up** - select previous activity
- `j`: **Down** - select next activity
- `K`: **PageUp** - select previous activity
- `J`: **PageDown** - select next activity
- `K`: **PageUp** - select previous activity (`shift-K` to move 10 down)
- `J`: **PageDown** - select next activity (`shift-J` to move 10 up)
- `n`: **Next** - (in activity view) next split
- `p`: **Previous** - (in activity view) previous split
- `o`: **ToggleSortOrder** - switch between ascending and descending order
Expand Down
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ impl App<'_> {
filter_dialog: false,
sort_dialog: false,
rank_dialog: false,
use_moving_time: true,
},
activity_view_state: ActivityViewState {
pace_table_state: TableState::default(),
Expand Down
60 changes: 34 additions & 26 deletions src/component/activity_list/list.rs
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@

use tui::{
layout::Constraint,
style::{Color, Modifier, Style},
text::Span,
widgets::{Cell, Row, Table},
};


use crate::{
app::App,
store::activity::{Activities},
};


use crate::{app::App, store::activity::Activities};

pub fn activity_list_table<'a>(app: &App, activities: &'a Activities) -> Table<'a> {
let mut rows = vec![];
let time_header = match app.activity_list.use_moving_time {
true => "🕑 Moving",
false => "🕑 Elapsed",
};
let header_names = [
"Date",
"",
"Title",
"Dst",
"🕑 Time",
time_header,
"👣 Pace",
"󰓅 Speed",
"💓 Avg. Heart",
Expand All @@ -41,13 +38,21 @@ pub fn activity_list_table<'a>(app: &App, activities: &'a Activities) -> Table<'
Cell::from(activity.activity_type_icon()),
Cell::from(activity.title.clone()),
Cell::from(app.unit_formatter.distance(activity.distance)),
Cell::from(app.unit_formatter.stopwatch_time(activity.elapsed_time)),
Cell::from(
app.unit_formatter.pace(activity.moving_time, activity.distance),
),
Cell::from(
app.unit_formatter.speed(activity.meters_per_hour()),
),
Cell::from(app.unit_formatter.stopwatch_time(
match app.activity_list.use_moving_time {
true => activity.moving_time,
false => activity.elapsed_time,
},
)),
Cell::from(match app.activity_list.use_moving_time {
true => app
.unit_formatter
.pace(activity.moving_time, activity.distance),
false => app
.unit_formatter
.pace(activity.elapsed_time, activity.distance),
}),
Cell::from(app.unit_formatter.speed(activity.meters_per_hour())),
Cell::from(
activity
.average_heartrate
Expand All @@ -58,7 +63,9 @@ pub fn activity_list_table<'a>(app: &App, activities: &'a Activities) -> Table<'
]));
}

Table::new(rows, &[
Table::new(
rows,
&[
Constraint::Length(10),
Constraint::Length(2),
Constraint::Percentage(20),
Expand All @@ -69,13 +76,14 @@ pub fn activity_list_table<'a>(app: &App, activities: &'a Activities) -> Table<'
Constraint::Min(8),
Constraint::Min(8),
Constraint::Min(8),
])
.header(
Row::new(headers)
.height(1)
.bottom_margin(1)
.style(Style::default()),
)
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol("")
],
)
.header(
Row::new(headers)
.height(1)
.bottom_margin(1)
.style(Style::default()),
)
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
.highlight_symbol("")
}
6 changes: 6 additions & 0 deletions src/component/activity_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl View for ActivityList {
StravaEvent::Filter => toggle_filter(app),
StravaEvent::Sort => toggle_sort(app),
StravaEvent::Rank => toggle_rank(app),
StravaEvent::MovingElapsed => toggle_moving_elapsed(app),
StravaEvent::Enter => table_status_select_current(app),
StravaEvent::Refresh => app.send(InputEvent::Sync),
StravaEvent::IncreaseTolerance => {
Expand Down Expand Up @@ -123,6 +124,7 @@ impl View for ActivityList {
StravaEvent::Sort,
StravaEvent::Rank,
StravaEvent::Refresh,
StravaEvent::MovingElapsed,
];
events.push(StravaEvent::Anchor);
if app.activity_anchored.is_some() {
Expand Down Expand Up @@ -195,6 +197,7 @@ pub struct ActivityListState {
pub filter_dialog: bool,
pub sort_dialog: bool,
pub rank_dialog: bool,
pub use_moving_time: bool,
}

pub struct ActivityViewState {
Expand Down Expand Up @@ -225,3 +228,6 @@ fn toggle_sort(app: &mut App) {
fn toggle_rank(app: &mut App) {
app.activity_list.rank_dialog = !app.activity_list.rank_dialog;
}
fn toggle_moving_elapsed(app: &mut App) {
app.activity_list.use_moving_time = !app.activity_list.use_moving_time;
}
1 change: 1 addition & 0 deletions src/component/activity_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl View for ActivityView {
StravaEvent::Previous,
StravaEvent::Enter,
StravaEvent::ToggleLogView,
StravaEvent::MovingElapsed,
StravaEvent::Quit,
]
}
Expand Down
3 changes: 3 additions & 0 deletions src/event/keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ impl KeyMap {
map.insert(KeyCode::Char('J'), StravaEvent::PageDown);
map.insert(KeyCode::Char('n'), StravaEvent::Next);
map.insert(KeyCode::Char('p'), StravaEvent::Previous);
map.insert(KeyCode::Char('m'), StravaEvent::MovingElapsed);
map.insert(KeyCode::Char('o'), StravaEvent::ToggleSortOrder);
map.insert(KeyCode::Char('u'), StravaEvent::ToggleUnitSystem);
map.insert(KeyCode::Char('s'), StravaEvent::Sort);
Expand Down Expand Up @@ -82,6 +83,7 @@ pub enum StravaEvent {
Previous,
PageDown,
PageUp,
MovingElapsed,
}
impl StravaEvent {
pub fn describe(se: &StravaEvent) -> &'static str {
Expand All @@ -106,6 +108,7 @@ impl StravaEvent {
StravaEvent::Next => "next",
StravaEvent::Previous => "prev",
StravaEvent::ToggleLogView => "logs",
StravaEvent::MovingElapsed => "moving/elapsed",
}
}
}

0 comments on commit cf051a5

Please sign in to comment.