diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-13 13:56:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-13 13:56:27 +0300 |
| commit | 44b54fd8ccf4b9ae0a7e459b446fe183b534292b (patch) | |
| tree | aaca9d4e2f316fe7d9b3795f406d8d0d5c65113c /src | |
| parent | d236e785c73d713fba688f5dad2624a313a194dd (diff) | |
v2: add delete fast from history via long-press BACK in edit window
Adds history_delete_entry() in fastforge_core.c which removes an entry at
a given index by shifting the tail with memmove, zeroing the vacated slot,
recomputing streaks, and persisting. Wires a long-press BACK (700ms) handler
in the history edit window that calls it. Updates the hint text to inform
the user. Fixed hint text buffer from [40] to [48] to fit the full string.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/c/fastforge.c | 19 | ||||
| -rw-r--r-- | src/c/fastforge.h | 1 | ||||
| -rw-r--r-- | src/c/fastforge_core.c | 20 |
3 files changed, 38 insertions, 2 deletions
diff --git a/src/c/fastforge.c b/src/c/fastforge.c index 2dc7cf0..7f6c360 100644 --- a/src/c/fastforge.c +++ b/src/c/fastforge.c @@ -106,7 +106,8 @@ static char s_history_edit_start_text[32]; static char s_history_edit_end_text[32]; static char s_history_edit_duration_text[48]; static char s_history_edit_stage_text[24]; -static char s_history_edit_hint_text[40]; +/* 45 bytes needed: "UP/DN adj SEL field\nHOLD save BACK-hold del" + NUL */ +static char s_history_edit_hint_text[48]; static char s_running_edit_start_text[32]; static char s_running_edit_elapsed_text[32]; static char s_running_edit_goal_text[32]; @@ -815,7 +816,7 @@ static void refresh_history_edit_window_content(void) { s_history_edit_field == EDIT_FIELD_NOTE ? '>' : ' ', note_text); snprintf(s_history_edit_stage_text, sizeof(s_history_edit_stage_text), "Badge %s", badge_label ? badge_label : "--"); - snprintf(s_history_edit_hint_text, sizeof(s_history_edit_hint_text), "UP/DN adjust SEL field\nHOLD save"); + snprintf(s_history_edit_hint_text, sizeof(s_history_edit_hint_text), "UP/DN adj SEL field\nHOLD save BACK-hold del"); text_layer_set_text(s_history_edit_title_layer, s_history_edit_title_text); text_layer_set_text(s_history_edit_start_layer, s_history_edit_start_text); @@ -940,6 +941,19 @@ static void history_edit_back_click_handler(ClickRecognizerRef recognizer, void window_stack_remove(s_history_edit_window, true); } +/* Long-press BACK deletes the current entry and returns to the history list. */ +static void history_edit_delete_click_handler(ClickRecognizerRef recognizer, void *context) { + (void)recognizer; + (void)context; + if (!history_delete_entry(s_history_edit_index)) { + return; + } + s_history_edit_index = -1; + refresh_timer_view(); + refresh_stats_window_content(); + window_stack_remove(s_history_edit_window, true); +} + static void history_edit_click_config_provider(void *context) { (void)context; window_single_click_subscribe(BUTTON_ID_UP, history_edit_up_click_handler); @@ -947,6 +961,7 @@ static void history_edit_click_config_provider(void *context) { window_single_click_subscribe(BUTTON_ID_SELECT, history_edit_select_click_handler); window_single_click_subscribe(BUTTON_ID_BACK, history_edit_back_click_handler); window_long_click_subscribe(BUTTON_ID_SELECT, 500, history_edit_save_click_handler, NULL); + window_long_click_subscribe(BUTTON_ID_BACK, 700, history_edit_delete_click_handler, NULL); } static void running_fast_edit_apply_delta_minutes(int delta_minutes) { diff --git a/src/c/fastforge.h b/src/c/fastforge.h index 263a75b..de1959c 100644 --- a/src/c/fastforge.h +++ b/src/c/fastforge.h @@ -29,5 +29,6 @@ bool fast_is_running(void); bool fast_start(uint16_t preset_target_minutes); bool fast_stop(void); bool fast_cancel(void); +bool history_delete_entry(int index); #endif diff --git a/src/c/fastforge_core.c b/src/c/fastforge_core.c index cde224f..0b4455e 100644 --- a/src/c/fastforge_core.c +++ b/src/c/fastforge_core.c @@ -215,6 +215,26 @@ static void append_history_entry(const FastEntry *entry) { history[MAX_FASTS - 1] = *entry; } +/* Remove history[index], shift tail entries down, and persist the change. */ +bool history_delete_entry(int index) { + if (index < 0 || index >= history_count) { + return false; + } + + int entries_after = history_count - index - 1; + if (entries_after > 0) { + memmove(&history[index], &history[index + 1], sizeof(FastEntry) * (size_t)entries_after); + } + history_count--; + memset(&history[history_count], 0, sizeof(FastEntry)); + + recompute_streak_data_for_today(); + save_all_data(); + history_menu_reload(); + APP_LOG(APP_LOG_LEVEL_INFO, "Deleted history entry %d, history_count=%d", index, history_count); + return true; +} + static uint16_t resolve_target_minutes(uint16_t preset_target_minutes) { if (preset_target_minutes > 0) { return preset_target_minutes; |
