Skip to content

Commit 1340650

Browse files
JustScottthnikkBoteium
committed
Add a new Calendar App
A basic calendar app that shows all the days dates in the current month along with the correlating week days, highlights the current day, and allows swiping left and right to increase and decrease the current month by one. Co-authored-by: thnikk <thnikk@users.noreply.github.com> Co-authored-by: Boteium <boteium@users.noreply.github.com>
1 parent ad73e1b commit 1340650

8 files changed

Lines changed: 161 additions & 1 deletion

File tree

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ list(APPEND SOURCE_FILES
377377
displayapp/screens/FirmwareUpdate.cpp
378378
displayapp/screens/Music.cpp
379379
displayapp/screens/Navigation.cpp
380+
displayapp/screens/Calendar.cpp
380381
displayapp/screens/Metronome.cpp
381382
displayapp/screens/Motion.cpp
382383
displayapp/screens/Weather.cpp

src/displayapp/DisplayApp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "displayapp/screens/Metronome.h"
2020
#include "displayapp/screens/Music.h"
2121
#include "displayapp/screens/Navigation.h"
22+
#include "displayapp/screens/Calendar.h"
2223
#include "displayapp/screens/Notifications.h"
2324
#include "displayapp/screens/SystemInfo.h"
2425
#include "displayapp/screens/Tile.h"

src/displayapp/apps/Apps.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Pinetime {
2323
Twos,
2424
HeartRate,
2525
Navigation,
26+
Calendar,
2627
StopWatch,
2728
Metronome,
2829
Motion,

src/displayapp/apps/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ else ()
1515
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Navigation")
1616
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Calculator")
1717
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Weather")
18+
set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Calendar")
1819
#set(DEFAULT_USER_APP_TYPES "${DEFAULT_USER_APP_TYPES}, Apps::Motion")
1920
set(USERAPP_TYPES "${DEFAULT_USER_APP_TYPES}" CACHE STRING "List of user apps to build into the firmware")
2021
endif ()

src/displayapp/fonts/fonts.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
{
99
"file": "FontAwesome5-Solid+Brands+Regular.woff",
10-
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf1ec, 0xf55a, 0xf3ed"
10+
"range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf0f3, 0xf522, 0xf743, 0xf1ec, 0xf55a, 0xf3ed, 0xf073"
1111
}
1212
],
1313
"bpp": 1,
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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, &current);
49+
lv_calendar_set_showed_date(calendar, &current);
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, &current);
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, &current);
74+
return true;
75+
}
76+
/*
77+
case TouchEvents::SwipeUp: {
78+
current.year++;
79+
lv_calendar_set_showed_date(calendar, &current);
80+
return true;
81+
}
82+
case TouchEvents::SwipeDown: {
83+
current.year--;
84+
lv_calendar_set_showed_date(calendar, &current);
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+
}

src/displayapp/screens/Calendar.h

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
#pragma once
20+
21+
#include "displayapp/apps/Apps.h"
22+
#include "displayapp/Controllers.h"
23+
#include "displayapp/screens/Screen.h"
24+
#include "components/datetime/DateTimeController.h"
25+
#include <lvgl/lvgl.h>
26+
27+
#include "Symbols.h"
28+
29+
namespace Pinetime {
30+
namespace Controllers {
31+
class Settings;
32+
}
33+
34+
namespace Applications {
35+
namespace Screens {
36+
class Calendar : public Screen {
37+
public:
38+
Calendar(Controllers::DateTime& dateTimeController);
39+
~Calendar() override;
40+
41+
private:
42+
bool OnTouchEvent(TouchEvents event);
43+
Controllers::DateTime& dateTimeController;
44+
lv_obj_t* calendar;
45+
lv_calendar_date_t current;
46+
};
47+
}
48+
49+
template <>
50+
struct AppTraits<Apps::Calendar> {
51+
static constexpr Apps app = Apps::Calendar;
52+
static constexpr const char* icon = Screens::Symbols::calendar;
53+
54+
static Screens::Screen* Create(AppControllers& controllers) {
55+
return new Screens::Calendar(controllers.dateTimeController);
56+
};
57+
};
58+
}
59+
}

src/displayapp/screens/Symbols.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ namespace Pinetime {
4242
static constexpr const char* sleep = "\xEE\xBD\x84";
4343
static constexpr const char* calculator = "\xEF\x87\xAC";
4444
static constexpr const char* backspace = "\xEF\x95\x9A";
45+
static constexpr const char* calendar = "\xEF\x81\xB3";
4546

4647
// fontawesome_weathericons.c
4748
// static constexpr const char* sun = "\xEF\x86\x85";

0 commit comments

Comments
 (0)