diff --git a/src/c/jellyPod.c b/src/c/jellyPod.c index 09370b4..df39b93 100644 --- a/src/c/jellyPod.c +++ b/src/c/jellyPod.c @@ -14,9 +14,8 @@ typedef enum { // TODO write to disk to restore exit point on re-open typedef struct { bool using_search; - char subscope_search[255]; // TODO tighten and only store first character - char subscope_artist[255]; - uint16_t scroll_row[NAV_SCOPE_ALBUM_TRACKS + 1]; // last selected row per scope + char last_subscope[NAV_SCOPE_ALBUM_TRACKS + 1][255]; // subscope each scope was last entered with + uint16_t scroll_row[NAV_SCOPE_ALBUM_TRACKS + 1]; // last selected row per scope } History; // constants @@ -57,18 +56,14 @@ static uint16_t s_menu_items_count = 0; // resources static GFont s_font_chicago; -static void append_to_subscope_history() { +static const char *get_current_scope_subscope() { switch (s_current_menu_scope) { 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: - snprintf(s_nav_history.subscope_artist, sizeof(s_nav_history.subscope_artist), "%s", s_pending_subscope); - break; + case NAV_SCOPE_ALBUM_TRACKS: + return s_pending_subscope; 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) { 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) { - 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; menu_layer_reload_data(s_menu_layer); 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; } + const char *subscope = subscope_index ? s_current_menu_vanity[*subscope_index] : ""; + snprintf(s_pending_subscope, sizeof(s_pending_subscope), "%s", subscope); if (subscope_index) { - snprintf(s_pending_subscope, sizeof(s_pending_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_cstring(out, MESSAGE_KEY_OUT_MENU_NAV_SUBSCOPE, subscope); } dict_write_uint8(out, MESSAGE_KEY_BIDIR_MENU_NAV_SCOPE, scope); @@ -176,12 +174,12 @@ static void to_pkjs_move_back() { break; case NAV_SCOPE_ALBUMS: 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); break; 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); break; default: