MCPcopy Create free account
hub / github.com/crosspoint-reader/crosspoint-reader / onEnter

Method onEnter

src/activities/reader/EpubReaderActivity.cpp:151–204  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

149} // namespace
150
151void EpubReaderActivity::onEnter() {
152 Activity::onEnter();
153
154 if (!epub) {
155 return;
156 }
157
158 // Configure screen orientation based on settings
159 // NOTE: This affects layout math and must be applied before any render calls.
160 ReaderUtils::applyOrientation(renderer, SETTINGS.orientation);
161
162 epub->setupCacheDir();
163
164 HalFile f;
165 if (Storage.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
166 uint8_t data[6];
167 int dataSize = f.read(data, 6);
168 if (dataSize == 4 || dataSize == 6) {
169 currentSpineIndex = data[0] + (data[1] << 8);
170 nextPageNumber = data[2] + (data[3] << 8);
171 if (nextPageNumber == UINT16_MAX) {
172 // UINT16_MAX is an in-memory navigation sentinel for "open previous
173 // chapter on its last page". It should never be treated as persisted
174 // resume state after sleep or reopen.
175 LOG_DBG("ERS", "Ignoring stale last-page sentinel from progress cache");
176 nextPageNumber = 0;
177 }
178 cachedSpineIndex = currentSpineIndex;
179 LOG_DBG("ERS", "Loaded cache: %d, %d", currentSpineIndex, nextPageNumber);
180 }
181 if (dataSize == 6) {
182 cachedChapterTotalPageCount = data[4] + (data[5] << 8);
183 }
184 }
185 // We may want a better condition to detect if we are opening for the first time.
186 // This will trigger if the book is re-opened at Chapter 0.
187 if (currentSpineIndex == 0) {
188 int textSpineIndex = epub->getSpineIndexForTextReference();
189 if (textSpineIndex != 0) {
190 currentSpineIndex = textSpineIndex;
191 LOG_DBG("ERS", "Opened for first time, navigating to text reference at index %d", textSpineIndex);
192 }
193 }
194
195 // Save current epub as last opened epub and add to recent books
196 APP_STATE.openEpubPath = epub->getPath();
197 APP_STATE.saveToFile();
198 RECENT_BOOKS.addBook(epub->getPath(), epub->getTitle(), epub->getAuthor(), epub->getThumbBmpPath());
199
200 loadCachedBookmarks();
201
202 // Trigger first update
203 requestUpdate();
204}
205
206void EpubReaderActivity::onExit() {
207 Activity::onExit();

Callers

nothing calls this directly

Calls 10

applyOrientationFunction · 0.85
openFileForReadMethod · 0.80
addBookMethod · 0.80
setupCacheDirMethod · 0.45
readMethod · 0.45
saveToFileMethod · 0.45
getTitleMethod · 0.45
getAuthorMethod · 0.45
getThumbBmpPathMethod · 0.45

Tested by

no test coverage detected