mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-05 15:17:37 +03:00
Refactor saving progress to dedicated function.
This commit is contained in:
parent
85a9204ad9
commit
de17b5da81
@ -191,31 +191,21 @@ void EpubReaderActivity::loop() {
|
|||||||
}
|
}
|
||||||
case EpubReaderMenuActivity::MenuAction::DELETE_CACHE: {
|
case EpubReaderMenuActivity::MenuAction::DELETE_CACHE: {
|
||||||
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
xSemaphoreTake(renderingMutex, portMAX_DELAY);
|
||||||
section.reset();
|
|
||||||
if (epub) {
|
if (epub) {
|
||||||
// 2. BACKUP: Read current progress
|
// 2. BACKUP: Read current progress
|
||||||
// We use the current variables that track our position
|
// We use the current variables that track our position
|
||||||
uint16_t backupSpine = currentSpineIndex;
|
uint16_t backupSpine = currentSpineIndex;
|
||||||
uint16_t backupPage = nextPageNumber;
|
uint16_t backupPage = section->currentPage;
|
||||||
|
|
||||||
// 3. WIPE: Clear the cache directory
|
section.reset();
|
||||||
epub->clearCache();
|
// 3. WIPE: Clear the cache directory
|
||||||
|
epub->clearCache();
|
||||||
|
|
||||||
// 4. RESTORE: Re-setup the directory and rewrite the progress file
|
// 4. RESTORE: Re-setup the directory and rewrite the progress file
|
||||||
epub->setupCacheDir();
|
epub->setupCacheDir();
|
||||||
|
|
||||||
FsFile f;
|
saveProgress(backupSpine, backupPage);
|
||||||
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
}
|
||||||
uint8_t data[4];
|
|
||||||
data[0] = backupSpine & 0xFF;
|
|
||||||
data[1] = (backupSpine >> 8) & 0xFF;
|
|
||||||
data[2] = backupPage & 0xFF;
|
|
||||||
data[3] = (backupPage >> 8) & 0xFF;
|
|
||||||
f.write(data, 4);
|
|
||||||
f.close();
|
|
||||||
Serial.println("[ERS] Progress restored after cache clear");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
exitActivity();
|
exitActivity();
|
||||||
updateRequired = true;
|
updateRequired = true;
|
||||||
xSemaphoreGive(renderingMutex);
|
xSemaphoreGive(renderingMutex);
|
||||||
@ -476,9 +466,13 @@ void EpubReaderActivity::renderScreen() {
|
|||||||
renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
|
renderContents(std::move(p), orientedMarginTop, orientedMarginRight, orientedMarginBottom, orientedMarginLeft);
|
||||||
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
|
Serial.printf("[%lu] [ERS] Rendered page in %dms\n", millis(), millis() - start);
|
||||||
}
|
}
|
||||||
|
saveProgress(currentSpineIndex, section->currentPage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EpubReaderActivity::saveProgress(int spineIndex, int page) {
|
||||||
FsFile f;
|
FsFile f;
|
||||||
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
if (SdMan.openFileForWrite("ERS", epub->getCachePath() + "/progress.bin", f)) {
|
||||||
|
<<<<<<< HEAD
|
||||||
uint8_t data[6];
|
uint8_t data[6];
|
||||||
data[0] = currentSpineIndex & 0xFF;
|
data[0] = currentSpineIndex & 0xFF;
|
||||||
data[1] = (currentSpineIndex >> 8) & 0xFF;
|
data[1] = (currentSpineIndex >> 8) & 0xFF;
|
||||||
@ -487,10 +481,20 @@ void EpubReaderActivity::renderScreen() {
|
|||||||
data[4] = section->pageCount & 0xFF;
|
data[4] = section->pageCount & 0xFF;
|
||||||
data[5] = (section->pageCount >> 8) & 0xFF;
|
data[5] = (section->pageCount >> 8) & 0xFF;
|
||||||
f.write(data, 6);
|
f.write(data, 6);
|
||||||
|
=======
|
||||||
|
uint8_t data[4];
|
||||||
|
data[0] = spineIndex & 0xFF;
|
||||||
|
data[1] = (spineIndex >> 8) & 0xFF;
|
||||||
|
data[2] = page & 0xFF;
|
||||||
|
data[3] = (page >> 8) & 0xFF;
|
||||||
|
f.write(data, 4);
|
||||||
|
>>>>>>> 95b7f80 (Refactor saving progress to dedicated function.)
|
||||||
f.close();
|
f.close();
|
||||||
|
Serial.printf("[ERS] Progress saved: Chapter %d, Page %d\n", spineIndex, page);
|
||||||
|
} else {
|
||||||
|
Serial.printf("[ERS] Could not save progress!\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int orientedMarginTop,
|
void EpubReaderActivity::renderContents(std::unique_ptr<Page> page, const int orientedMarginTop,
|
||||||
const int orientedMarginRight, const int orientedMarginBottom,
|
const int orientedMarginRight, const int orientedMarginBottom,
|
||||||
const int orientedMarginLeft) {
|
const int orientedMarginLeft) {
|
||||||
|
|||||||
@ -27,6 +27,7 @@ class EpubReaderActivity final : public ActivityWithSubactivity {
|
|||||||
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
|
void renderContents(std::unique_ptr<Page> page, int orientedMarginTop, int orientedMarginRight,
|
||||||
int orientedMarginBottom, int orientedMarginLeft);
|
int orientedMarginBottom, int orientedMarginLeft);
|
||||||
void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const;
|
void renderStatusBar(int orientedMarginRight, int orientedMarginBottom, int orientedMarginLeft) const;
|
||||||
|
void saveProgress(int spineIndex, int page);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EpubReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Epub> epub,
|
explicit EpubReaderActivity(GfxRenderer& renderer, MappedInputManager& mappedInput, std::unique_ptr<Epub> epub,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user