Watch face settings : disable watch faces that are not available (external resources are not installed).

This commit is contained in:
Jean-François Milants 2022-10-11 21:36:31 +02:00
parent 8c7be1fbb1
commit eb0af22ecf
9 changed files with 72 additions and 11 deletions

View file

@ -390,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingWatchFace:
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController);
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController, filesystem);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingTimeFormat:

View file

@ -18,7 +18,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
const char* optionsSymbol,
uint32_t originalValue,
std::function<void(uint32_t)> OnValueChanged,
std::array<const char*, MaxItems> options)
std::array<Item, MaxItems> options)
: Screen(app), screenID {screenID}, OnValueChanged {std::move(OnValueChanged)}, options {options}, value {originalValue} {
// Set the background to Black
lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
@ -72,9 +72,12 @@ CheckboxList::CheckboxList(const uint8_t screenID,
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
for (unsigned int i = 0; i < options.size(); i++) {
if (strcmp(options[i], "")) {
if (strcmp(options[i].name, "")) {
cbOption[i] = lv_checkbox_create(container1, nullptr);
lv_checkbox_set_text(cbOption[i], options[i]);
lv_checkbox_set_text(cbOption[i], options[i].name);
if (!options[i].enabled) {
lv_checkbox_set_disabled(cbOption[i]);
}
cbOption[i]->user_data = this;
lv_obj_set_event_cb(cbOption[i], event_handler);
SetRadioButtonStyle(cbOption[i]);
@ -94,13 +97,16 @@ CheckboxList::~CheckboxList() {
void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
if (event == LV_EVENT_VALUE_CHANGED) {
for (unsigned int i = 0; i < options.size(); i++) {
if (strcmp(options[i], "")) {
if (strcmp(options[i].name, "")) {
if (object == cbOption[i]) {
lv_checkbox_set_checked(cbOption[i], true);
value = MaxItems * screenID + i;
} else {
lv_checkbox_set_checked(cbOption[i], false);
}
if (!options[i].enabled) {
lv_checkbox_set_disabled(cbOption[i]);
}
}
}
}

View file

@ -14,6 +14,11 @@ namespace Pinetime {
class CheckboxList : public Screen {
public:
static constexpr size_t MaxItems = 4;
struct Item {
const char* name;
bool enabled;
};
CheckboxList(const uint8_t screenID,
const uint8_t numScreens,
DisplayApp* app,
@ -21,14 +26,14 @@ namespace Pinetime {
const char* optionsSymbol,
uint32_t originalValue,
std::function<void(uint32_t)> OnValueChanged,
std::array<const char*, MaxItems> options);
std::array<Item, MaxItems> options);
~CheckboxList() override;
void UpdateSelected(lv_obj_t* object, lv_event_t event);
private:
const uint8_t screenID;
std::function<void(uint32_t)> OnValueChanged;
std::array<const char*, MaxItems> options;
std::array<Item, MaxItems> options;
std::array<lv_obj_t*, MaxItems> cbOption;
std::array<lv_point_t, 2> pageIndicatorBasePoints;
std::array<lv_point_t, 2> pageIndicatorPoints;

View file

@ -333,3 +333,20 @@ void WatchFaceCasioStyleG7710::Refresh() {
lv_obj_realign(stepIcon);
}
}
bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) {
lfs_file file = {};
if (filesystem.FileOpen(&file, "/fonts/lv_font_dots_40.bin", LFS_O_RDONLY) < 0) {
return false;
}
if (filesystem.FileOpen(&file, "/fonts/7segments_40.bin", LFS_O_RDONLY) < 0) {
return false;
}
if (filesystem.FileOpen(&file, "/fonts/7segments_115.bin", LFS_O_RDONLY) < 0) {
return false;
}
return true;
}

View file

@ -37,6 +37,8 @@ namespace Pinetime {
void Refresh() override;
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
private:
uint8_t displayedHour = -1;
uint8_t displayedMinute = -1;

View file

@ -609,3 +609,21 @@ void WatchFaceInfineat::ToggleBatteryIndicatorColor(bool showSideCover) {
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 7]));
}
}
bool WatchFaceInfineat::IsAvailable(Pinetime::Controllers::FS& filesystem) {
lfs_file file = {};
if (filesystem.FileOpen(&file, "/fonts/teko.bin", LFS_O_RDONLY) < 0) {
return false;
}
if (filesystem.FileOpen(&file, "/fonts/bebas.bin", LFS_O_RDONLY) < 0) {
return false;
}
if (filesystem.FileOpen(&file, "/images/pine_small.bin", LFS_O_RDONLY) < 0) {
return false;
}
return true;
}

View file

@ -39,6 +39,8 @@ namespace Pinetime {
void Refresh() override;
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
private:
char displayedChar[5] {};

View file

@ -4,15 +4,20 @@
#include "displayapp/screens/CheckboxList.h"
#include "displayapp/screens/Screen.h"
#include "components/settings/Settings.h"
#include "displayapp/screens/WatchFaceInfineat.h"
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
using namespace Pinetime::Applications::Screens;
constexpr const char* SettingWatchFace::title;
constexpr const char* SettingWatchFace::symbol;
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::Settings& settingsController,
Pinetime::Controllers::FS& filesystem)
: Screen(app),
settingsController {settingsController},
filesystem {filesystem},
screens {app,
0,
{[this]() -> std::unique_ptr<Screen> {
@ -33,7 +38,8 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
}
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
std::array<const char*, 4> watchfaces {"Digital face", "Analog face", "PineTimeStyle", "Terminal"};
std::array<Screens::CheckboxList::Item, 4> watchfaces {
{{"Digital face", true}, {"Analog face", true}, {"PineTimeStyle", true}, {"Terminal", true}}};
return std::make_unique<Screens::CheckboxList>(
0,
2,
@ -49,7 +55,11 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
}
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
std::array<const char*, 4> watchfaces {"Infineat face", "Casio G7710", "", ""};
std::array<Screens::CheckboxList::Item, 4> watchfaces {
{{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
{"", false},
{"", false}}};
return std::make_unique<Screens::CheckboxList>(
1,
2,

View file

@ -16,13 +16,14 @@ namespace Pinetime {
class SettingWatchFace : public Screen {
public:
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem);
~SettingWatchFace() override;
bool OnTouchEvent(TouchEvents event) override;
private:
Controllers::Settings& settingsController;
Pinetime::Controllers::FS& filesystem;
ScreenList<2> screens;
static constexpr const char* title = "Watch face";