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

Added 12 hour set time interface #907

Merged
merged 9 commits into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 1 addition & 1 deletion src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingSetTime:
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController);
currentScreen = std::make_unique<Screens::SettingSetTime>(this, dateTimeController, settingsController);
ReturnApp(Apps::Settings, FullRefreshDirections::Down, TouchEvents::SwipeDown);
break;
case Apps::SettingChimes:
Expand Down
50 changes: 32 additions & 18 deletions src/displayapp/screens/settings/SettingSetTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <nrf_log.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Symbols.h"
#include "components/settings/Settings.h"

using namespace Pinetime::Applications::Screens;

Expand All @@ -16,23 +17,24 @@ namespace {
constexpr int16_t POS_Y_MINUS = 40;
constexpr int16_t OFS_Y_COLON = -2;

void event_handler(lv_obj_t * obj, lv_event_t event) {
auto* screen = static_cast<SettingSetTime *>(obj->user_data);
void event_handler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<SettingSetTime*>(obj->user_data);
screen->HandleButtonPress(obj, event);
}
}

SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime::Controllers::DateTime &dateTimeController) :
Screen(app),
dateTimeController {dateTimeController} {
lv_obj_t * title = lv_label_create(lv_scr_act(), nullptr);
SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp* app,
Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Settings& settingsController)
: Screen(app), dateTimeController {dateTimeController}, settingsController {settingsController} {
lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text_static(title, "Set current time");
lv_label_set_align(title, LV_LABEL_ALIGN_CENTER);
lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15);

lv_obj_t * icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);

lv_label_set_text_static(icon, Symbols::clock);
lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER);
lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0);
Expand All @@ -45,7 +47,7 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime
lv_obj_align(lblHours, lv_scr_act(), LV_ALIGN_CENTER, POS_X_HOURS, POS_Y_TEXT);
lv_obj_set_auto_realign(lblHours, true);

lv_obj_t * lblColon1 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_t* lblColon1 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblColon1, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_static(lblColon1, ":");
lv_label_set_align(lblColon1, LV_LABEL_ALIGN_CENTER);
Expand All @@ -59,18 +61,24 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime
lv_obj_align(lblMinutes, lv_scr_act(), LV_ALIGN_CENTER, POS_X_MINUTES, POS_Y_TEXT);
lv_obj_set_auto_realign(lblMinutes, true);

lv_obj_t * lblColon2 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_t* lblColon2 = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblColon2, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_static(lblColon2, ":");
lv_label_set_align(lblColon2, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lblColon2, lv_scr_act(), LV_ALIGN_CENTER, (POS_X_MINUTES + POS_X_SECONDS) / 2, POS_Y_TEXT + OFS_Y_COLON);

lv_obj_t * lblSeconds = lv_label_create(lv_scr_act(), nullptr);
lv_obj_t* lblSeconds = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblSeconds, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42);
lv_label_set_text_static(lblSeconds, "00");
lv_label_set_align(lblSeconds, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lblSeconds, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_TEXT);

lblampm = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
lv_label_set_text_static(lblampm, " ");
lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, POS_X_SECONDS, POS_Y_PLUS);

btnHoursPlus = lv_btn_create(lv_scr_act(), nullptr);
btnHoursPlus->user_data = this;
lv_obj_set_size(btnHoursPlus, 50, 40);
Expand Down Expand Up @@ -105,38 +113,44 @@ SettingSetTime::SettingSetTime(Pinetime::Applications::DisplayApp *app, Pinetime
lv_obj_align(btnSetTime, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_style_local_value_str(btnSetTime, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, "Set");
lv_obj_set_event_cb(btnSetTime, event_handler);

setHourLabels(hoursValue);
}

SettingSetTime::~SettingSetTime() {
lv_obj_clean(lv_scr_act());
}

void SettingSetTime::HandleButtonPress(lv_obj_t *object, lv_event_t event) {
void SettingSetTime::HandleButtonPress(lv_obj_t* object, lv_event_t event) {
if (event != LV_EVENT_CLICKED)
return;

if (object == btnHoursPlus) {
hoursValue++;
if (hoursValue > 23)
if (hoursValue > 23) {
hoursValue = 0;
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
}
setHourLabels(hoursValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnHoursMinus) {
hoursValue--;
if (hoursValue < 0)
if (hoursValue < 0) {
hoursValue = 23;
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
}
setHourLabels(hoursValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnMinutesPlus) {
minutesValue++;
if (minutesValue > 59)
if (minutesValue > 59) {
minutesValue = 0;
}
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnMinutesMinus) {
minutesValue--;
if (minutesValue < 0)
if (minutesValue < 0) {
minutesValue = 59;
}
lv_label_set_text_fmt(lblMinutes, "%02d", minutesValue);
lv_btn_set_state(btnSetTime, LV_BTN_STATE_RELEASED);
} else if (object == btnSetTime) {
Expand Down
64 changes: 47 additions & 17 deletions src/displayapp/screens/settings/SettingSetTime.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,60 @@
#include <cstdint>
#include <lvgl/lvgl.h>
#include "components/datetime/DateTimeController.h"
#include "components/settings/Settings.h"
#include "displayapp/screens/Screen.h"

namespace Pinetime {
namespace Applications {
namespace Screens {
class SettingSetTime : public Screen{
public:
SettingSetTime(DisplayApp* app, Pinetime::Controllers::DateTime &dateTimeController);
~SettingSetTime() override;
class SettingSetTime : public Screen {
public:
SettingSetTime(DisplayApp* app,
Pinetime::Controllers::DateTime& dateTimeController,
Pinetime::Controllers::Settings& settingsController);
~SettingSetTime() override;

void HandleButtonPress(lv_obj_t *object, lv_event_t event);

private:
Controllers::DateTime& dateTimeController;
void HandleButtonPress(lv_obj_t* object, lv_event_t event);

int hoursValue;
int minutesValue;
lv_obj_t * lblHours;
lv_obj_t * lblMinutes;
lv_obj_t * btnHoursPlus;
lv_obj_t * btnHoursMinus;
lv_obj_t * btnMinutesPlus;
lv_obj_t * btnMinutesMinus;
lv_obj_t * btnSetTime;
private:
Controllers::DateTime& dateTimeController;
Controllers::Settings& settingsController;

int hoursValue;
int minutesValue;
lv_obj_t* lblHours;
lv_obj_t* lblMinutes;
lv_obj_t* lblampm;
lv_obj_t* btnHoursPlus;
lv_obj_t* btnHoursMinus;
lv_obj_t* btnMinutesPlus;
lv_obj_t* btnMinutesMinus;
lv_obj_t* btnSetTime;

void setHourLabels(int time24H) {
switch (time24H) {
if (settingsController.GetClockType() == Controllers::Settings::ClockType::H12) {
case 0:
lv_label_set_text_static(lblHours, "12");
lv_label_set_text_static(lblampm, "AM");
break;
case 1 ... 11:
lv_label_set_text_fmt(lblHours, "%02d", time24H);
lv_label_set_text_static(lblampm, "AM");
break;
case 12:
lv_label_set_text_static(lblHours, "12");
lv_label_set_text_static(lblampm, "PM");
break;
case 13 ... 23:
lv_label_set_text_fmt(lblHours, "%02d", time24H - 12);
lv_label_set_text_static(lblampm, "PM");
break;
} else {
lv_label_set_text_fmt(lblHours, "%02d", hoursValue);
}
}
}
Riksu9000 marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
Expand Down