From eb0af22ecf66957b9341521990c49a6d1d5d70e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Milants?= Date: Tue, 11 Oct 2022 21:36:31 +0200 Subject: [PATCH] Watch face settings : disable watch faces that are not available (external resources are not installed). --- src/displayapp/DisplayApp.cpp | 2 +- src/displayapp/screens/CheckboxList.cpp | 14 ++++++++++---- src/displayapp/screens/CheckboxList.h | 9 +++++++-- .../screens/WatchFaceCasioStyleG7710.cpp | 17 +++++++++++++++++ .../screens/WatchFaceCasioStyleG7710.h | 2 ++ src/displayapp/screens/WatchFaceInfineat.cpp | 18 ++++++++++++++++++ src/displayapp/screens/WatchFaceInfineat.h | 2 ++ .../screens/settings/SettingWatchFace.cpp | 16 +++++++++++++--- .../screens/settings/SettingWatchFace.h | 3 ++- 9 files changed, 72 insertions(+), 11 deletions(-) diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 4afcd8dc..108e380d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -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(this, settingsController); + currentScreen = std::make_unique(this, settingsController, filesystem); ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown); break; case Apps::SettingTimeFormat: diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp index d97726dd..5889c69a 100644 --- a/src/displayapp/screens/CheckboxList.cpp +++ b/src/displayapp/screens/CheckboxList.cpp @@ -18,7 +18,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, const char* optionsSymbol, uint32_t originalValue, std::function OnValueChanged, - std::array options) + std::array 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]); + } } } } diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h index f9c3bae0..e9104bfb 100644 --- a/src/displayapp/screens/CheckboxList.h +++ b/src/displayapp/screens/CheckboxList.h @@ -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 OnValueChanged, - std::array options); + std::array options); ~CheckboxList() override; void UpdateSelected(lv_obj_t* object, lv_event_t event); private: const uint8_t screenID; std::function OnValueChanged; - std::array options; + std::array options; std::array cbOption; std::array pageIndicatorBasePoints; std::array pageIndicatorPoints; diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp index f9a01abd..525c2eeb 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.cpp @@ -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; +} diff --git a/src/displayapp/screens/WatchFaceCasioStyleG7710.h b/src/displayapp/screens/WatchFaceCasioStyleG7710.h index c3821205..eb7bb9e8 100644 --- a/src/displayapp/screens/WatchFaceCasioStyleG7710.h +++ b/src/displayapp/screens/WatchFaceCasioStyleG7710.h @@ -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; diff --git a/src/displayapp/screens/WatchFaceInfineat.cpp b/src/displayapp/screens/WatchFaceInfineat.cpp index 5822a1e8..01b425da 100644 --- a/src/displayapp/screens/WatchFaceInfineat.cpp +++ b/src/displayapp/screens/WatchFaceInfineat.cpp @@ -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; +} diff --git a/src/displayapp/screens/WatchFaceInfineat.h b/src/displayapp/screens/WatchFaceInfineat.h index 285908e8..6c3c30ba 100644 --- a/src/displayapp/screens/WatchFaceInfineat.h +++ b/src/displayapp/screens/WatchFaceInfineat.h @@ -39,6 +39,8 @@ namespace Pinetime { void Refresh() override; + static bool IsAvailable(Pinetime::Controllers::FS& filesystem); + private: char displayedChar[5] {}; diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 6d47f3a5..217f97b8 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -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 { @@ -33,7 +38,8 @@ bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } std::unique_ptr SettingWatchFace::CreateScreen1() { - std::array watchfaces {"Digital face", "Analog face", "PineTimeStyle", "Terminal"}; + std::array watchfaces { + {{"Digital face", true}, {"Analog face", true}, {"PineTimeStyle", true}, {"Terminal", true}}}; return std::make_unique( 0, 2, @@ -49,7 +55,11 @@ std::unique_ptr SettingWatchFace::CreateScreen1() { } std::unique_ptr SettingWatchFace::CreateScreen2() { - std::array watchfaces {"Infineat face", "Casio G7710", "", ""}; + std::array watchfaces { + {{"Infineat face", Applications::Screens::WatchFaceInfineat::IsAvailable(filesystem)}, + {"Casio G7710", Applications::Screens::WatchFaceCasioStyleG7710::IsAvailable(filesystem)}, + {"", false}, + {"", false}}}; return std::make_unique( 1, 2, diff --git a/src/displayapp/screens/settings/SettingWatchFace.h b/src/displayapp/screens/settings/SettingWatchFace.h index 7d14554e..158397f8 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.h +++ b/src/displayapp/screens/settings/SettingWatchFace.h @@ -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";