Brings ~55 mod-exclusive files to the upstream-based mod/master-resync branch: Activities (migrated to new ActivityManager pattern): - Clock/Time: SetTimeActivity, SetTimezoneOffsetActivity, NtpSyncActivity - Dictionary: DictionaryDefinitionActivity, DictionarySuggestionsActivity, DictionaryWordSelectActivity, LookedUpWordsActivity - Bookmark: EpubReaderBookmarkSelectionActivity - Book management: BookManageMenuActivity, EndOfBookMenuActivity - OPDS: OpdsServerListActivity, OpdsSettingsActivity - Utility: DirectoryPickerActivity, NumericStepperActivity Utilities (unchanged): - BookManager, BookSettings, BookmarkStore, BootNtpSync - Dictionary, LookupHistory, TimeSync, OpdsServerStore Libraries: PlaceholderCover, TableData, ChapterXPathIndexer Scripts: inject_mod_version, generate_book_icon, preview_placeholder_cover Docs: KOReader sync XPath mapping Migration changes: - ActivityWithSubactivity -> Activity base class - Callback constructors -> finish()/setResult() pattern - enterNewActivity() -> startActivityForResult() - Activity::RenderLock&& -> RenderLock&& These files won't compile yet - they reference mod settings and I18n strings that will be added in subsequent phases. Made-with: Cursor
102 lines
2.8 KiB
C++
102 lines
2.8 KiB
C++
#include "SetTimezoneOffsetActivity.h"
|
|
|
|
#include <GfxRenderer.h>
|
|
#include <I18n.h>
|
|
|
|
#include <cstdio>
|
|
#include <cstdlib>
|
|
|
|
#include "CrossPointSettings.h"
|
|
#include "MappedInputManager.h"
|
|
#include "components/UITheme.h"
|
|
#include "fontIds.h"
|
|
|
|
void SetTimezoneOffsetActivity::onEnter() {
|
|
Activity::onEnter();
|
|
offsetHours = SETTINGS.timezoneOffsetHours;
|
|
requestUpdate();
|
|
}
|
|
|
|
void SetTimezoneOffsetActivity::onExit() { Activity::onExit(); }
|
|
|
|
void SetTimezoneOffsetActivity::loop() {
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Back)) {
|
|
finish();
|
|
return;
|
|
}
|
|
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Confirm)) {
|
|
SETTINGS.timezoneOffsetHours = offsetHours;
|
|
SETTINGS.saveToFile();
|
|
// Apply timezone immediately
|
|
setenv("TZ", SETTINGS.getTimezonePosixStr(), 1);
|
|
tzset();
|
|
finish();
|
|
return;
|
|
}
|
|
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Up)) {
|
|
if (offsetHours < 14) {
|
|
offsetHours++;
|
|
requestUpdate();
|
|
}
|
|
return;
|
|
}
|
|
|
|
if (mappedInput.wasPressed(MappedInputManager::Button::Down)) {
|
|
if (offsetHours > -12) {
|
|
offsetHours--;
|
|
requestUpdate();
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
|
|
void SetTimezoneOffsetActivity::render(RenderLock&&) {
|
|
renderer.clearScreen();
|
|
|
|
const auto pageWidth = renderer.getScreenWidth();
|
|
const int lineHeight12 = renderer.getLineHeight(UI_12_FONT_ID);
|
|
|
|
// Title
|
|
renderer.drawCenteredText(UI_12_FONT_ID, 20, tr(STR_SET_UTC_OFFSET), true, EpdFontFamily::BOLD);
|
|
|
|
// Format the offset string
|
|
char offsetStr[16];
|
|
if (offsetHours >= 0) {
|
|
snprintf(offsetStr, sizeof(offsetStr), "UTC+%d", offsetHours);
|
|
} else {
|
|
snprintf(offsetStr, sizeof(offsetStr), "UTC%d", offsetHours);
|
|
}
|
|
|
|
const int textWidth = renderer.getTextWidth(UI_12_FONT_ID, offsetStr);
|
|
const int startX = (pageWidth - textWidth) / 2;
|
|
const int valueY = 80;
|
|
|
|
// Draw selection highlight
|
|
constexpr int highlightPad = 10;
|
|
renderer.fillRoundedRect(startX - highlightPad, valueY - 4, textWidth + highlightPad * 2, lineHeight12 + 8, 6,
|
|
Color::LightGray);
|
|
|
|
// Draw the offset text
|
|
renderer.drawText(UI_12_FONT_ID, startX, valueY, offsetStr, true);
|
|
|
|
// Draw up/down arrows
|
|
const int arrowX = pageWidth / 2;
|
|
const int arrowUpY = valueY - 20;
|
|
const int arrowDownY = valueY + lineHeight12 + 12;
|
|
constexpr int arrowSize = 6;
|
|
for (int row = 0; row < arrowSize; row++) {
|
|
renderer.drawLine(arrowX - row, arrowUpY + row, arrowX + row, arrowUpY + row);
|
|
}
|
|
for (int row = 0; row < arrowSize; row++) {
|
|
renderer.drawLine(arrowX - row, arrowDownY + arrowSize - 1 - row, arrowX + row, arrowDownY + arrowSize - 1 - row);
|
|
}
|
|
|
|
// Button hints
|
|
const auto labels = mappedInput.mapLabels(tr(STR_BACK), tr(STR_SAVE), tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
|
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
|
|
|
renderer.displayBuffer();
|
|
}
|