Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings: Add double click action settings #1821

Closed
wants to merge 1 commit into from
Closed
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 @@ -417,6 +417,7 @@ list(APPEND SOURCE_FILES
displayapp/screens/settings/SettingChimes.cpp
displayapp/screens/settings/SettingShakeThreshold.cpp
displayapp/screens/settings/SettingBluetooth.cpp
displayapp/screens/settings/SettingDoubleClick.cpp

## Watch faces
displayapp/screens/WatchFaceAnalog.cpp
Expand Down
12 changes: 12 additions & 0 deletions src/components/settings/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Pinetime {
enum class Notification : uint8_t { On, Off, Sleep };
enum class ChimesOption : uint8_t { None, Hours, HalfHours };
enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
enum class DoubleClickAction : uint8_t { GoToNotifications, AudioNext };
enum class Colors : uint8_t {
White,
Silver,
Expand Down Expand Up @@ -249,6 +250,16 @@ namespace Pinetime {
return settings.wakeUpMode;
}

void SetDoubleClickAction(DoubleClickAction action) {
if (settings.doubleClickAction != action)
settingsChanged = true;
settings.doubleClickAction = action;
}

DoubleClickAction GetDoubleClickAction() {
return settings.doubleClickAction;
}

bool isWakeUpModeOn(const WakeUpMode mode) const {
return getWakeUpModes()[static_cast<size_t>(mode)];
}
Expand Down Expand Up @@ -308,6 +319,7 @@ namespace Pinetime {
uint16_t shakeWakeThreshold = 150;

Controllers::BrightnessController::Levels brightLevel = Controllers::BrightnessController::Levels::Medium;
DoubleClickAction doubleClickAction;
};

SettingsData settings;
Expand Down
22 changes: 19 additions & 3 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "components/ble/BleController.h"
#include "components/datetime/DateTimeController.h"
#include "components/ble/NotificationManager.h"
#include "components/ble/MusicService.h"
#include "components/motion/MotionController.h"
#include "components/motor/MotorController.h"
#include "displayapp/screens/ApplicationList.h"
Expand Down Expand Up @@ -48,6 +49,7 @@
#include "displayapp/screens/settings/SettingChimes.h"
#include "displayapp/screens/settings/SettingShakeThreshold.h"
#include "displayapp/screens/settings/SettingBluetooth.h"
#include "displayapp/screens/settings/SettingDoubleClick.h"

#include "libs/lv_conf.h"
#include "UserApps.h"
Expand Down Expand Up @@ -360,9 +362,7 @@ void DisplayApp::Refresh() {
LoadNewScreen(Apps::SysInfo, DisplayApp::FullRefreshDirections::Up);
break;
case Messages::ButtonDoubleClicked:
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
}
HandleDoubleClick();
break;

case Messages::BleFirmwareUpdateStarted:
Expand Down Expand Up @@ -507,6 +507,9 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
case Apps::SettingWakeUp:
currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);
break;
case Apps::SettingDoubleClick:
currentScreen = std::make_unique<Screens::SettingDoubleClick>(settingsController);
break;
case Apps::SettingDisplay:
currentScreen = std::make_unique<Screens::SettingDisplay>(this, settingsController);
break;
Expand Down Expand Up @@ -632,3 +635,16 @@ void DisplayApp::ApplyBrightness() {
}
brightnessController.Set(brightness);
}

void DisplayApp::HandleDoubleClick() {
switch (settingsController.GetDoubleClickAction()) {
case Controllers::Settings::DoubleClickAction::GoToNotifications:
if (currentApp != Apps::Notifications && currentApp != Apps::NotificationsPreview) {
LoadNewScreen(Apps::Notifications, DisplayApp::FullRefreshDirections::Down);
}
break;
case Controllers::Settings::DoubleClickAction::AudioNext:
systemTask->nimble().music().event(Controllers::MusicService::EVENT_MUSIC_NEXT);
break;
}
}
1 change: 1 addition & 0 deletions src/displayapp/DisplayApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ namespace Pinetime {
DisplayApp::FullRefreshDirections nextDirection;
System::BootErrors bootError;
void ApplyBrightness();
void HandleDoubleClick();

static constexpr size_t returnAppStackSize = 10;
Utility::StaticStack<Apps, returnAppStackSize> returnAppStack;
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 @@ -41,6 +41,7 @@ namespace Pinetime {
SettingChimes,
SettingShakeThreshold,
SettingBluetooth,
SettingDoubleClick,
Error,
Weather
};
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/screens/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ namespace Pinetime {
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* sleep = "\xEE\xBD\x84";
static constexpr const char* angleDoubleRight = "\xEF\x84\x81";

// fontawesome_weathericons.c
// static constexpr const char* sun = "\xEF\x86\x85";
Expand Down
61 changes: 61 additions & 0 deletions src/displayapp/screens/settings/SettingDoubleClick.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "displayapp/screens/settings/SettingDoubleClick.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 {
Pinetime::Controllers::Settings::DoubleClickAction action;
const char* name;
};

constexpr std::array<Option, 2> options = {{
{Pinetime::Controllers::Settings::DoubleClickAction::GoToNotifications, "Notifications"},
{Pinetime::Controllers::Settings::DoubleClickAction::AudioNext, "Audio Next"},
}};

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(Pinetime::Controllers::Settings::DoubleClickAction currentOption) {
for (size_t i = 0; i < options.size(); i++) {
if (options[i].action == currentOption) {
return i;
}
}
return 0;
}
}

SettingDoubleClick::SettingDoubleClick(Pinetime::Controllers::Settings& settingsController)
: checkboxList(
0,
1,
"Double Click",
Symbols::angleDoubleRight,
GetDefaultOption(settingsController.GetDoubleClickAction()),
[&settings = settingsController](uint32_t index) {
settings.SetDoubleClickAction(options[index].action);
settings.SaveSettings();
},
CreateOptionArray()) {
}

SettingDoubleClick::~SettingDoubleClick() {
lv_obj_clean(lv_scr_act());
}
26 changes: 26 additions & 0 deletions src/displayapp/screens/settings/SettingDoubleClick.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 SettingDoubleClick : public Screen {
public:
SettingDoubleClick(Pinetime::Controllers::Settings& settingsController);
~SettingDoubleClick() 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 @@ -34,9 +34,10 @@ namespace Pinetime {
static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
{Symbols::sun, "Display", Apps::SettingDisplay},
{Symbols::eye, "Wake Up", Apps::SettingWakeUp},
{Symbols::angleDoubleRight, "Double Click", Apps::SettingDoubleClick},
{Symbols::clock, "Time format", Apps::SettingTimeFormat},
{Symbols::home, "Watch face", Apps::SettingWatchFace},

{Symbols::home, "Watch face", Apps::SettingWatchFace},
{Symbols::shoe, "Steps", Apps::SettingSteps},
{Symbols::clock, "Date&Time", Apps::SettingSetDateTime},
{Symbols::cloudSunRain, "Weather", Apps::SettingWeatherFormat},
Expand Down
Loading