From 18c13002db86d896a3ac456504b0406b6b7345ee Mon Sep 17 00:00:00 2001 From: Jakub <106778416+MarekZegare4@users.noreply.github.com> Date: Sun, 10 May 2026 18:52:31 +0200 Subject: [PATCH] QuickMsgScreen: sort favourites first, mark with asterisk MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Favourite contacts (flags & 0x01 set by companion app) appear at the top of the contact picker, marked with '*'. Non-favourites appear below. The favourite bit is already synced by the existing protocol via CMD_ADD_UPDATE_CONTACT — no protocol changes needed. Co-Authored-By: Claude Sonnet 4.6 --- examples/companion_radio/ui-new/UITask.cpp | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/examples/companion_radio/ui-new/UITask.cpp b/examples/companion_radio/ui-new/UITask.cpp index 84622b3c..79ff490a 100644 --- a/examples/companion_radio/ui-new/UITask.cpp +++ b/examples/companion_radio/ui-new/UITask.cpp @@ -348,6 +348,7 @@ class QuickMsgScreen : public UIScreen { int _contact_sel, _contact_scroll; int _msg_sel, _msg_scroll; int _num_contacts; + uint8_t _sorted[MAX_CONTACTS]; // contact indices, favourites sorted first ContactInfo _sel_contact; static const int VISIBLE = 4; @@ -390,6 +391,18 @@ public: _contact_sel = _contact_scroll = 0; _msg_sel = _msg_scroll = 0; _num_contacts = the_mesh.getNumContacts(); + // sort: favourites (flags & 0x01) first, rest after + ContactInfo c; + int nfavs = 0; + for (int i = 0; i < _num_contacts; i++) + if (the_mesh.getContactByIdx(i, c) && (c.flags & 0x01)) nfavs++; + int fpos = 0, npos = nfavs; + for (int i = 0; i < _num_contacts; i++) { + if (the_mesh.getContactByIdx(i, c) && (c.flags & 0x01)) + _sorted[fpos++] = i; + else + _sorted[npos++] = i; + } } int render(DisplayDriver& display) override { @@ -407,15 +420,17 @@ public: } for (int i = 0; i < VISIBLE && (_contact_scroll+i) < _num_contacts; i++) { - int idx = _contact_scroll + i; - bool sel = (idx == _contact_sel); + int list_idx = _contact_scroll + i; + int mesh_idx = _sorted[list_idx]; + bool sel = (list_idx == _contact_sel); int y = START_Y + i * ITEM_H; display.setColor(sel ? DisplayDriver::YELLOW : DisplayDriver::LIGHT); - display.setCursor(0, y); - display.print(sel ? ">" : " "); ContactInfo c; - if (the_mesh.getContactByIdx(idx, c)) { + if (the_mesh.getContactByIdx(mesh_idx, c)) { + bool fav = (c.flags & 0x01); + display.setCursor(0, y); + display.print(sel ? ">" : (fav ? "*" : " ")); char filtered[sizeof(c.name)]; display.translateUTF8ToBlocks(filtered, c.name, sizeof(filtered)); display.drawTextEllipsized(8, y, display.width() - 24, filtered); @@ -470,7 +485,7 @@ public: return true; } if (c == KEY_ENTER && _num_contacts > 0) { - if (the_mesh.getContactByIdx(_contact_sel, _sel_contact)) { + if (the_mesh.getContactByIdx(_sorted[_contact_sel], _sel_contact)) { _phase = MSG_PICK; _msg_sel = _msg_scroll = 0; }