nice
This commit is contained in:
@@ -58,6 +58,47 @@ void EpubReaderActivity::onEnter() {
|
||||
|
||||
epub->setupCacheDir();
|
||||
|
||||
// Check if cover generation is needed and do it NOW (blocking)
|
||||
const bool needsThumb = !SdMan.exists(epub->getThumbBmpPath().c_str());
|
||||
const bool needsMicroThumb = !SdMan.exists(epub->getMicroThumbBmpPath().c_str());
|
||||
const bool needsCoverFit = !SdMan.exists(epub->getCoverBmpPath(false).c_str());
|
||||
const bool needsCoverCrop = !SdMan.exists(epub->getCoverBmpPath(true).c_str());
|
||||
|
||||
if (needsThumb || needsMicroThumb || needsCoverFit || needsCoverCrop) {
|
||||
// Show "Preparing book... [X%]" popup, updating every 3 seconds
|
||||
constexpr int boxMargin = 20;
|
||||
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, "Preparing book... [100%]");
|
||||
const int boxWidth = textWidth + boxMargin * 2;
|
||||
const int boxHeight = renderer.getLineHeight(UI_12_FONT_ID) + boxMargin * 2;
|
||||
const int boxX = (renderer.getScreenWidth() - boxWidth) / 2;
|
||||
constexpr int boxY = 50;
|
||||
|
||||
unsigned long lastUpdate = 0;
|
||||
|
||||
// Draw initial popup
|
||||
renderer.clearScreen();
|
||||
renderer.fillRect(boxX, boxY, boxWidth, boxHeight, false);
|
||||
renderer.drawRect(boxX + 5, boxY + 5, boxWidth - 10, boxHeight - 10);
|
||||
renderer.drawText(UI_12_FONT_ID, boxX + boxMargin, boxY + boxMargin, "Preparing book... [0%]");
|
||||
renderer.displayBuffer(EInkDisplay::FAST_REFRESH);
|
||||
|
||||
// Generate covers with progress callback
|
||||
epub->generateAllCovers([&](int percent) {
|
||||
const unsigned long now = millis();
|
||||
if ((now - lastUpdate) >= 3000) {
|
||||
lastUpdate = now;
|
||||
|
||||
renderer.fillRect(boxX, boxY, boxWidth, boxHeight, false);
|
||||
renderer.drawRect(boxX + 5, boxY + 5, boxWidth - 10, boxHeight - 10);
|
||||
|
||||
char progressStr[32];
|
||||
snprintf(progressStr, sizeof(progressStr), "Preparing book... [%d%%]", percent);
|
||||
renderer.drawText(UI_12_FONT_ID, boxX + boxMargin, boxY + boxMargin, progressStr);
|
||||
renderer.displayBuffer(EInkDisplay::FAST_REFRESH);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
FsFile f;
|
||||
if (SdMan.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[4];
|
||||
@@ -486,6 +527,7 @@ void EpubReaderActivity::renderScreen() {
|
||||
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
|
||||
}
|
||||
|
||||
// Save progress
|
||||
FsFile f;
|
||||
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||
uint8_t data[4];
|
||||
|
||||
Reference in New Issue
Block a user