Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/Settings.cpp
displayapp/screens/settings/SettingWatchFace.cpp
displayapp/screens/settings/SettingTimeFormat.cpp
displayapp/screens/settings/SettingNotificationTimeout.cpp
displayapp/screens/settings/SettingWeatherFormat.cpp
displayapp/screens/settings/SettingWakeUp.cpp
displayapp/screens/settings/SettingDisplay.cpp
Expand Down
14 changes: 13 additions & 1 deletion src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,17 @@ namespace Pinetime {
return settings.clockType;
};

void SetNotificationTimeout(uint32_t notificationTimeout) {
if (notificationTimeout != settings.notificationTimeout) {
settingsChanged = true;
}
settings.notificationTimeout = notificationTimeout;
};

uint32_t GetNotificationTimeout() const {
return settings.notificationTimeout;
};

void SetWeatherFormat(WeatherFormat weatherFormat) {
if (weatherFormat != settings.weatherFormat) {
settingsChanged = true;
Expand Down Expand Up @@ -354,12 +365,13 @@ namespace Pinetime {
private:
Pinetime::Controllers::FS& fs;

static constexpr uint32_t settingsVersion = 0x000a;
static constexpr uint32_t settingsVersion = 0x000b;

struct SettingsData {
uint32_t version = settingsVersion;
uint32_t stepsGoal = 10000;
uint32_t screenTimeOut = 15000;
uint32_t notificationTimeout = 7000;

bool alwaysOnDisplay = false;

Expand Down
6 changes: 6 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "displayapp/screens/settings/Settings.h"
#include "displayapp/screens/settings/SettingWatchFace.h"
#include "displayapp/screens/settings/SettingTimeFormat.h"
#include "displayapp/screens/settings/SettingNotificationTimeout.h"
#include "displayapp/screens/settings/SettingWeatherFormat.h"
#include "displayapp/screens/settings/SettingWakeUp.h"
#include "displayapp/screens/settings/SettingDisplay.h"
Expand Down Expand Up @@ -568,6 +569,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
settingsController,
*systemTask,
Screens::Notifications::Modes::Normal);
break;
Expand All @@ -576,6 +578,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
settingsController,
*systemTask,
Screens::Notifications::Modes::Preview);
break;
Expand All @@ -601,6 +604,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
});
currentScreen = std::make_unique<Screens::SettingWatchFace>(this, std::move(items), settingsController, filesystem);
} break;
case Apps::SettingNotificationTimeout:
currentScreen = std::make_unique<Screens::SettingNotificationTimeout>(settingsController);
break;
case Apps::SettingTimeFormat:
currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
break;
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/apps/Apps.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Pinetime {
Settings,
SettingWatchFace,
SettingTimeFormat,
SettingNotificationTimeout,
SettingWeatherFormat,
SettingHeartRate,
SettingDisplay,
Expand Down
27 changes: 18 additions & 9 deletions src/displayapp/screens/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ Notifications::Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
System::SystemTask& systemTask,
Modes mode)
: app {app},
notificationManager {notificationManager},
alertNotificationService {alertNotificationService},
motorController {motorController},
settingsController {settingsController},
wakeLock(systemTask),
mode {mode} {

Expand All @@ -33,10 +35,11 @@ Notifications::Notifications(DisplayApp* app,
notification.category,
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
motorController,
settingsController);
validDisplay = true;
} else {
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController);
currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController, settingsController);
validDisplay = false;
}
if (mode == Modes::Preview) {
Expand Down Expand Up @@ -109,7 +112,8 @@ void Notifications::Refresh() {
notification.category,
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
motorController,
settingsController);
} else {
running = false;
}
Expand Down Expand Up @@ -202,7 +206,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
previousNotification.category,
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
motorController,
settingsController);
}
return true;
case Pinetime::Applications::TouchEvents::SwipeUp: {
Expand All @@ -229,7 +234,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
nextNotification.category,
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
motorController,
settingsController);
}
return true;
default:
Expand All @@ -245,14 +251,16 @@ namespace {
}

Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController)
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController)
: NotificationItem("Notifications",
"No notifications to display",
0,
Controllers::NotificationManager::Categories::Unknown,
0,
alertNotificationService,
motorController) {
motorController,
settingsController) {
}

