feat: add custom sleep timer picker (#2206)
## Summary * **What is the goal of this PR?** Mainly fixes #2196, but also allows users to set a sleep time of 1~30 min or to never sleep. * **What changes are included?** 1. Revert changes from #1948 and #2137 (Sorry @Uri-Tauber) 2. Cherrypick changes from https://github.com/uxjulia/CrossInk/commit/0cb91c3dd1c63f0559d4392fadc4a8340af5bdde and https://github.com/uxjulia/CrossInk/commit/4e6bd634b6ede51ff1a7107ba3e8efcd152bc6ee for a timeout interval picker UI, the custom sleep time feature, and migrate the existing setting in v1.3.0, `sleepTimeout`, to `sleepTimeoutMinutes` (Thanks! @uxjulia) 3. Add a "Never" at the far right of the timeout interval picker --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**PARTIALLY**_ --------- Co-authored-by: Julia <julia@uxj.io>
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
#include <GfxRenderer.h>
|
||||
#include <Logging.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#include "ButtonRemapActivity.h"
|
||||
#include "ClearCacheActivity.h"
|
||||
#include "CrossPointSettings.h"
|
||||
@@ -18,6 +22,7 @@
|
||||
#include "SettingsList.h"
|
||||
#include "StatusBarSettingsActivity.h"
|
||||
#include "activities/network/WifiSelectionActivity.h"
|
||||
#include "activities/util/IntervalSelectionActivity.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
@@ -183,6 +188,11 @@ void SettingsActivity::toggleCurrentSetting() {
|
||||
const bool sleepScreenChanged = setting.valuePtr == &CrossPointSettings::sleepScreen;
|
||||
const bool quickResumeTimeoutChanged = setting.valuePtr == &CrossPointSettings::quickResumeSleepScreen;
|
||||
|
||||
if (setting.nameId == StrId::STR_TIME_TO_SLEEP) {
|
||||
openSleepTimeoutPicker();
|
||||
return;
|
||||
}
|
||||
|
||||
if (setting.type == SettingType::TOGGLE && setting.valuePtr != nullptr) {
|
||||
// Toggle the boolean value using the member pointer
|
||||
const bool currentValue = SETTINGS.*(setting.valuePtr);
|
||||
@@ -286,6 +296,22 @@ void SettingsActivity::syncQuickResumeTimeoutForSleepScreen(bool sleepScreenChan
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsActivity::openSleepTimeoutPicker() {
|
||||
startActivityForResult(
|
||||
std::make_unique<IntervalSelectionActivity>(
|
||||
renderer, mappedInput, "SleepTimeoutInterval", StrId::STR_TIME_TO_SLEEP, StrId::STR_SLEEP_TIMER_STEP_HINT,
|
||||
SETTINGS.sleepTimeoutMinutes, CrossPointSettings::MIN_SLEEP_TIMEOUT_MINUTES,
|
||||
CrossPointSettings::MAX_SLEEP_TIMEOUT_MINUTES, 1, 5, StrId::STR_SLEEP_TIMER_VALUE_FORMAT, false, true,
|
||||
StrId::STR_SLEEP_NEVER),
|
||||
[this](const ActivityResult& result) {
|
||||
if (!result.isCancelled) {
|
||||
SETTINGS.sleepTimeoutMinutes = static_cast<uint8_t>(std::get<IntervalResult>(result.data).value);
|
||||
SETTINGS.saveToFile();
|
||||
}
|
||||
requestUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
void SettingsActivity::render(RenderLock&&) {
|
||||
renderer.clearScreen();
|
||||
|
||||
@@ -330,16 +356,30 @@ void SettingsActivity::render(RenderLock&&) {
|
||||
valueText = I18N.get(setting.enumValues[value]);
|
||||
}
|
||||
} else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) {
|
||||
valueText = std::to_string(SETTINGS.*(setting.valuePtr));
|
||||
if (setting.nameId == StrId::STR_TIME_TO_SLEEP) {
|
||||
char valueBuffer[32];
|
||||
if (SETTINGS.sleepTimeoutMinutes >= CrossPointSettings::SLEEP_TIMEOUT_NEVER_MINUTES) {
|
||||
valueText = tr(STR_SLEEP_NEVER);
|
||||
} else {
|
||||
snprintf(valueBuffer, sizeof(valueBuffer), tr(STR_SLEEP_TIMER_VALUE_FORMAT),
|
||||
static_cast<unsigned int>(SETTINGS.*(setting.valuePtr)));
|
||||
valueText = valueBuffer;
|
||||
}
|
||||
} else {
|
||||
valueText = std::to_string(SETTINGS.*(setting.valuePtr));
|
||||
}
|
||||
}
|
||||
return valueText;
|
||||
},
|
||||
true);
|
||||
|
||||
// Draw help text
|
||||
const auto confirmLabel = (selectedSettingIndex == 0)
|
||||
? I18N.get(categoryNames[(selectedCategoryIndex + 1) % categoryCount])
|
||||
: tr(STR_TOGGLE);
|
||||
const auto confirmLabel =
|
||||
(selectedSettingIndex == 0)
|
||||
? I18N.get(categoryNames[(selectedCategoryIndex + 1) % categoryCount])
|
||||
: (selectedSettingIndex > 0 && (*currentSettings)[selectedSettingIndex - 1].nameId == StrId::STR_TIME_TO_SLEEP
|
||||
? tr(STR_SELECT)
|
||||
: tr(STR_TOGGLE));
|
||||
const auto labels = mappedInput.mapLabels(tr(STR_BACK), confirmLabel, tr(STR_DIR_UP), tr(STR_DIR_DOWN));
|
||||
GUI.drawButtonHints(renderer, labels.btn1, labels.btn2, labels.btn3, labels.btn4);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user