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

Calendar app #923

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
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/FirmwareUpdate.cpp
displayapp/screens/Music.cpp
displayapp/screens/Weather.cpp
displayapp/screens/Calendar.cpp
displayapp/screens/Navigation.cpp
displayapp/screens/Metronome.cpp
displayapp/screens/Motion.cpp
Expand Down
1 change: 1 addition & 0 deletions src/displayapp/Apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ namespace Pinetime {
FlashLight,
BatteryInfo,
Music,
Calendar,
Paint,
Paddle,
Twos,
Expand Down
4 changes: 4 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "displayapp/screens/Meter.h"
#include "displayapp/screens/Metronome.h"
#include "displayapp/screens/Music.h"
#include "displayapp/screens/Calendar.h"
#include "displayapp/screens/Navigation.h"
#include "displayapp/screens/Notifications.h"
#include "displayapp/screens/SystemInfo.h"
Expand Down Expand Up @@ -435,6 +436,9 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction)
case Apps::Twos:
currentScreen = std::make_unique<Screens::Twos>(this);
break;
case Apps::Calendar:
currentScreen = std::make_unique<Screens::Calendar>(this, batteryController,dateTimeController);
Copy link
Contributor

@minacode minacode Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
currentScreen = std::make_unique<Screens::Calendar>(this, batteryController,dateTimeController);
currentScreen = std::make_unique<Screens::Calendar>(this, batteryController, dateTimeController);

break;
case Apps::Paint:
currentScreen = std::make_unique<Screens::InfiniPaint>(this, lvgl, motorController);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/displayapp/fonts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static constexpr const char* newSymbol = "\xEF\x86\x85";
* Do not enable font compression or horizontal subpixel rendering
* Load the file `JetBrainsMono-Bold.tff` (use the file in this repo to ensure the version matches) and specify the following range: `0x20-0x7e, 0x410-0x44f`
* Add a 2nd font, load the file `FontAwesome5-Solid+Brands+Regular.woff` and specify the following
range: `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015`
range: `0xf293, 0xf294, 0xf244, 0xf240, 0xf242, 0xf243, 0xf241, 0xf54b, 0xf21e, 0xf1e6, 0xf54b, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf069, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf029, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf201, 0xf06e, 0xf015, 0xf073`
* Fix an error in the font conversion.