Notifications::NotificationItem::NotificationItem(const char* title,
Expand All @@ -261,8 +269,9 @@ Notifications::NotificationItem::NotificationItem(const char* title,
Controllers::NotificationManager::Categories category,
uint8_t notifNb,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController)
: alertNotificationService {alertNotificationService}, motorController {motorController} {
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController)
: alertNotificationService {alertNotificationService}, motorController {motorController}, settingsController {settingsController} {
container = lv_cont_create(lv_scr_act(), nullptr);
lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES);
lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
Expand Down
12 changes: 9 additions & 3 deletions src/displayapp/screens/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "displayapp/screens/Screen.h"
#include "components/ble/NotificationManager.h"
#include "components/motor/MotorController.h"
#include "components/settings/Settings.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"

Expand All @@ -25,6 +26,7 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController,
System::SystemTask& systemTask,
Modes mode);
~Notifications() override;
Expand All @@ -38,14 +40,16 @@ namespace Pinetime {
class NotificationItem {
public:
NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController);
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController);
NotificationItem(const char* title,
const char* msg,
uint8_t notifNr,
Controllers::NotificationManager::Categories,
uint8_t notifNb,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController);
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::Settings& settingsController);
~NotificationItem();

bool IsRunning() const {
Expand All @@ -65,6 +69,7 @@ namespace Pinetime {
lv_obj_t* label_reject;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::Settings& settingsController;

bool running = true;
};
Expand All @@ -74,6 +79,7 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::Settings& settingsController;
System::WakeLock wakeLock;
Modes mode = Modes::Normal;
std::unique_ptr<NotificationItem> currentItem;
Expand All @@ -85,7 +91,7 @@ namespace Pinetime {
lv_obj_t* timeoutLine = nullptr;
TickType_t timeoutTickCountStart;

static const TickType_t timeoutLength = pdMS_TO_TICKS(7000);
const TickType_t timeoutLength = pdMS_TO_TICKS(settingsController.GetNotificationTimeout());
bool interacted = true;

bool dismissingNotification = false;
Expand Down
62 changes: 62 additions & 0 deletions src/displayapp/screens/settings/SettingNotificationTimeout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "displayapp/screens/settings/SettingNotificationTimeout.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Styles.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"

using namespace Pinetime::Applications::Screens;

namespace {
struct Option {
uint32_t notificationTimeout;
const char* name;
};

constexpr std::array<Option, 3> options = {{
{7000, "7s"},
{15000, "15s"},
{30000, "30s"},
}};

std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
if (i >= options.size()) {
optionArray[i].name = "";
optionArray[i].enabled = false;
} else {
optionArray[i].name = options[i].name;
optionArray[i].enabled = true;
}
}
return optionArray;
}

uint32_t GetDefaultOption(uint32_t currentOption) {
for (size_t i = 0; i < options.size(); i++) {
if (options[i].notificationTimeout == currentOption) {
return i;
}
}
return 0;
}
}

SettingNotificationTimeout::SettingNotificationTimeout(Pinetime::Controllers::Settings& settingsController)
: checkboxList(
0,
1,
"Notification\nTimeout",
Symbols::bell,
GetDefaultOption(settingsController.GetNotificationTimeout()),
[&settings = settingsController](uint32_t index) {
settings.SetNotificationTimeout(options[index].notificationTimeout);
settings.SaveSettings();
},
CreateOptionArray()) {
}

SettingNotificationTimeout::~SettingNotificationTimeout() {
lv_obj_clean(lv_scr_act());
}
26 changes: 26 additions & 0 deletions src/displayapp/screens/settings/SettingNotificationTimeout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

#include <array>
#include <cstdint>
#include <lvgl/lvgl.h>

#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/CheckboxList.h"

namespace Pinetime {

namespace Applications {
namespace Screens {

class SettingNotificationTimeout : public Screen {
public:
SettingNotificationTimeout(Pinetime::Controllers::Settings& settingsController);
~SettingNotificationTimeout() override;

private:
CheckboxList checkboxList;
};
}
}
}
3 changes: 2 additions & 1 deletion src/displayapp/screens/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ namespace Pinetime {

{Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
{Symbols::clock, "Chimes", Apps::SettingChimes},
{Symbols::bell, "Notifications", Apps::SettingNotificationTimeout},
{Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
{Symbols::check, "Firmware", Apps::FirmwareValidation},

{Symbols::check, "Firmware", Apps::FirmwareValidation},
{Symbols::shieldAlt, "Over-the-air", Apps::SettingOTA},
{Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
{Symbols::list, "About", Apps::SysInfo},
Expand Down
Loading