Add on-watch search alpha listing

This commit is contained in:
RandyTheSilly committed 2026-10-10 20:10:42 -04:00
1 parent ba4edccb15
commit 03bf39227c
3 files changed
+64 -34

No files matched your search

+43 -27
View File
@@ -10,20 +10,8 @@ typedef enum {
NAV_SCOPE_ALBUM_TRACKS = 4,
} NavScope;
// layer-age
static Window *s_main_window;
static CustomStatusBarLayer *s_status_bar_layer;
static Layer *s_divider_layer;
static MenuLayer *s_menu_layer;
// globals
static bool s_pkjs_ready = false;
static NavScope s_current_menu_scope = NAV_SCOPE_MAIN;
// resources
static GFont s_font_chicago;
// constants
#define MAX_MENU_ITEMS 2048
#define BAR_HEIGHT 20
#ifdef PBL_RECT
#define MARGIN_X 4
@@ -39,22 +27,57 @@ static GFont s_font_chicago;
static const GRect s_menu_grect = GRect(MARGIN_X, BAR_HEIGHT + MARGIN_Y, PBL_DISPLAY_WIDTH - (MARGIN_X * 2), PBL_DISPLAY_HEIGHT - (MARGIN_Y * 2));
static const char *s_main_menu_options[4] = {"Shuffle Songs", "Shuffle Artists", "> All Artists", "> Search Artists"};
// layer-age
static Window *s_main_window;
static CustomStatusBarLayer *s_status_bar_layer;
static Layer *s_divider_layer;
static MenuLayer *s_menu_layer;
// globals
static bool s_pkjs_ready = false;
static NavScope s_current_menu_scope = NAV_SCOPE_MAIN;
static const char *s_current_menu_vanity[MAX_MENU_ITEMS];
// static uint16_t s_current_menu_seq_ids[MAX_MENU_ITEMS];
static uint16_t s_menu_items_count = 0;
// resources
static GFont s_font_chicago;
////////////////////// PKJS //////////////////////
static void outbox_failed_handler(DictionaryIterator *iter, AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_ERROR, "outbox failed: %d", (int)reason);
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) {
Tuple *t_ready = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (t_ready) {
s_pkjs_ready = true;
return;
}
// handle incoming menu list items
for (uint16_t i = 0; i < MAX_MENU_ITEMS; i++) {
Tuple *t_vanity = dict_find(iter, MESSAGE_KEY_IN_VANITY_LIST + i);
if (t_vanity) {
s_current_menu_vanity[i] = t_vanity->value->cstring;
} else {
s_menu_items_count = i;
break;
}
}
s_current_menu_scope = NAV_SCOPE_SEARCH;
menu_layer_reload_data(s_menu_layer);
menu_layer_set_selected_index(s_menu_layer, MenuIndex(0, 0), MenuRowAlignTop, false);
return;
}
// request a new menu scope from the PKJS side
static void to_pkjs_scope_change(NavScope scope) {
if (!s_pkjs_ready) {
return;
}
// send scope to return data for (PKJS side should track last scope and only send new data if the new scope differs)
DictionaryIterator *out;
AppMessageResult result = app_message_outbox_begin(&out);
if (result != APP_MSG_OK) {
@@ -72,12 +95,8 @@ static uint16_t menu_get_num_rows(MenuLayer *menu_layer, uint16_t section_index,
switch (s_current_menu_scope) {
case NAV_SCOPE_MAIN:
return 4;
case NAV_SCOPE_SEARCH:
case NAV_SCOPE_ARTISTS:
case NAV_SCOPE_ALBUMS:
case NAV_SCOPE_ALBUM_TRACKS:
default:
return 99;
return s_menu_items_count;
}
}
@@ -86,12 +105,8 @@ static void menu_draw_row(GContext *ctx, const Layer *cell_layer, MenuIndex *cel
case NAV_SCOPE_MAIN:
custom_menu_cell_title_draw(ctx, cell_layer, s_main_menu_options[cell_index->row], NULL, s_font_chicago, MARGIN_X);
break;
case NAV_SCOPE_SEARCH:
case NAV_SCOPE_ARTISTS:
case NAV_SCOPE_ALBUMS:
case NAV_SCOPE_ALBUM_TRACKS:
default:
return;
custom_menu_cell_title_draw(ctx, cell_layer, s_current_menu_vanity[cell_index->row], NULL, s_font_chicago, MARGIN_X);
}
}
@@ -163,7 +178,8 @@ static void main_window_unload() {
static void init() {
// initialize pkjs
app_message_register_inbox_received(inbox_received_handler);
app_message_open(4096, 1024); // TODO adjust sizes
app_message_register_outbox_failed(outbox_failed_handler);
app_message_open(app_message_inbox_size_maximum(), 512);
// load font
s_font_chicago = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CHICAGO_16));