Replace the following:
Expand Down
70 changes: 40 additions & 30 deletions src/displayapp/fonts/jetbrains_mono_bold_20.c
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,14 @@ static LV_ATTRIBUTE_LARGE_CONST const uint8_t glyph_bitmap[] = {
0xf8, 0xf, 0x80, 0xf8, 0x3e, 0x0, 0xff, 0xf0,
0x0, 0x3f, 0x80, 0x0,

/* U+F073 "" */
0x4, 0x8, 0x3, 0x87, 0x0, 0xe1, 0xc1, 0xff,
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfc,
0x0, 0x0, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x73,
0x9f, 0x9c, 0xe7, 0xe7, 0x39, 0xff, 0xff, 0xff,
0xff, 0xff, 0x9c, 0xe7, 0xe7, 0x39, 0xf9, 0xce,
0x7f, 0xff, 0xfd, 0xff, 0xfe,

/* U+F095 "" */
0x0, 0x0, 0x0, 0x0, 0x3e, 0x0, 0x7, 0xf0,
0x0, 0x7f, 0x0, 0x7, 0xf0, 0x0, 0xff, 0x0,
Expand Down Expand Up @@ -1220,31 +1228,32 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {
{.bitmap_index = 3027, .adv_w = 280, .box_w = 13, .box_h = 17, .ofs_x = 2, .ofs_y = -1},
{.bitmap_index = 3055, .adv_w = 320, .box_w = 19, .box_h = 20, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3103, .adv_w = 360, .box_w = 23, .box_h = 15, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 3147, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3200, .adv_w = 120, .box_w = 8, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3219, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3269, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3305, .adv_w = 320, .box_w = 20, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3353, .adv_w = 320, .box_w = 21, .box_h = 15, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 3393, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3436, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3474, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3512, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3550, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3588, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3626, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3662, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
{.bitmap_index = 3700, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3729, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
{.bitmap_index = 3767, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3833, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3882, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3932, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3992, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4045, .adv_w = 360, .box_w = 23, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4106, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4161, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4214, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
{.bitmap_index = 3147, .adv_w = 280, .box_w = 18, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3192, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3245, .adv_w = 120, .box_w = 8, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3264, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3314, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3350, .adv_w = 320, .box_w = 20, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3398, .adv_w = 320, .box_w = 21, .box_h = 15, .ofs_x = 0, .ofs_y = 0},
{.bitmap_index = 3438, .adv_w = 320, .box_w = 20, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3481, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3519, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3557, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3595, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3633, .adv_w = 400, .box_w = 25, .box_h = 12, .ofs_x = 0, .ofs_y = 1},
{.bitmap_index = 3671, .adv_w = 240, .box_w = 15, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3707, .adv_w = 280, .box_w = 15, .box_h = 20, .ofs_x = 1, .ofs_y = -3},
{.bitmap_index = 3745, .adv_w = 200, .box_w = 11, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3774, .adv_w = 280, .box_w = 16, .box_h = 19, .ofs_x = 1, .ofs_y = -2},
{.bitmap_index = 3812, .adv_w = 400, .box_w = 25, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 3878, .adv_w = 360, .box_w = 23, .box_h = 17, .ofs_x = 0, .ofs_y = -1},
{.bitmap_index = 3927, .adv_w = 320, .box_w = 20, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 3977, .adv_w = 400, .box_w = 25, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4037, .adv_w = 320, .box_w = 20, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4090, .adv_w = 360, .box_w = 23, .box_h = 21, .ofs_x = 0, .ofs_y = -3},
{.bitmap_index = 4151, .adv_w = 360, .box_w = 22, .box_h = 20, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4206, .adv_w = 360, .box_w = 22, .box_h = 19, .ofs_x = 0, .ofs_y = -2},
{.bitmap_index = 4259, .adv_w = 320, .box_w = 20, .box_h = 15, .ofs_x = 0, .ofs_y = 0}
};

/*---------------------
Expand All @@ -1253,10 +1262,11 @@ static const lv_font_fmt_txt_glyph_dsc_t glyph_dsc[] = {

static const uint16_t unicode_list_2[] = {
0x0, 0x14, 0x16, 0x23, 0x26, 0x27, 0x28, 0x39,
0x47, 0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x6d, 0x94,
0x128, 0x184, 0x1e5, 0x1fb, 0x200, 0x21d, 0x23f, 0x240,
0x241, 0x242, 0x243, 0x251, 0x292, 0x293, 0x2f1, 0x3dc,
0x3fc, 0x45c, 0x54a, 0x55f, 0x568, 0x59e, 0x59f, 0x6a8
0x47, 0x4a, 0x4b, 0x4c, 0x50, 0x68, 0x6d, 0x72,
0x94, 0x128, 0x184, 0x1e5, 0x1fb, 0x200, 0x21d, 0x23f,
0x240, 0x241, 0x242, 0x243, 0x251, 0x292, 0x293, 0x2f1,
0x3dc, 0x3fc, 0x45c, 0x54a, 0x55f, 0x568, 0x59e, 0x59f,
0x6a8
};

/*Collect the unicode lists and glyph_id offsets*/
Expand All @@ -1272,7 +1282,7 @@ static const lv_font_fmt_txt_cmap_t cmaps[] =
},
{
.range_start = 61441, .range_length = 1705, .glyph_id_start = 160,
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 40, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
.unicode_list = unicode_list_2, .glyph_id_ofs_list = NULL, .list_length = 41, .type = LV_FONT_FMT_TXT_CMAP_SPARSE_TINY
}
};

Expand Down
22 changes: 9 additions & 13 deletions src/displayapp/screens/ApplicationList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ ApplicationList::ApplicationList(Pinetime::Applications::DisplayApp* app,
[this]() -> std::unique_ptr<Screen> {
return CreateScreen2();
},
//[this]() -> std::unique_ptr<Screen> { return CreateScreen3(); }
[this]() -> std::unique_ptr<Screen> {
return CreateScreen3();
}
},
Screens::ScreenListModes::UpDown} {
}
Expand All @@ -48,7 +50,7 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen1() {
{Symbols::hourGlass, Apps::Timer},
}};

return std::make_unique<Screens::Tile>(0, 2, app, settingsController, batteryController, dateTimeController, applications);
return std::make_unique<Screens::Tile>(0, 3, app, settingsController, batteryController, dateTimeController, applications);
}

std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
Expand All @@ -61,19 +63,13 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() {
{Symbols::clock, Apps::Alarm},
}};

return std::make_unique<Screens::Tile>(1, 2, app, settingsController, batteryController, dateTimeController, applications);
return std::make_unique<Screens::Tile>(1, 3, app, settingsController, batteryController, dateTimeController, applications);
}

/*std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
std::unique_ptr<Screen> ApplicationList::CreateScreen3() {
std::array<Screens::Tile::Applications, 6> applications {
{{"A", Apps::Meter},
{"B", Apps::Navigation},
{"C", Apps::Clock},
{"D", Apps::Music},
{"E", Apps::SysInfo},
{"F", Apps::Brightness}
}
};
{{Symbols::calendar, Apps::Calendar}
}};

return std::make_unique<Screens::Tile>(2, 3, app, settingsController, batteryController, dateTimeController, applications);
}*/
}
4 changes: 2 additions & 2 deletions src/displayapp/screens/ApplicationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ namespace Pinetime {
Pinetime::Controllers::Battery& batteryController;
Controllers::DateTime& dateTimeController;

ScreenList<2> screens;
ScreenList<3> screens;
std::unique_ptr<Screen> CreateScreen1();
std::unique_ptr<Screen> CreateScreen2();
// std::unique_ptr<Screen> CreateScreen3();
std::unique_ptr<Screen> CreateScreen3();
};
}
}
Expand Down
85 changes: 85 additions & 0 deletions src/displayapp/screens/Calendar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "displayapp/screens/Calendar.h"
#include "displayapp/DisplayApp.h"
#include "components/datetime/DateTimeController.h"
#include "displayapp/screens/BatteryIcon.h"

