mirror of
https://github.com/InfiniTimeOrg/InfiniTime.git
synced 2024-12-24 02:02:22 +03:00
Combine Date and Time Settings (#1465)
Replace separate SettingSetDate and SettingSetTime with a combined screenlist. Add DotIndicators. Similar to PageIndicator, but for use when separating screens instead of pages of a list. Co-authored-by: Riku Isokoski <riksu9000@gmail.com>
This commit is contained in:
parent
6f6ea68aca
commit
a7f8b59bfb
@ -407,6 +407,7 @@ list(APPEND SOURCE_FILES
|
||||
displayapp/Colors.cpp
|
||||
displayapp/widgets/Counter.cpp
|
||||
displayapp/widgets/PageIndicator.cpp
|
||||
displayapp/widgets/DotIndicator.cpp
|
||||
displayapp/widgets/StatusIcons.cpp
|
||||
|
||||
## Settings
|
||||
@ -417,6 +418,7 @@ list(APPEND SOURCE_FILES
|
||||
displayapp/screens/settings/SettingWakeUp.cpp
|
||||
displayapp/screens/settings/SettingDisplay.cpp
|
||||
displayapp/screens/settings/SettingSteps.cpp
|
||||
displayapp/screens/settings/SettingSetDateTime.cpp
|
||||
displayapp/screens/settings/SettingSetDate.cpp
|
||||
displayapp/screens/settings/SettingSetTime.cpp
|
||||
displayapp/screens/settings/SettingChimes.cpp
|
||||
@ -616,6 +618,7 @@ set(INCLUDE_FILES
|
||||
displayapp/Colors.h
|
||||
displayapp/widgets/Counter.h
|
||||
displayapp/widgets/PageIndicator.h
|
||||
displayapp/widgets/DotIndicator.h
|
||||
displayapp/widgets/StatusIcons.h
|
||||
drivers/St7789.h
|
||||
drivers/SpiNorFlash.h
|
||||
|
@ -34,8 +34,7 @@ namespace Pinetime {
|
||||
SettingDisplay,
|
||||
SettingWakeUp,
|
||||
SettingSteps,
|
||||
SettingSetDate,
|
||||
SettingSetTime,
|
||||
SettingSetDateTime,
|
||||
SettingChimes,
|
||||
SettingShakeThreshold,
|
||||
SettingBluetooth,
|
||||
|
@ -43,8 +43,7 @@
|
||||
#include "displayapp/screens/settings/SettingWakeUp.h"
|
||||
#include "displayapp/screens/settings/SettingDisplay.h"
|
||||
#include "displayapp/screens/settings/SettingSteps.h"
|
||||
#include "displayapp/screens/settings/SettingSetDate.h"
|
||||
#include "displayapp/screens/settings/SettingSetTime.h"
|
||||
#include "displayapp/screens/settings/SettingSetDateTime.h"
|
||||
#include "displayapp/screens/settings/SettingChimes.h"
|
||||
#include "displayapp/screens/settings/SettingShakeThreshold.h"
|
||||
#include "displayapp/screens/settings/SettingBluetooth.h"
|
||||
@ -430,11 +429,8 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
|
||||
case Apps::SettingSteps:
|
||||
currentScreen = std::make_unique<Screens::SettingSteps>(this, settingsController);
|
||||
break;
|
||||
case Apps::SettingSetDate:
|
||||
currentScreen = std::make_unique<Screens::SettingSetDate>(this, dateTimeController);
|
||||
break;
|
||||
case Apps::SettingSetTime:
|
||||
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController, settingsController);
|
||||
case Apps::SettingSetDateTime:
|
||||
currentScreen = std::make_unique<Screens::SettingSetDateTime>(this, dateTimeController, settingsController);
|
||||
break;
|
||||
case Apps::SettingChimes:
|
||||
currentScreen = std::make_unique<Screens::SettingChimes>(this, settingsController);
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "displayapp/screens/settings/SettingSetDate.h"
|
||||
#include "displayapp/screens/settings/SettingSetDateTime.h"
|
||||
#include <lvgl/lvgl.h>
|
||||
#include <hal/nrf_rtc.h>
|
||||
#include <nrf_log.h>
|
||||
@ -44,8 +45,11 @@ namespace {
|
||||
}
|
||||
}
|
||||
|
||||
SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::DateTime& dateTimeController)
|
||||
: Screen(app), dateTimeController {dateTimeController} {
|
||||
SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime)
|
||||
: Screen(app), dateTimeController {dateTimeController}, settingSetDateTime {settingSetDateTime} {
|
||||
|
||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Set current date");
|
||||
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
|
||||
@ -82,8 +86,6 @@ SettingSetDate::SettingSetDate(Pinetime::Applications::DisplayApp* app, Pinetime
|
||||
lblSetTime = lv_label_create(btnSetTime, nullptr);
|
||||
lv_label_set_text_static(lblSetTime, "Set");
|
||||
lv_obj_set_event_cb(btnSetTime, event_handler);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
SettingSetDate::~SettingSetDate() {
|
||||
@ -103,13 +105,10 @@ void SettingSetDate::HandleButtonPress() {
|
||||
dateTimeController.Minutes(),
|
||||
dateTimeController.Seconds(),
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_DISABLED);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DISABLED);
|
||||
settingSetDateTime.Advance();
|
||||
}
|
||||
|
||||
void SettingSetDate::CheckDay() {
|
||||
const int maxDay = MaximumDayOfMonth(monthCounter.GetValue(), yearCounter.GetValue());
|
||||
dayCounter.SetMax(maxDay);
|
||||
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DEFAULT);
|
||||
}
|
||||
|
@ -5,13 +5,17 @@
|
||||
#include "components/datetime/DateTimeController.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/widgets/Counter.h"
|
||||
#include "displayapp/widgets/DotIndicator.h"
|
||||
#include "displayapp/screens/settings/SettingSetDateTime.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class SettingSetDate : public Screen {
|
||||
public:
|
||||
SettingSetDate(DisplayApp* app, Pinetime::Controllers::DateTime& dateTimeController);
|
||||
SettingSetDate(DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime);
|
||||
~SettingSetDate() override;
|
||||
|
||||
void HandleButtonPress();
|
||||
@ -19,6 +23,7 @@ namespace Pinetime {
|
||||
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime;
|
||||
|
||||
lv_obj_t* btnSetTime;
|
||||
lv_obj_t* lblSetTime;
|
||||
|
54
src/displayapp/screens/settings/SettingSetDateTime.cpp
Normal file
54
src/displayapp/screens/settings/SettingSetDateTime.cpp
Normal file
@ -0,0 +1,54 @@
|
||||
#include "displayapp/screens/settings/SettingSetDateTime.h"
|
||||
#include "displayapp/screens/settings/SettingSetDate.h"
|
||||
#include "displayapp/screens/settings/SettingSetTime.h"
|
||||
#include "displayapp/DisplayApp.h"
|
||||
#include "displayapp/screens/ScreenList.h"
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/widgets/DotIndicator.h"
|
||||
|
||||
using namespace Pinetime::Applications::Screens;
|
||||
|
||||
bool SettingSetDateTime::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
||||
return screens.OnTouchEvent(event);
|
||||
}
|
||||
|
||||
SettingSetDateTime::SettingSetDateTime(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app),
|
||||
dateTimeController {dateTimeController},
|
||||
settingsController {settingsController},
|
||||
screens {app,
|
||||
0,
|
||||
{[this]() -> std::unique_ptr<Screen> {
|
||||
return screenSetDate();
|
||||
},
|
||||
[this]() -> std::unique_ptr<Screen> {
|
||||
return screenSetTime();
|
||||
}},
|
||||
Screens::ScreenListModes::UpDown} {
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingSetDateTime::screenSetDate() {
|
||||
Widgets::DotIndicator dotIndicator(0, 2);
|
||||
dotIndicator.Create();
|
||||
return std::make_unique<Screens::SettingSetDate>(app, dateTimeController, *this);
|
||||
}
|
||||
|
||||
std::unique_ptr<Screen> SettingSetDateTime::screenSetTime() {
|
||||
Widgets::DotIndicator dotIndicator(1, 2);
|
||||
dotIndicator.Create();
|
||||
return std::make_unique<Screens::SettingSetTime>(app, dateTimeController, settingsController, *this);
|
||||
}
|
||||
|
||||
SettingSetDateTime::~SettingSetDateTime() {
|
||||
lv_obj_clean(lv_scr_act());
|
||||
}
|
||||
|
||||
void SettingSetDateTime::Advance() {
|
||||
screens.OnTouchEvent(Pinetime::Applications::TouchEvents::SwipeUp);
|
||||
}
|
||||
|
||||
void SettingSetDateTime::Quit() {
|
||||
running = false;
|
||||
}
|
32
src/displayapp/screens/settings/SettingSetDateTime.h
Normal file
32
src/displayapp/screens/settings/SettingSetDateTime.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <lvgl/lvgl.h>
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/screens/ScreenList.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Screens {
|
||||
class SettingSetDateTime : public Screen {
|
||||
public:
|
||||
SettingSetDateTime(DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
~SettingSetDateTime() override;
|
||||
|
||||
bool OnTouchEvent(TouchEvents event) override;
|
||||
void Advance();
|
||||
void Quit();
|
||||
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Controllers::Settings& settingsController;
|
||||
|
||||
ScreenList<2> screens;
|
||||
std::unique_ptr<Screen> screenSetDate();
|
||||
std::unique_ptr<Screen> screenSetTime();
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -27,8 +27,9 @@ namespace {
|
||||
|
||||
SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController)
|
||||
: Screen(app), dateTimeController {dateTimeController}, settingsController {settingsController} {
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime)
|
||||
: Screen(app), dateTimeController {dateTimeController}, settingsController {settingsController}, settingSetDateTime {settingSetDateTime} {
|
||||
|
||||
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
|
||||
lv_label_set_text_static(title, "Set current time");
|
||||
@ -75,8 +76,6 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
|
||||
lv_obj_set_event_cb(btnSetTime, SetTimeEventHandler);
|
||||
|
||||
UpdateScreen();
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DISABLED);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DISABLED);
|
||||
}
|
||||
|
||||
SettingSetTime::~SettingSetTime() {
|
||||
@ -91,8 +90,6 @@ void SettingSetTime::UpdateScreen() {
|
||||
lv_label_set_text_static(lblampm, "AM");
|
||||
}
|
||||
}
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DEFAULT);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DEFAULT);
|
||||
}
|
||||
|
||||
void SettingSetTime::SetTime() {
|
||||
@ -107,6 +104,5 @@ void SettingSetTime::SetTime() {
|
||||
static_cast<uint8_t>(minutesValue),
|
||||
0,
|
||||
nrf_rtc_counter_get(portNRF_RTC_REG));
|
||||
lv_obj_set_state(btnSetTime, LV_STATE_DISABLED);
|
||||
lv_obj_set_state(lblSetTime, LV_STATE_DISABLED);
|
||||
settingSetDateTime.Quit();
|
||||
}
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "components/settings/Settings.h"
|
||||
#include "displayapp/widgets/Counter.h"
|
||||
#include "displayapp/screens/Screen.h"
|
||||
#include "displayapp/widgets/DotIndicator.h"
|
||||
#include "displayapp/screens/settings/SettingSetDateTime.h"
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
@ -14,7 +16,8 @@ namespace Pinetime {
|
||||
public:
|
||||
SettingSetTime(DisplayApp* app,
|
||||
Pinetime::Controllers::DateTime& dateTimeController,
|
||||
Pinetime::Controllers::Settings& settingsController);
|
||||
Pinetime::Controllers::Settings& settingsController,
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime);
|
||||
~SettingSetTime() override;
|
||||
|
||||
void SetTime();
|
||||
@ -23,6 +26,7 @@ namespace Pinetime {
|
||||
private:
|
||||
Controllers::DateTime& dateTimeController;
|
||||
Controllers::Settings& settingsController;
|
||||
Pinetime::Applications::Screens::SettingSetDateTime& settingSetDateTime;
|
||||
|
||||
lv_obj_t* lblampm;
|
||||
lv_obj_t* btnSetTime;
|
||||
|
@ -28,7 +28,7 @@ namespace Pinetime {
|
||||
static constexpr int entriesPerScreen = 4;
|
||||
|
||||
// Increment this when more space is needed
|
||||
static constexpr int nScreens = 4;
|
||||
static constexpr int nScreens = 3;
|
||||
|
||||
static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
|
||||
{Symbols::sun, "Display", Apps::SettingDisplay},
|
||||
@ -37,19 +37,20 @@ namespace Pinetime {
|
||||
{Symbols::home, "Watch face", Apps::SettingWatchFace},
|
||||
|
||||
{Symbols::shoe, "Steps", Apps::SettingSteps},
|
||||
{Symbols::clock, "Set date", Apps::SettingSetDate},
|
||||
{Symbols::clock, "Set time", Apps::SettingSetTime},
|
||||
{Symbols::clock, "Date&Time", Apps::SettingSetDateTime},
|
||||
{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
|
||||
|
||||
{Symbols::clock, "Chimes", Apps::SettingChimes},
|
||||
|
||||
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
|
||||
{Symbols::check, "Firmware", Apps::FirmwareValidation},
|
||||
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
|
||||
|
||||
{Symbols::list, "About", Apps::SysInfo},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
{Symbols::none, "None", Apps::None},
|
||||
|
||||
// {Symbols::none, "None", Apps::None},
|
||||
// {Symbols::none, "None", Apps::None},
|
||||
// {Symbols::none, "None", Apps::None},
|
||||
// {Symbols::none, "None", Apps::None},
|
||||
|
||||
}};
|
||||
ScreenList<nScreens> screens;
|
||||
};
|
||||
|
28
src/displayapp/widgets/DotIndicator.cpp
Normal file
28
src/displayapp/widgets/DotIndicator.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
#include "displayapp/widgets/DotIndicator.h"
|
||||
#include "displayapp/InfiniTimeTheme.h"
|
||||
|
||||
using namespace Pinetime::Applications::Widgets;
|
||||
|
||||
DotIndicator::DotIndicator(uint8_t nCurrentScreen, uint8_t nScreens) : nCurrentScreen {nCurrentScreen}, nScreens {nScreens} {
|
||||
}
|
||||
|
||||
void DotIndicator::Create() {
|
||||
lv_obj_t* dotIndicator[nScreens];
|
||||
static constexpr uint8_t dotSize = 12;
|
||||
|
||||
lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr);
|
||||
lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT);
|
||||
lv_cont_set_fit(container, LV_FIT_TIGHT);
|
||||
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, dotSize);
|
||||
lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP);
|
||||
|
||||
for (int i = 0; i < nScreens; i++) {
|
||||
dotIndicator[i] = lv_obj_create(container, nullptr);
|
||||
lv_obj_set_size(dotIndicator[i], dotSize, dotSize);
|
||||
lv_obj_set_style_local_bg_color(dotIndicator[i], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
||||
}
|
||||
|
||||
lv_obj_set_style_local_bg_color(dotIndicator[nCurrentScreen], LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
||||
|
||||
lv_obj_align(container, nullptr, LV_ALIGN_IN_RIGHT_MID, 0, 0);
|
||||
}
|
18
src/displayapp/widgets/DotIndicator.h
Normal file
18
src/displayapp/widgets/DotIndicator.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
#include <lvgl/lvgl.h>
|
||||
|
||||
namespace Pinetime {
|
||||
namespace Applications {
|
||||
namespace Widgets {
|
||||
class DotIndicator {
|
||||
public:
|
||||
DotIndicator(uint8_t nCurrentScreen, uint8_t nScreens);
|
||||
void Create();
|
||||
|
||||
private:
|
||||
uint8_t nCurrentScreen;
|
||||
uint8_t nScreens;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user