feat(hardcover): auto-connect to WiFi before syncing
This commit is contained in:
@@ -2,36 +2,66 @@
|
||||
|
||||
#include <GfxRenderer.h>
|
||||
#include <I18n.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#include "HardcoverPlugin.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "activities/network/WifiSelectionActivity.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
void HardcoverSyncActivity::onEnter() {
|
||||
Activity::onEnter();
|
||||
state = SYNCING;
|
||||
result = HardcoverPlugin::SyncResult::OK;
|
||||
requestUpdate();
|
||||
result = HardcoverPlugin::SyncResult::OK;
|
||||
startWifiThenSync();
|
||||
}
|
||||
|
||||
void HardcoverSyncActivity::onExit() { Activity::onExit(); }
|
||||
|
||||
void HardcoverSyncActivity::startWifiThenSync() {
|
||||
if (WiFi.status() == WL_CONNECTED) {
|
||||
state = SYNCING;
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
|
||||
state = CONNECTING;
|
||||
requestUpdate();
|
||||
|
||||
startActivityForResult(
|
||||
std::make_unique<WifiSelectionActivity>(renderer, mappedInput),
|
||||
[this](const ActivityResult&) {
|
||||
if (WiFi.status() != WL_CONNECTED) {
|
||||
result = HardcoverPlugin::SyncResult::NO_WIFI;
|
||||
state = DONE;
|
||||
requestUpdate();
|
||||
return;
|
||||
}
|
||||
state = SYNCING;
|
||||
requestUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
void HardcoverSyncActivity::render(RenderLock&&) {
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const auto& metrics = UITheme::getInstance().getMetrics();
|
||||
const auto pageWidth = renderer.getScreenWidth();
|
||||
const auto pageHeight = renderer.getScreenHeight();
|
||||
|
||||
renderer.clearScreen();
|
||||
GUI.drawHeader(renderer, Rect{0, metrics.topPadding, pageWidth, metrics.headerHeight}, "Hardcover");
|
||||
|
||||
if (state == CONNECTING) {
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, "Connecting to WiFi...");
|
||||
renderer.displayBuffer();
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == SYNCING) {
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2, "Syncing...");
|
||||
renderer.displayBuffer();
|
||||
return;
|
||||
}
|
||||
|
||||
// DONE state - show result
|
||||
const char* line1 = nullptr;
|
||||
const char* line2 = nullptr;
|
||||
|
||||
@@ -60,9 +90,8 @@ void HardcoverSyncActivity::render(RenderLock&&) {
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 - (line2 ? 15 : 0), line1, true,
|
||||
result == HardcoverPlugin::SyncResult::OK ? EpdFontFamily::BOLD
|
||||
: EpdFontFamily::REGULAR);
|
||||
if (line2) {
|
||||
if (line2)
|
||||
renderer.drawCenteredText(UI_10_FONT_ID, pageHeight / 2 + 15, line2);
|
||||
}
|
||||
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), "", "", "");
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
@@ -86,9 +115,8 @@ void HardcoverSyncActivity::loop() {
|
||||
}
|
||||
|
||||
if (state == DONE) {
|
||||
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
||||
if (mappedInput.wasPressed(MappedInputManager::Button::Back))
|
||||
finish();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user