mirror of
https://github.com/ratspeak/ratdeck.git
synced 2026-10-10 19:57:15 +00:00
ui: fix stale peer age display
This commit is contained in:
@@ -50,14 +50,8 @@ std::string compactAge(unsigned long ageMs) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string contactMetaFor(const DiscoveredNode& node, unsigned long ageMs) {
|
||||
std::string age = compactAge(ageMs);
|
||||
if (node.hops > 0 && node.hops < 128) {
|
||||
char buf[24];
|
||||
snprintf(buf, sizeof(buf), "%uH %s", (unsigned)node.hops, age.c_str());
|
||||
return buf;
|
||||
}
|
||||
return age;
|
||||
std::string contactMetaFor(unsigned long ageMs) {
|
||||
return compactAge(ageMs);
|
||||
}
|
||||
|
||||
lv_obj_t* createEmptyState(lv_obj_t* parent) {
|
||||
@@ -132,15 +126,17 @@ void LvContactsScreen::onEnter() {
|
||||
|
||||
void LvContactsScreen::refreshUI() {
|
||||
if (!_am) return;
|
||||
unsigned long now = millis();
|
||||
int contacts = 0;
|
||||
for (const auto& n : _am->nodes()) { if (n.saved) contacts++; }
|
||||
if (contacts != _lastContactCount) {
|
||||
if (contacts != _lastContactCount || now - _lastRebuild >= REBUILD_INTERVAL_MS) {
|
||||
rebuildList();
|
||||
}
|
||||
}
|
||||
|
||||
void LvContactsScreen::rebuildList() {
|
||||
if (!_am || !_list) return;
|
||||
_lastRebuild = millis();
|
||||
_contactIndices.clear();
|
||||
|
||||
lv_obj_clean(_list);
|
||||
@@ -224,7 +220,7 @@ void LvContactsScreen::rebuildList() {
|
||||
lv_obj_set_style_text_align(metaLbl, LV_TEXT_ALIGN_RIGHT, 0);
|
||||
lv_label_set_long_mode(metaLbl, LV_LABEL_LONG_CLIP);
|
||||
lv_obj_set_width(metaLbl, 64);
|
||||
std::string meta = contactMetaFor(node, age);
|
||||
std::string meta = contactMetaFor(age);
|
||||
lv_label_set_text(metaLbl, meta.c_str());
|
||||
lv_obj_set_pos(metaLbl, Theme::CONTENT_W - 72, 5);
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ private:
|
||||
bool _focusActive = false;
|
||||
int _deleteIdx = -1;
|
||||
int _lastContactCount = -1;
|
||||
unsigned long _lastRebuild = 0;
|
||||
static constexpr unsigned long REBUILD_INTERVAL_MS = 30000;
|
||||
std::vector<int> _contactIndices;
|
||||
std::vector<std::vector<uint8_t>> _avatarBuffers;
|
||||
|
||||
|
||||
@@ -48,19 +48,8 @@ std::string compactAge(unsigned long ageMs) {
|
||||
return buf;
|
||||
}
|
||||
|
||||
std::string hopTextFor(const DiscoveredNode& node) {
|
||||
if (node.hops > 0 && node.hops < 128) {
|
||||
char buf[12];
|
||||
snprintf(buf, sizeof(buf), "%uhop", (unsigned)node.hops);
|
||||
return buf;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string peerMetaFor(const DiscoveredNode& node, unsigned long ageMs, bool devMode) {
|
||||
std::string meta = hopTextFor(node);
|
||||
if (!meta.empty()) meta += " ";
|
||||
meta += compactAge(ageMs);
|
||||
std::string meta = compactAge(ageMs);
|
||||
if (devMode && node.rssi != 0) {
|
||||
char buf[14];
|
||||
snprintf(buf, sizeof(buf), " %ddB", node.rssi);
|
||||
@@ -242,7 +231,8 @@ void LvNodesScreen::refreshUI() {
|
||||
for (const auto& n : _am->nodes()) { if (n.saved) contacts++; }
|
||||
int countDelta = abs(_am->nodeCount() - _lastNodeCount);
|
||||
int contactDelta = abs(contacts - _lastContactCount);
|
||||
if (countDelta > 0 || contactDelta > 0) {
|
||||
bool ageRefresh = now - _lastRebuild >= AGE_REBUILD_INTERVAL_MS;
|
||||
if (countDelta > 0 || contactDelta > 0 || ageRefresh) {
|
||||
_lastRebuild = now;
|
||||
rebuildList();
|
||||
}
|
||||
@@ -250,6 +240,7 @@ void LvNodesScreen::refreshUI() {
|
||||
|
||||
void LvNodesScreen::rebuildList() {
|
||||
if (!_am || !_list) return;
|
||||
_lastRebuild = millis();
|
||||
// Preserve scroll position across rebuilds
|
||||
lv_coord_t scrollY = lv_obj_get_scroll_y(_list);
|
||||
lv_obj_clean(_list);
|
||||
|
||||
@@ -71,6 +71,7 @@ private:
|
||||
|
||||
unsigned long _lastRebuild = 0;
|
||||
static constexpr unsigned long REBUILD_INTERVAL_MS = 5000;
|
||||
static constexpr unsigned long AGE_REBUILD_INTERVAL_MS = 30000;
|
||||
|
||||
lv_obj_t* _list = nullptr;
|
||||
lv_obj_t* _emptyState = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user