|
| 1 | +#include "displayapp/screens/settings/SettingActivity.h" |
| 2 | + |
| 3 | +#include <cstdint> |
| 4 | +#include <cinttypes> |
| 5 | + |
| 6 | +#include "displayapp/DisplayApp.h" |
| 7 | +#include "displayapp/screens/Symbols.h" |
| 8 | + |
| 9 | +using namespace Pinetime::Applications::Screens; |
| 10 | + |
| 11 | +namespace { |
| 12 | + void EventHandler(lv_obj_t* obj, lv_event_t event) { |
| 13 | + SettingActivity* screen = static_cast<SettingActivity*>(obj->user_data); |
| 14 | + screen->UpdateSelected(obj, event); |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +SettingActivity::SettingActivity(Controllers::Settings& settingsController) : settingsController {settingsController} { |
| 19 | + lv_obj_t* container = lv_cont_create(lv_scr_act(), nullptr); |
| 20 | + |
| 21 | + lv_obj_set_style_local_bg_opa(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_OPA_TRANSP); |
| 22 | + lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); |
| 23 | + lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); |
| 24 | + lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); |
| 25 | + lv_obj_set_pos(container, 30, 60); |
| 26 | + lv_obj_set_width(container, LV_HOR_RES - 50); |
| 27 | + lv_obj_set_height(container, LV_VER_RES - 60); |
| 28 | + lv_cont_set_layout(container, LV_LAYOUT_COLUMN_LEFT); |
| 29 | + |
| 30 | + lv_obj_t* title = lv_label_create(lv_scr_act(), nullptr); |
| 31 | + lv_label_set_text_static(title, "Activity notifications"); |
| 32 | + lv_label_set_align(title, LV_LABEL_ALIGN_CENTER); |
| 33 | + lv_obj_align(title, lv_scr_act(), LV_ALIGN_IN_TOP_MID, 15, 15); |
| 34 | + |
| 35 | + lv_obj_t* icon = lv_label_create(lv_scr_act(), nullptr); |
| 36 | + lv_obj_set_style_local_text_color(icon, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE); |
| 37 | + |
| 38 | + lv_label_set_text_static(icon, Symbols::shoe); |
| 39 | + lv_label_set_align(icon, LV_LABEL_ALIGN_CENTER); |
| 40 | + lv_obj_align(icon, title, LV_ALIGN_OUT_LEFT_MID, -10, 0); |
| 41 | + |
| 42 | + enabled = lv_checkbox_create(container, nullptr); |
| 43 | + lv_checkbox_set_text(enabled, "Enabled"); |
| 44 | + if (settingsController.GetActivity() == Controllers::Settings::Activity::On) { |
| 45 | + lv_checkbox_set_checked(enabled, true); |
| 46 | + } |
| 47 | + enabled->user_data = this; |
| 48 | + lv_obj_set_event_cb(enabled, EventHandler); |
| 49 | + |
| 50 | + stepValue = lv_label_create(lv_scr_act(), nullptr); |
| 51 | + lv_obj_set_style_local_text_font(stepValue, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_42); |
| 52 | + lv_label_set_text_fmt(stepValue, "%" PRIu32, settingsController.GetActivityThresh()); |
| 53 | + lv_label_set_align(stepValue, LV_LABEL_ALIGN_CENTER); |
| 54 | + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20); |
| 55 | + |
| 56 | + btnPlus = lv_btn_create(lv_scr_act(), nullptr); |
| 57 | + btnPlus->user_data = this; |
| 58 | + lv_obj_set_size(btnPlus, 80, 50); |
| 59 | + lv_obj_align(btnPlus, lv_scr_act(), LV_ALIGN_CENTER, 55, 80); |
| 60 | + lv_obj_t* lblPlus = lv_label_create(btnPlus, nullptr); |
| 61 | + lv_label_set_text_static(lblPlus, "+"); |
| 62 | + lv_obj_set_event_cb(btnPlus, EventHandler); |
| 63 | + |
| 64 | + btnMinus = lv_btn_create(lv_scr_act(), nullptr); |
| 65 | + btnMinus->user_data = this; |
| 66 | + lv_obj_set_size(btnMinus, 80, 50); |
| 67 | + lv_obj_set_event_cb(btnMinus, EventHandler); |
| 68 | + lv_obj_align(btnMinus, lv_scr_act(), LV_ALIGN_CENTER, -55, 80); |
| 69 | + lv_obj_t* lblMinus = lv_label_create(btnMinus, nullptr); |
| 70 | + lv_label_set_text_static(lblMinus, "-"); |
| 71 | +} |
| 72 | + |
| 73 | +SettingActivity::~SettingActivity() { |
| 74 | + lv_obj_clean(lv_scr_act()); |
| 75 | + settingsController.SaveSettings(); |
| 76 | +} |
| 77 | + |
| 78 | +void SettingActivity::UpdateSelected(lv_obj_t* object, lv_event_t event) { |
| 79 | + uint16_t value = settingsController.GetActivityThresh(); |
| 80 | + if (object == btnPlus && event == LV_EVENT_PRESSED) { |
| 81 | + value += 1; |
| 82 | + if (value <= 15000) { |
| 83 | + settingsController.SetActivityThresh(value); |
| 84 | + lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh()); |
| 85 | + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20); |
| 86 | + } |
| 87 | + } |
| 88 | + |
| 89 | + if (object == btnMinus && event == LV_EVENT_PRESSED) { |
| 90 | + value -= 1; |
| 91 | + if (value >= 1) { |
| 92 | + settingsController.SetActivityThresh(value); |
| 93 | + lv_label_set_text_fmt(stepValue, "%" PRIu16, settingsController.GetActivityThresh()); |
| 94 | + lv_obj_align(stepValue, lv_scr_act(), LV_ALIGN_CENTER, 0, 20); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + if (object == enabled && event == LV_EVENT_VALUE_CHANGED) { |
| 99 | + bool currentState = settingsController.GetActivity() == Controllers::Settings::Activity::On; |
| 100 | + settingsController.SetActivity(currentState ? Controllers::Settings::Activity::Off : Controllers::Settings::Activity::On); |
| 101 | + lv_checkbox_set_checked(enabled, !currentState); |
| 102 | + } |
| 103 | +} |
0 commit comments