|
| 1 | +/* Copyright (C) 2024 thnikk, Boteium, JustScott |
| 2 | +
|
| 3 | + This file is part of InfiniTime. |
| 4 | +
|
| 5 | + InfiniTime is free software: you can redistribute it and/or modify |
| 6 | + it under the terms of the GNU General Public License as published |
| 7 | + by the Free Software Foundation, either version 3 of the License, or |
| 8 | + (at your option) any later version. |
| 9 | +
|
| 10 | + InfiniTime is distributed in the hope that it will be useful, |
| 11 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + GNU General Public License for more details. |
| 14 | +
|
| 15 | + You should have received a copy of the GNU General Public License |
| 16 | + along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 17 | +*/ |
| 18 | + |
| 19 | +#include "displayapp/screens/Calendar.h" |
| 20 | +#include "components/datetime/DateTimeController.h" |
| 21 | +#include "displayapp/InfiniTimeTheme.h" |
| 22 | + |
| 23 | +using namespace Pinetime::Applications::Screens; |
| 24 | + |
| 25 | +Calendar::Calendar(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { |
| 26 | + |
| 27 | + // Create calendar object |
| 28 | + calendar = lv_calendar_create(lv_scr_act(), NULL); |
| 29 | + // Set size |
| 30 | + lv_obj_set_size(calendar, LV_HOR_RES, LV_VER_RES); |
| 31 | + // Set alignment |
| 32 | + lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5); |
| 33 | + // Disable clicks |
| 34 | + lv_obj_set_click(calendar, false); |
| 35 | + |
| 36 | + // Set style of today's date |
| 37 | + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, Colors::deepOrange); |
| 38 | + |
| 39 | + // Set style of inactive month's days |
| 40 | + lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, Colors::gray); |
| 41 | + |
| 42 | + // Get today's date |
| 43 | + current.year = static_cast<int>(dateTimeController.Year()); |
| 44 | + current.month = static_cast<int>(dateTimeController.Month()); |
| 45 | + current.day = static_cast<int>(dateTimeController.Day()); |
| 46 | + |
| 47 | + // Set today's date |
| 48 | + lv_calendar_set_today_date(calendar, ¤t); |
| 49 | + lv_calendar_set_showed_date(calendar, ¤t); |
| 50 | +} |
| 51 | + |
| 52 | +bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) { |
| 53 | + switch (event) { |
| 54 | + case TouchEvents::SwipeLeft: { |
| 55 | + if (current.month == 12) { |
| 56 | + current.month = 1; |
| 57 | + current.year++; |
| 58 | + } else { |
| 59 | + current.month++; |
| 60 | + } |
| 61 | + |
| 62 | + lv_calendar_set_showed_date(calendar, ¤t); |
| 63 | + return true; |
| 64 | + } |
| 65 | + case TouchEvents::SwipeRight: { |
| 66 | + if (current.month == 1) { |
| 67 | + current.month = 12; |
| 68 | + current.year--; |
| 69 | + } else { |
| 70 | + current.month--; |
| 71 | + } |
| 72 | + |
| 73 | + lv_calendar_set_showed_date(calendar, ¤t); |
| 74 | + return true; |
| 75 | + } |
| 76 | + /* |
| 77 | + case TouchEvents::SwipeUp: { |
| 78 | + current.year++; |
| 79 | + lv_calendar_set_showed_date(calendar, ¤t); |
| 80 | + return true; |
| 81 | + } |
| 82 | + case TouchEvents::SwipeDown: { |
| 83 | + current.year--; |
| 84 | + lv_calendar_set_showed_date(calendar, ¤t); |
| 85 | + return true; |
| 86 | + } |
| 87 | + */ |
| 88 | + default: { |
| 89 | + return false; |
| 90 | + } |
| 91 | + } |
| 92 | +} |
| 93 | + |
| 94 | +Calendar::~Calendar() { |
| 95 | + lv_obj_clean(lv_scr_act()); |
| 96 | +} |
0 commit comments