Simplify table updating when a flag is downloaded

This commit is contained in:
UnknownShadow200 2024-10-03 21:25:08 +10:00
parent 10f849cad1
commit 447d4060d5
3 changed files with 11 additions and 17 deletions

View file

@ -31,6 +31,7 @@ void LBackend_UpdateTitleFont(void);
void LBackend_DrawTitle(struct Context2D* ctx, const char* title);
void LBackend_DecodeFlag(struct Flag* flag, cc_uint8* data, cc_uint32 len);
void LBackend_TableFlagAdded(struct LTable* w);
/* Marks the entire launcher contents as needing to be redrawn */
void LBackend_Redraw(void);

View file

@ -598,19 +598,14 @@ static void LTable_UpdateCell(UITableView* table, UITableViewCell* cell, int row
}
// TODO only redraw flags
static void OnFlagsChanged(void) {
struct LScreen* s = Launcher_Active;
for (int i = 0; i < s->numWidgets; i++)
{
if (s->widgets[i]->type != LWIDGET_TABLE) continue;
UITableView* tbl = (__bridge UITableView*)s->widgets[i]->meta;
// trying to update cell.imageView.image doesn't seem to work,
// so pointlessly reload entire table data instead
NSIndexPath* selected = [tbl indexPathForSelectedRow];
[tbl reloadData];
[tbl selectRowAtIndexPath:selected animated:NO scrollPosition:UITableViewScrollPositionNone];
}
void LBackend_TableFlagAdded(struct LTable* w) {
UITableView* tbl = (__bridge UITableView*)w->meta;
// trying to update cell.imageView.image doesn't seem to work,
// so pointlessly reload entire table data instead
NSIndexPath* selected = [tbl indexPathForSelectedRow];
[tbl reloadData];
[tbl selectRowAtIndexPath:selected animated:NO scrollPosition:UITableViewScrollPositionNone];
}
/*########################################################################################################################*
@ -621,8 +616,7 @@ void LBackend_DecodeFlag(struct Flag* flag, cc_uint8* data, cc_uint32 len) {
UIImage* img = [UIImage imageWithData:ns_data];
if (!img) return;
flag->meta = CFBridgingRetain(img);
OnFlagsChanged();
flag->meta = CFBridgingRetain(img);
}
static void LBackend_LayoutDimensions(struct LWidget* w, CGRect* r) {

View file

@ -1347,9 +1347,8 @@ static void ServersScreen_Tick(struct LScreen* s_) {
flagsCount = FetchFlagsTask.count;
LWebTask_Tick(&FetchFlagsTask.Base, NULL);
if (flagsCount != FetchFlagsTask.count) {
LBackend_NeedsRedraw(&s->table);
LBackend_TableFlagAdded(&s->table);
}
if (!FetchServersTask.Base.working) return;