Skip to content

Commit 0aead42

Browse files
authored
navigation: Add is available (#1847)
Navigation app now needs 2 images to be loaded from the resources on the external filesystem. This PR adds an 'enabled' field to the Applications struct. This field is true for all applications expect for Navigation which calls Navigation::IsAvailable(). This methods returns true if the 2 files are available in the resources. The application list disables the application (draws it in grey, disables the touch callback) if the enable flag is not set.
1 parent 44d1798 commit 0aead42

File tree

7 files changed

+42
-20
lines changed

7 files changed

+42
-20
lines changed

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
404404
switch (app) {
405405
case Apps::Launcher:
406406
currentScreen =
407-
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController);
407+
std::make_unique<Screens::ApplicationList>(this, settingsController, batteryController, bleController, dateTimeController, filesystem);
408408
break;
409409
case Apps::Motion:
410410
// currentScreen = std::make_unique<Screens::Motion>(motionController);

src/displayapp/screens/ApplicationList.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
using namespace Pinetime::Applications::Screens;
88

9-
constexpr std::array<Tile::Applications, ApplicationList::applications.size()> ApplicationList::applications;
10-
119
auto ApplicationList::CreateScreenList() const {
1210
std::array<std::function<std::unique_ptr<Screen>()>, nScreens> screens;
1311
for (size_t i = 0; i < screens.size(); i++) {
@@ -22,12 +20,14 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
2220
Pinetime::Controllers::Settings& settingsController,
2321
const Pinetime::Controllers::Battery& batteryController,
2422
const Pinetime::Controllers::Ble& bleController,
25-
Controllers::DateTime& dateTimeController)
23+
Controllers::DateTime& dateTimeController,
24+
Pinetime::Controllers::FS& filesystem)
2625
: app {app},
2726
settingsController {settingsController},
2827
batteryController {batteryController},
2928
bleController {bleController},
3029
dateTimeController {dateTimeController},
30+
filesystem{filesystem},
3131
screens {app, settingsController.GetAppMenu(), CreateScreenList(), Screens::ScreenListModes::UpDown} {
3232
}
3333

src/displayapp/screens/ApplicationList.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "components/battery/BatteryController.h"
1111
#include "displayapp/screens/Symbols.h"
1212
#include "displayapp/screens/Tile.h"
13+
#include "displayapp/screens/Navigation.h"
1314

1415
namespace Pinetime {
1516
namespace Applications {
@@ -20,7 +21,8 @@ namespace Pinetime {
2021
Pinetime::Controllers::Settings& settingsController,
2122
const Pinetime::Controllers::Battery& batteryController,
2223
const Pinetime::Controllers::Ble& bleController,
23-
Controllers::DateTime& dateTimeController);
24+
Controllers::DateTime& dateTimeController,
25+
Pinetime::Controllers::FS& filesystem);
2426
~ApplicationList() override;
2527
bool OnTouchEvent(TouchEvents event) override;
2628

@@ -33,26 +35,27 @@ namespace Pinetime {
3335
const Pinetime::Controllers::Battery& batteryController;
3436
const Pinetime::Controllers::Ble& bleController;
3537
Controllers::DateTime& dateTimeController;
38+
Pinetime::Controllers::FS& filesystem;
3639

3740
static constexpr int appsPerScreen = 6;
3841

3942
// Increment this when more space is needed
4043
static constexpr int nScreens = 2;
4144

42-
static constexpr std::array<Tile::Applications, appsPerScreen * nScreens> applications {{
43-
{Symbols::stopWatch, Apps::StopWatch},
44-
{Symbols::clock, Apps::Alarm},
45-
{Symbols::hourGlass, Apps::Timer},
46-
{Symbols::shoe, Apps::Steps},
47-
{Symbols::heartBeat, Apps::HeartRate},
48-
{Symbols::music, Apps::Music},
49-
50-
{Symbols::paintbrush, Apps::Paint},
51-
{Symbols::paddle, Apps::Paddle},
52-
{"2", Apps::Twos},
53-
{Symbols::drum, Apps::Metronome},
54-
{Symbols::map, Apps::Navigation},
55-
{Symbols::none, Apps::None},
45+
std::array<Tile::Applications, appsPerScreen * nScreens> applications {{
46+
{Symbols::stopWatch, Apps::StopWatch, true},
47+
{Symbols::clock, Apps::Alarm, true},
48+
{Symbols::hourGlass, Apps::Timer, true},
49+
{Symbols::shoe, Apps::Steps, true},
50+
{Symbols::heartBeat, Apps::HeartRate, true},
51+
{Symbols::music, Apps::Music, true},
52+
53+
{Symbols::paintbrush, Apps::Paint, true},
54+
{Symbols::paddle, Apps::Paddle, true},
55+
{"2", Apps::Twos, true},
56+
{Symbols::drum, Apps::Metronome, true},
57+
{Symbols::map, Apps::Navigation, Applications::Screens::Navigation::IsAvailable(filesystem)},
58+
{Symbols::none, Apps::None, false},
5659

5760
// {"M", Apps::Motion},
5861
}};

src/displayapp/screens/Navigation.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,3 +265,19 @@ void Navigation::Refresh() {
265265
}
266266
}
267267
}
268+
269+
bool Navigation::IsAvailable(Pinetime::Controllers::FS& filesystem) {
270+
lfs_file file = {};
271+
272+
if (filesystem.FileOpen(&file, "/images/navigation0.bin", LFS_O_RDONLY) < 0) {
273+
return false;
274+
}
275+
filesystem.FileClose(&file);
276+
277+
if (filesystem.FileOpen(&file, "/images/navigation1.bin", LFS_O_RDONLY) < 0) {
278+
return false;
279+
}
280+
filesystem.FileClose(&file);
281+
282+
return true;
283+
}

src/displayapp/screens/Navigation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
namespace Pinetime {
2727
namespace Controllers {
2828
class NavigationService;
29+
class FS;
2930
}
3031

3132
namespace Applications {
@@ -36,6 +37,7 @@ namespace Pinetime {
3637
~Navigation() override;
3738

3839
void Refresh() override;
40+
static bool IsAvailable(Pinetime::Controllers::FS& filesystem);
3941

4042
private:
4143
lv_obj_t* imgFlag;

src/displayapp/screens/Tile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Tile::Tile(uint8_t screenID,
7676

7777
for (uint8_t i = 0; i < 6; i++) {
7878
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_CLICK_TRIG);
79-
if (applications[i].application == Apps::None) {
79+
if (applications[i].application == Apps::None || !applications[i].enabled) {
8080
lv_btnmatrix_set_btn_ctrl(btnm1, i, LV_BTNMATRIX_CTRL_DISABLED);
8181
}
8282
}

src/displayapp/screens/Tile.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ namespace Pinetime {
1919
struct Applications {
2020
const char* icon;
2121
Pinetime::Applications::Apps application;
22+
bool enabled;
2223
};
2324

2425
explicit Tile(uint8_t screenID,

0 commit comments

Comments
 (0)