** Function: loopFirmware ** Where you choose which Firmware to see more data **********************************************************************/
| 1229 | ** Where you choose which Firmware to see more data |
| 1230 | **********************************************************************/ |
| 1231 | void loopFirmware() { |
| 1232 | int _page = current_page; |
| 1233 | String order_by = "downloads"; |
| 1234 | String query = ""; |
| 1235 | bool star = false; |
| 1236 | bool refine = false; |
| 1237 | int index = 0; |
| 1238 | |
| 1239 | RESTART: |
| 1240 | currentIndex = -1; |
| 1241 | if (_page != current_page || refine) { |
| 1242 | GetJsonFromLauncherHub(current_page, order_by, star, query); |
| 1243 | index = 1; |
| 1244 | } |
| 1245 | options = {}; |
| 1246 | int items = doc["page_size"].as<int>(); |
| 1247 | int page = doc["page"].as<int>(); |
| 1248 | if (total_firmware < (page * items)) { |
| 1249 | if (page == 1) items = total_firmware; |
| 1250 | else items = total_firmware - items * (page - 1); |
| 1251 | } |
| 1252 | options.push_back({"[Refine Search]", [&]() { refine = true; }, ALCOLOR}); |
| 1253 | |
| 1254 | if (current_page > 1) { |
| 1255 | // Volta uma página |
| 1256 | options.push_back({"[Previous Page]", [=]() { current_page -= 1; }, ALCOLOR}); |
| 1257 | } |
| 1258 | for (int i = 0; i < items; i++) { |
| 1259 | bool stared = doc["items"][i]["star"].as<bool>(); |
| 1260 | String txt = |
| 1261 | doc["items"][i]["name"].as<String>() + " (" + doc["items"][i]["author"].as<String>() + ")"; |
| 1262 | options.push_back({txt, [=]() { currentIndex = i; }, stared ? FGCOLOR - 0x1111 : FGCOLOR}); |
| 1263 | }; |
| 1264 | if (total_firmware > doc["page_size"].as<int>() * current_page) { |
| 1265 | // Avança uma pagina |
| 1266 | options.push_back({"[Next Page]", [=]() { current_page += 1; }, ALCOLOR}); |
| 1267 | } |
| 1268 | options.push_back({"[Main Menu]", [=]() { returnToMenu = true; }, ALCOLOR}); |
| 1269 | |
| 1270 | tft->fillScreen(BGCOLOR); |
| 1271 | index = loopOptions(options, false, FGCOLOR, BGCOLOR, false, index); |
| 1272 | if (currentIndex >= 0) loopVersions(doc["items"][currentIndex]["fid"].as<String>()); |
| 1273 | if (refine) { |
| 1274 | refine = false; |
| 1275 | std::vector<Option> opt = { |
| 1276 | {"Order by downloads", |
| 1277 | [&]() { |
| 1278 | order_by = "downloads"; |
| 1279 | refine = true; |
| 1280 | }, order_by == "downloads" ? FGCOLOR : NO_COLOR}, |
| 1281 | {"Order by name", |
| 1282 | [&]() { |
| 1283 | order_by = "name"; |
| 1284 | refine = true; |
| 1285 | }, order_by == "name" ? FGCOLOR : NO_COLOR}, |
| 1286 | {"Order by latest", |
| 1287 | [&]() { |
| 1288 | order_by = "date"; |
no test coverage detected