using namespace Pinetime::Applications::Screens;

Calendar::Calendar(DisplayApp* app, Pinetime::Controllers::Battery& batteryController, Controllers::DateTime& dateTimeController) : Screen(app), batteryController {batteryController}, dateTimeController {dateTimeController} {

// Status bar clock and battery
label_time = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(label_time, dateTimeController.FormattedTime().c_str());
lv_label_set_align(label_time, LV_LABEL_ALIGN_CENTER);
lv_obj_align(label_time, lv_scr_act(), LV_ALIGN_IN_TOP_LEFT, 0, 0);
batteryIcon = lv_label_create(lv_scr_act(), nullptr);
lv_label_set_text(batteryIcon, BatteryIcon::GetBatteryIcon(batteryController.PercentRemaining()));
lv_obj_align(batteryIcon, nullptr, LV_ALIGN_IN_TOP_RIGHT, 0, 0);

// Create calendar object
calendar = lv_calendar_create(lv_scr_act(), NULL);
// Set size
lv_obj_set_size(calendar, 230, 200);
// Set alignment
lv_obj_align(calendar, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -5);
// Disable clicks
lv_obj_set_click(calendar, false);

// Set background of today's date
lv_obj_set_style_local_bg_opa(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_OPA_COVER);
lv_obj_set_style_local_bg_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_WHITE);
lv_obj_set_style_local_radius(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, 3);

// Set style of today's date
lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_FOCUSED, LV_COLOR_BLACK);

// Set style of inactive month's days
lv_obj_set_style_local_text_color(calendar, LV_CALENDAR_PART_DATE, LV_STATE_DISABLED, lv_color_hex(0x505050));

// Get today's date
today.year = static_cast<int>(dateTimeController.Year());
today.month = static_cast<int>(dateTimeController.Month());
today.day = static_cast<int>(dateTimeController.Day());

// Set today's date
lv_calendar_set_today_date(calendar, &today);
lv_calendar_set_showed_date(calendar, &today);

// Use today's date as a reference for which month to show if moved
current = today;

}

bool Calendar::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
switch (event) {
case TouchEvents::SwipeLeft: {
if (current.month == 12) {
current.month = 1;
current.year++;
}
else{
current.month++;
}
lv_calendar_set_showed_date(calendar, &current);
return true;
}
case TouchEvents::SwipeRight: {
if (current.month == 1) {
current.month = 12;
current.year--;
}
else{
current.month--;
}
lv_calendar_set_showed_date(calendar, &current);
return true;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also utilize SwipeUP/SwipeDown to switch to next/prev year.

Btw, a rebase is needed. And I've just done that so you call pull from:
https://github.com/Boteium/InfiniTime/tree/rebase_calendar

default: {
return false;
}
}
}

Calendar::~Calendar() {
lv_obj_clean(lv_scr_act());
}
33 changes: 33 additions & 0 deletions src/displayapp/screens/Calendar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#pragma once

#include "displayapp/screens/Screen.h"
#include <lvgl/lvgl.h>
#include "components/datetime/DateTimeController.h"
#include "components/battery/BatteryController.h"

namespace Pinetime {
namespace Controllers {
class Settings;
}

namespace Applications {
namespace Screens {
class Calendar : public Screen {
public:
Calendar(DisplayApp* app,
Pinetime::Controllers::Battery& batteryController,
Controllers::DateTime& dateTimeController);
~Calendar() override;
private:
bool OnTouchEvent(TouchEvents event);
Pinetime::Controllers::Battery& batteryController;
Controllers::DateTime& dateTimeController;
lv_obj_t* batteryIcon;
lv_obj_t* label_time;
lv_obj_t * calendar;
lv_calendar_date_t today;
lv_calendar_date_t current;
};
}
}
}
1 change: 1 addition & 0 deletions src/displayapp/screens/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Pinetime {
static constexpr const char* chartLine = "\xEF\x88\x81";
static constexpr const char* eye = "\xEF\x81\xAE";
static constexpr const char* home = "\xEF\x80\x95";
static constexpr const char* calendar = "\xEF\x81\xB3";

// lv_font_sys_48.c
static constexpr const char* settings = "\xEE\xA4\x82"; // e902
Expand Down