Strart with System settings
This commit is contained in:
@@ -475,3 +475,6 @@ STR_WEATHER_SUN_INFO: "Sun"
|
|||||||
STR_READER_TOOLS: "Tools"
|
STR_READER_TOOLS: "Tools"
|
||||||
STR_READER_NAVIGATION: "Navigation"
|
STR_READER_NAVIGATION: "Navigation"
|
||||||
STR_READER_APPEARANCE: "Appearance"
|
STR_READER_APPEARANCE: "Appearance"
|
||||||
|
STR_MENU_SYS_SYSTEM: "System"
|
||||||
|
STR_MENU_SYS_NETWORK: "Network"
|
||||||
|
STR_MENU_SYS_TOOLS: "Tools"
|
||||||
@@ -67,8 +67,8 @@ std::vector<EpubReaderMenuActivity::MenuItem> EpubReaderMenuActivity::buildMenuI
|
|||||||
|
|
||||||
void EpubReaderMenuActivity::onEnter() {
|
void EpubReaderMenuActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
const auto pred = UITheme::makeSelectablePredicate(
|
const auto pred = UITheme::makeSelectablePredicate(static_cast<int>(menuItems.size()),
|
||||||
static_cast<int>(menuItems.size()), [this](int i) { return menuItems[i].getTitle(); });
|
[this](int i) { return menuItems[i].getTitle(); });
|
||||||
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
||||||
if (!pred(selectedIndex)) {
|
if (!pred(selectedIndex)) {
|
||||||
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
||||||
@@ -187,9 +187,7 @@ void EpubReaderMenuActivity::render(RenderLock&&) {
|
|||||||
|
|
||||||
GUI.drawList(
|
GUI.drawList(
|
||||||
renderer, Rect{contentRect.x, startY, contentRect.width, listHeight}, static_cast<int>(menuItems.size()),
|
renderer, Rect{contentRect.x, startY, contentRect.width, listHeight}, static_cast<int>(menuItems.size()),
|
||||||
selectedIndex,
|
selectedIndex, [this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr,
|
||||||
[this](int index) { return menuItems[index].getTitle(); },
|
|
||||||
nullptr, nullptr,
|
|
||||||
[this](int index) {
|
[this](int index) {
|
||||||
const auto& item = menuItems[index];
|
const auto& item = menuItems[index];
|
||||||
switch (item.action) {
|
switch (item.action) {
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ std::vector<ClockSettingsActivity::MenuItem> ClockSettingsActivity::buildMenuIte
|
|||||||
|
|
||||||
void ClockSettingsActivity::onEnter() {
|
void ClockSettingsActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
const auto pred = UITheme::makeSelectablePredicate(
|
const auto pred = UITheme::makeSelectablePredicate(static_cast<int>(menuItems.size()),
|
||||||
static_cast<int>(menuItems.size()), [this](int i) { return menuItems[i].getTitle(); });
|
[this](int i) { return menuItems[i].getTitle(); });
|
||||||
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
buttonNavigator.setSelectablePredicate(pred, static_cast<int>(menuItems.size()));
|
||||||
if (!pred(selectedIndex)) {
|
if (!pred(selectedIndex)) {
|
||||||
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
selectedIndex = buttonNavigator.nextIndex(selectedIndex);
|
||||||
@@ -126,8 +126,7 @@ void ClockSettingsActivity::render(RenderLock&&) {
|
|||||||
|
|
||||||
GUI.drawList(
|
GUI.drawList(
|
||||||
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuItems.size()), selectedIndex,
|
renderer, Rect{0, contentTop, pageWidth, contentHeight}, static_cast<int>(menuItems.size()), selectedIndex,
|
||||||
[this](int index) { return menuItems[index].getTitle(); },
|
[this](int index) { return menuItems[index].getTitle(); }, nullptr, nullptr,
|
||||||
nullptr, nullptr,
|
|
||||||
[this](int index) {
|
[this](int index) {
|
||||||
const auto action = menuItems[index].action;
|
const auto action = menuItems[index].action;
|
||||||
switch (action) {
|
switch (action) {
|
||||||
|
|||||||
@@ -26,6 +26,15 @@
|
|||||||
const StrId SettingsActivity::categoryNames[categoryCount] = {StrId::STR_CAT_DISPLAY, StrId::STR_CAT_READER,
|
const StrId SettingsActivity::categoryNames[categoryCount] = {StrId::STR_CAT_DISPLAY, StrId::STR_CAT_READER,
|
||||||
StrId::STR_CAT_CONTROLS, StrId::STR_CAT_SYSTEM};
|
StrId::STR_CAT_CONTROLS, StrId::STR_CAT_SYSTEM};
|
||||||
|
|
||||||
|
std::string SettingInfo::getTitle() const {
|
||||||
|
const auto t = I18N.get(nameId);
|
||||||
|
return isSeparator ? UITheme::makeSeparatorTitle(t) : t;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SettingsActivity::isListItemSelectable(int settingIdx) const {
|
||||||
|
return settingIdx >= 0 && settingIdx < settingsCount && !(*currentSettings)[settingIdx].isSeparator;
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsActivity::onEnter() {
|
void SettingsActivity::onEnter() {
|
||||||
Activity::onEnter();
|
Activity::onEnter();
|
||||||
|
|
||||||
@@ -57,15 +66,23 @@ void SettingsActivity::onEnter() {
|
|||||||
// Append device-only ACTION items
|
// Append device-only ACTION items
|
||||||
controlsSettings.insert(controlsSettings.begin(),
|
controlsSettings.insert(controlsSettings.begin(),
|
||||||
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
|
SettingInfo::Action(StrId::STR_REMAP_FRONT_BUTTONS, SettingAction::RemapFrontButtons));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLOCK_SETTINGS, SettingAction::ClockSettings));
|
|
||||||
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
|
||||||
|
// Network section
|
||||||
|
systemSettings.push_back(SettingInfo::Separator(StrId::STR_MENU_SYS_NETWORK));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_WIFI_NETWORKS, SettingAction::Network));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_WIFI_NETWORKS, SettingAction::Network));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_KOREADER_SYNC, SettingAction::KOReaderSync));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_KOREADER_SYNC, SettingAction::KOReaderSync));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_OPDS_BROWSER, SettingAction::OPDSBrowser));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_OPDS_BROWSER, SettingAction::OPDSBrowser));
|
||||||
|
// Tools section
|
||||||
|
systemSettings.push_back(SettingInfo::Separator(StrId::STR_MENU_SYS_TOOLS));
|
||||||
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLOCK_SETTINGS, SettingAction::ClockSettings));
|
||||||
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_WEATHER_SETTINGS, SettingAction::Weather));
|
||||||
|
// System section
|
||||||
|
systemSettings.push_back(SettingInfo::Separator(StrId::STR_MENU_SYS_SYSTEM));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_CLEAR_READING_CACHE, SettingAction::ClearCache));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_CHECK_UPDATES, SettingAction::CheckForUpdates));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_LANGUAGE, SettingAction::Language));
|
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_SYSTEM_INFO, SettingAction::SystemInfo));
|
systemSettings.push_back(SettingInfo::Action(StrId::STR_SYSTEM_INFO, SettingAction::SystemInfo));
|
||||||
systemSettings.push_back(SettingInfo::Action(StrId::STR_WEATHER_SETTINGS, SettingAction::Weather));
|
|
||||||
readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));
|
||||||
|
|
||||||
// Reset selection to first category
|
// Reset selection to first category
|
||||||
@@ -115,12 +132,14 @@ void SettingsActivity::loop() {
|
|||||||
|
|
||||||
// Handle navigation
|
// Handle navigation
|
||||||
buttonNavigator.onNextRelease([this] {
|
buttonNavigator.onNextRelease([this] {
|
||||||
selectedSettingIndex = ButtonNavigator::nextIndex(selectedSettingIndex, settingsCount + 1);
|
selectedSettingIndex = ButtonNavigator::nextIndex(selectedSettingIndex, settingsCount + 1,
|
||||||
|
[this](int i) { return i == 0 || isListItemSelectable(i - 1); });
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
buttonNavigator.onPreviousRelease([this] {
|
buttonNavigator.onPreviousRelease([this] {
|
||||||
selectedSettingIndex = ButtonNavigator::previousIndex(selectedSettingIndex, settingsCount + 1);
|
selectedSettingIndex = ButtonNavigator::previousIndex(
|
||||||
|
selectedSettingIndex, settingsCount + 1, [this](int i) { return i == 0 || isListItemSelectable(i - 1); });
|
||||||
requestUpdate();
|
requestUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -163,6 +182,7 @@ void SettingsActivity::toggleCurrentSetting() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const auto& setting = (*currentSettings)[selectedSetting];
|
const auto& setting = (*currentSettings)[selectedSetting];
|
||||||
|
if (setting.isSeparator) return;
|
||||||
|
|
||||||
if (setting.type == SettingType::TOGGLE && setting.valuePtr != nullptr) {
|
if (setting.type == SettingType::TOGGLE && setting.valuePtr != nullptr) {
|
||||||
// Toggle the boolean value using the member pointer
|
// Toggle the boolean value using the member pointer
|
||||||
@@ -258,8 +278,8 @@ void SettingsActivity::render(RenderLock&&) {
|
|||||||
Rect{contentRect.x, contentTop, contentRect.width,
|
Rect{contentRect.x, contentTop, contentRect.width,
|
||||||
contentRect.height -
|
contentRect.height -
|
||||||
(metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing * 2)},
|
(metrics.topPadding + metrics.headerHeight + metrics.tabBarHeight + metrics.verticalSpacing * 2)},
|
||||||
settingsCount, selectedSettingIndex - 1,
|
settingsCount, selectedSettingIndex - 1, [&settings](int index) { return settings[index].getTitle(); }, nullptr,
|
||||||
[&settings](int index) { return std::string(I18N.get(settings[index].nameId)); }, nullptr, nullptr,
|
nullptr,
|
||||||
[&settings](int i) {
|
[&settings](int i) {
|
||||||
const auto& setting = settings[i];
|
const auto& setting = settings[i];
|
||||||
std::string valueText = "";
|
std::string valueText = "";
|
||||||
|
|||||||
@@ -142,6 +142,17 @@ struct SettingInfo {
|
|||||||
s.category = category;
|
s.category = category;
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SettingInfo Separator(StrId nameId) {
|
||||||
|
SettingInfo s;
|
||||||
|
s.nameId = nameId;
|
||||||
|
s.type = SettingType::ACTION;
|
||||||
|
s.isSeparator = true;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isSeparator = false;
|
||||||
|
[[nodiscard]] std::string getTitle() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SettingsActivity final : public Activity {
|
class SettingsActivity final : public Activity {
|
||||||
@@ -163,6 +174,7 @@ class SettingsActivity final : public Activity {
|
|||||||
|
|
||||||
void enterCategory(int categoryIndex);
|
void enterCategory(int categoryIndex);
|
||||||
void toggleCurrentSetting();
|
void toggleCurrentSetting();
|
||||||
|
[[nodiscard]] bool isListItemSelectable(int settingIdx) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
explicit SettingsActivity(GfxRenderer& renderer, MappedInputManager& mappedInput)
|
||||||
|
|||||||
@@ -108,11 +108,9 @@ std::string UITheme::stripSeparatorTitle(const std::string& title) {
|
|||||||
return isSeparatorTitle(title) ? title.substr(2) : title;
|
return isSeparatorTitle(title) ? title.substr(2) : title;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<bool(int)> UITheme::makeSelectablePredicate(int total,
|
std::function<bool(int)> UITheme::makeSelectablePredicate(int total, std::function<std::string(int)> titleGetter) {
|
||||||
std::function<std::string(int)> titleGetter) {
|
return
|
||||||
return [total, titleGetter](int index) {
|
[total, titleGetter](int index) { return index >= 0 && index < total && !isSeparatorTitle(titleGetter(index)); };
|
||||||
return index >= 0 && index < total && !isSeparatorTitle(titleGetter(index));
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UITheme::getCoverThumbPath(std::string coverBmpPath, int coverHeight) {
|
std::string UITheme::getCoverThumbPath(std::string coverBmpPath, int coverHeight) {
|
||||||
|
|||||||
Reference in New Issue
Block a user