Track row index when moving deeper, as well

This commit is contained in:
RandyTheSilly committed 2026-10-11 03:39:13 -04:00
1 parent e2136a65e1
commit c95c75b11d
1 file changed
+18 -20
+18 -20
View File
@@ -14,9 +14,8 @@ typedef enum {
// TODO write to disk to restore exit point on re-open // TODO write to disk to restore exit point on re-open
typedef struct { typedef struct {
bool using_search; bool using_search;
char subscope_search[255]; // TODO tighten and only store first character char last_subscope[NAV_SCOPE_ALBUM_TRACKS + 1][255]; // subscope each scope was last entered with
char subscope_artist[255]; uint16_t scroll_row[NAV_SCOPE_ALBUM_TRACKS + 1]; // last selected row per scope
uint16_t scroll_row[NAV_SCOPE_ALBUM_TRACKS + 1]; // last selected row per scope
} History; } History;
// constants // constants
@@ -57,18 +56,14 @@ static uint16_t s_menu_items_count = 0;
// resources // resources
static GFont s_font_chicago; static GFont s_font_chicago;
static void append_to_subscope_history() { static const char *get_current_scope_subscope() {
switch (s_current_menu_scope) { switch (s_current_menu_scope) {
case NAV_SCOPE_ARTISTS: case NAV_SCOPE_ARTISTS:
if (s_nav_history.using_search) {
snprintf(s_nav_history.subscope_search, sizeof(s_nav_history.subscope_search), "%s", s_pending_subscope);
}
break;
case NAV_SCOPE_ALBUMS: case NAV_SCOPE_ALBUMS:
snprintf(s_nav_history.subscope_artist, sizeof(s_nav_history.subscope_artist), "%s", s_pending_subscope); case NAV_SCOPE_ALBUM_TRACKS:
break; return s_pending_subscope;
default: default:
return; return "";
} }
} }
@@ -113,12 +108,15 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
} else if (!moving_deeper && s_current_menu_scope == NAV_SCOPE_SEARCH) { } else if (!moving_deeper && s_current_menu_scope == NAV_SCOPE_SEARCH) {
s_nav_history.using_search = false; // reset when returning to search menu s_nav_history.using_search = false; // reset when returning to search menu
} }
// restore the row the user left off on (unless moving deeper into a different subscope)
uint16_t scroll_row = s_nav_history.scroll_row[s_current_menu_scope];
if (moving_deeper) { if (moving_deeper) {
append_to_subscope_history(); const char *subscope = get_current_scope_subscope();
if (strcmp(subscope, s_nav_history.last_subscope[s_current_menu_scope]) != 0) {
scroll_row = 0;
snprintf(s_nav_history.last_subscope[s_current_menu_scope], sizeof(s_nav_history.last_subscope[s_current_menu_scope]), "%s", subscope);
}
} }
// when moving deeper start at the top, otherwise restore the row the user left off on
uint16_t scroll_row = moving_deeper ? 0 : s_nav_history.scroll_row[s_current_menu_scope];
s_nav_history.scroll_row[s_current_menu_scope] = scroll_row; s_nav_history.scroll_row[s_current_menu_scope] = scroll_row;
menu_layer_reload_data(s_menu_layer); menu_layer_reload_data(s_menu_layer);
menu_layer_set_selected_index(s_menu_layer, MenuIndex(0, scroll_row), MenuRowAlignTop, false); menu_layer_set_selected_index(s_menu_layer, MenuIndex(0, scroll_row), MenuRowAlignTop, false);
@@ -137,10 +135,10 @@ static void to_pkjs_move_deeper(NavScope scope, uint16_t *subscope_index) {
return; return;
} }
const char *subscope = subscope_index ? s_current_menu_vanity[*subscope_index] : "";
snprintf(s_pending_subscope, sizeof(s_pending_subscope), "%s", subscope);
if (subscope_index) { if (subscope_index) {
snprintf(s_pending_subscope, sizeof(s_pending_subscope), dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, subscope);
"%s", s_current_menu_vanity[*subscope_index]);
dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, s_current_menu_vanity[*subscope_index]);
} }
dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, scope); dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, scope);
@@ -176,12 +174,12 @@ static void to_pkjs_move_back() {
break; break;
case NAV_SCOPE_ALBUMS: case NAV_SCOPE_ALBUMS:
if (s_nav_history.using_search) { if (s_nav_history.using_search) {
dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, s_nav_history.subscope_search); dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, s_nav_history.last_subscope[NAV_SCOPE_ARTISTS]);
} }
dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, NAV_SCOPE_ARTISTS); dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, NAV_SCOPE_ARTISTS);
break; break;
case NAV_SCOPE_ALBUM_TRACKS: case NAV_SCOPE_ALBUM_TRACKS:
dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, s_nav_history.subscope_artist); dict_write_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, s_nav_history.last_subscope[NAV_SCOPE_ALBUMS]);
dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, NAV_SCOPE_ALBUMS); dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, NAV_SCOPE_ALBUMS);
break; break;
default: default: