Skip to content

Commit eb0af22

Browse files
committed
Watch face settings : disable watch faces that are not available (external resources are not installed).
1 parent 8c7be1f commit eb0af22

File tree

9 files changed

+72
-11
lines changed

9 files changed

+72
-11
lines changed

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
390390
ReturnApp(Apps::QuickSettings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
391391
break;
392392
case Apps::SettingWatchFace:
393-
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController);
393+
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, settingsController, filesystem);
394394
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
395395
break;
396396
case Apps::SettingTimeFormat:

src/displayapp/screens/CheckboxList.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ CheckboxList::CheckboxList(const uint8_t screenID,
1818
const char* optionsSymbol,
1919
uint32_t originalValue,
2020
std::function<void(uint32_t)> OnValueChanged,
21-
std::array<const char*, MaxItems> options)
21+
std::array<Item, MaxItems> options)
2222
: Screen(app), screenID {screenID}, OnValueChanged {std::move(OnValueChanged)}, options {options}, value {originalValue} {
2323
// Set the background to Black
2424
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,
7272
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
7373

7474
for (unsigned int i = 0; i < options.size(); i++) {
75-
if (strcmp(options[i], "")) {
75+
if (strcmp(options[i].name, "")) {
7676
cbOption[i] = lv_checkbox_create(container1, nullptr);
77-
lv_checkbox_set_text(cbOption[i], options[i]);
77+
lv_checkbox_set_text(cbOption[i], options[i].name);
78+
if (!options[i].enabled) {
79+
lv_checkbox_set_disabled(cbOption[i]);
80+
}
7881
cbOption[i]->user_data = this;
7982
lv_obj_set_event_cb(cbOption[i], event_handler);
8083
SetRadioButtonStyle(cbOption[i]);
@@ -94,13 +97,16 @@ CheckboxList::~CheckboxList() {
9497
void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) {
9598
if (event == LV_EVENT_VALUE_CHANGED) {
9699
for (unsigned int i = 0; i < options.size(); i++) {
97-
if (strcmp(options[i], "")) {
100+
if (strcmp(options[i].name, "")) {
98101
if (object == cbOption[i]) {
99102
lv_checkbox_set_checked(cbOption[i], true);
100103
value = MaxItems * screenID + i;
101104
} else {
102105
lv_checkbox_set_checked(cbOption[i], false);
103106
}
107+
if (!options[i].enabled) {
108+
lv_checkbox_set_disabled(cbOption[i]);
109+
}
104110
}
105111
}
106112
}

src/displayapp/screens/CheckboxList.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,26 @@ namespace Pinetime {
1414
class CheckboxList : public Screen {
1515
public:
1616
static constexpr size_t MaxItems = 4;
17+
struct Item {
18+
const char* name;
19+
bool enabled;
20+
};
21+
1722
CheckboxList(const uint8_t screenID,
1823
const uint8_t numScreens,
1924
DisplayApp* app,
2025
const char* optionsTitle,
2126
const char* optionsSymbol,
2227
uint32_t originalValue,
2328
std::function<void(uint32_t)> OnValueChanged,
24-
std::array<const char*, MaxItems> options);
29+
std::array<Item, MaxItems> options);
2530
~CheckboxList() override;
2631
void UpdateSelected(lv_obj_t* object, lv_event_t event);
2732

2833
private:
2934
const uint8_t screenID;
3035
std::function<void(uint32_t)> OnValueChanged;
31-
std::array<const char*, MaxItems> options;
36+
std::array<Item, MaxItems> options;
3237
std::array<lv_obj_t*, MaxItems> cbOption;
3338
std::array<lv_point_t, 2> pageIndicatorBasePoints;
3439
std::array<lv_point_t, 2> pageIndicatorPoints;

src/displayapp/screens/WatchFaceCasioStyleG7710.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,20 @@ void WatchFaceCasioStyleG7710::Refresh() {
333333
lv_obj_realign(stepIcon);
334334
}
335335
}
336+
bool WatchFaceCasioStyleG7710::IsAvailable(Pinetime::Controllers::FS& filesystem) {
337+
lfs_file file = {};
338+
339+
if (filesystem.FileOpen(&file, "/fonts/lv_font_dots_40.bin", LFS_O_RDONLY) < 0) {
340+
return false;
341+
}
342+
343+
if (filesystem.FileOpen(&file, "/fonts/7segments_40.bin", LFS_O_RDONLY) < 0) {
344+
return false;
345+
}
346+
347+
if (filesystem.FileOpen(&file, "/fonts/7segments_115.bin", LFS_O_RDONLY) < 0) {
348+
return false;
349+
}
350+
351+
return true;
352+
}

src/displayapp/screens/WatchFaceCasioStyleG7710.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace Pinetime {
3737

3838
void Refresh() override;
3939

40+
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
41+
4042
private:
4143
uint8_t displayedHour = -1;
4244
uint8_t displayedMinute = -1;

src/displayapp/screens/WatchFaceInfineat.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,3 +609,21 @@ void WatchFaceInfineat::ToggleBatteryIndicatorColor(bool showSideCover) {
609609
lv_color_hex(infineatColors.orange[settingsController.GetInfineatColorIndex() * nLines + 7]));
610610
}
611611
}
612+
613+
bool WatchFaceInfineat::IsAvailable(Pinetime::Controllers::FS& filesystem) {
614+
lfs_file file = {};
615+
616+
if (filesystem.FileOpen(&file, "/fonts/teko.bin", LFS_O_RDONLY) < 0) {
617+
return false;
618+
}
619+
620+
if (filesystem.FileOpen(&file, "/fonts/bebas.bin", LFS_O_RDONLY) < 0) {
621+
return false;
622+
}
623+
624+
if (filesystem.FileOpen(&file, "/images/pine_small.bin", LFS_O_RDONLY) < 0) {
625+
return false;
626+
}
627+
628+
return true;
629+
}

src/displayapp/screens/WatchFaceInfineat.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ namespace Pinetime {
3939

4040
void Refresh() override;
4141

42+
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
43+
4244
private:
4345
char displayedChar[5] {};
4446

src/displayapp/screens/settings/SettingWatchFace.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
#include "displayapp/screens/CheckboxList.h"
55
#include "displayapp/screens/Screen.h"
66
#include "components/settings/Settings.h"
7+
#include "displayapp/screens/WatchFaceInfineat.h"
8+
#include "displayapp/screens/WatchFaceCasioStyleG7710.h"
79

810
using namespace Pinetime::Applications::Screens;
911

1012
constexpr const char* SettingWatchFace::title;
1113
constexpr const char* SettingWatchFace::symbol;
1214

13-
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pinetime::Controllers::Settings& settingsController)
15+
SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app,
16+
Pinetime::Controllers::Settings& settingsController,
17+
Pinetime::Controllers::FS& filesystem)
1418
: Screen(app),
1519
settingsController {settingsController},
20+
filesystem {filesystem},
1621
screens {app,
1722
0,
1823
{[this]() -> std::unique_ptr<Screen> {
@@ -33,7 +38,8 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
3338
}
3439

3540
std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
36-
std::array<const char*, 4> watchfaces {"Digital face", "Analog face", "PineTimeStyle", "Terminal"};
41+
std::array<Screens::CheckboxList::Item, 4> watchfaces {
42+
{{"Digital face", true}, {"Analog face", true}, {"PineTimeStyle", true}, {"Terminal", true}}};
3743
return std::make_unique<Screens::CheckboxList>(
3844
0,
3945
2,
@@ -49,7 +55,11 @@ std::unique_ptr<Screen> SettingWatchFace::CreateScreen1() {
4955
}
5056

5157
std::unique_ptr<Screen> SettingWatchFace::CreateScreen2() {
52-
std::array<const char*, 4> watchfaces {"Infineat face", "Casio G7710", "", ""};
58+
std::array<Screens::CheckboxList::Item, 4> watchfaces {
59+
{{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)},
60+
{"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)},
61+
{"", false},
62+
{"", false}}};
5363
return std::make_unique<Screens::CheckboxList>(
5464
1,
5565
2,

src/displayapp/screens/settings/SettingWatchFace.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ namespace Pinetime {
1616

1717
class SettingWatchFace : public Screen {
1818
public:
19-
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController);
19+
SettingWatchFace(DisplayApp* app, Pinetime::Controllers::Settings& settingsController, Pinetime::Controllers::FS& filesystem);
2020
~SettingWatchFace() override;
2121

2222
bool OnTouchEvent(TouchEvents event) override;
2323

2424
private:
2525
Controllers::Settings& settingsController;
26+
Pinetime::Controllers::FS& filesystem;
2627
ScreenList<2> screens;
2728

2829
static constexpr const char* title = "Watch face";

0 commit comments

Comments
 (0)