diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp index 487a92c3..22f8402d 100644 --- a/src/displayapp/DisplayApp.cpp +++ b/src/displayapp/DisplayApp.cpp @@ -478,7 +478,7 @@ void DisplayApp::LoadApp(Apps app, DisplayApp::FullRefreshDirections direction) break; case Apps::Agenda: - currentScreen = std::make_unique(this, systemTask->nimble().agenda()); + currentScreen = std::make_unique(this, systemTask->nimble().agenda(), dateTimeController); break; } currentApp = app; diff --git a/src/displayapp/screens/Agenda.cpp b/src/displayapp/screens/Agenda.cpp index 620fd08b..232e174c 100644 --- a/src/displayapp/screens/Agenda.cpp +++ b/src/displayapp/screens/Agenda.cpp @@ -8,7 +8,7 @@ using namespace Pinetime::Applications::Screens; using namespace Pinetime::Controllers; -Agenda::Agenda(DisplayApp* app, AgendaService& agenda) : Screen(app), agendaSvc(agenda) { +Agenda::Agenda(DisplayApp* app, AgendaService& agenda, Controllers::DateTime& dateTimeController) : Screen(app), agendaSvc(agenda), dateTimeController(dateTimeController) { lv_obj_t* alignNextTo = lv_scr_act(); for (uint8_t i = 0; i < 4; ++i) { @@ -35,12 +35,12 @@ Agenda::~Agenda() { void Agenda::Refresh() { using namespace date; using namespace std::chrono; - std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); + std::chrono::system_clock::time_point now = dateTimeController.CurrentDateTime(); auto todayDate = floor(now); auto nowTimePart = make_time(now - todayDate); auto todayYmd = year_month_day(todayDate); - NRF_LOG_INFO("date CURRENT %d-%u-%u %ldh%ldh%ld", (int) todayYmd.year(), (unsigned) todayYmd.month(), (unsigned) todayYmd.day(), nowTimePart.hours().count(), nowTimePart.minutes().count(), nowTimePart.seconds().count()); +// NRF_LOG_INFO("date CURRENT %d-%u-%u %ldh%ldh%ld", (int) todayYmd.year(), (unsigned) todayYmd.month(), (unsigned) todayYmd.day(), nowTimePart.hours().count(), nowTimePart.minutes().count(), nowTimePart.seconds().count()); //std::cout << todayDate << ' ' << nowTimePart << '\n'; @@ -54,19 +54,22 @@ void Agenda::Refresh() { lv_label_set_text_static(agendaItem, "--h--\n ....."); lv_obj_set_style_local_text_color(agendaItem, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x332222)); } else { - auto timestamp = std::chrono::system_clock::time_point{time * 1s}; - auto agendaDate = floor(timestamp); - auto agendaTimePart = make_time(timestamp - agendaDate); - auto ymd = year_month_day(agendaDate); + sys_seconds timestamp = sys_days{1970_y/1/1} + seconds{time}; + //auto timestamp = std::chrono::system_clock::time_point{time * 1s}; + sys_days agendaDate = floor(timestamp); + time_of_day agendaTimePart = make_time(timestamp - agendaDate); + year_month_day ymd = year_month_day(agendaDate); //std::cout << agendaDate << ' ' << agendaTimePart << '\n'; /*std::time_t result = std::time(nullptr); std::time_t result = std::time(nullptr); std::chrono::time_point = */; - NRF_LOG_INFO("unix IDX%u %lld", itemIdx, time); - NRF_LOG_INFO("date IDX%u %d-%u-%u %ldh%ldh%ld", itemIdx, (int) ymd.year(), (unsigned) ymd.month(), (unsigned) ymd.day(), agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaTimePart.seconds().count()); - NRF_LOG_INFO("item IDX%u %s", itemIdx, agendaSvc.getAgendaPiece(itemIdx).data()); +// NRF_LOG_INFO("IDX %u", itemIdx); +// NRF_LOG_INFO("unix %u", time); +// NRF_LOG_INFO("date %d-%u-%u ", (int) ymd.year(), (unsigned) ymd.month(), (unsigned) ymd.day()); +// NRF_LOG_INFO("time %ldh%ldm%ld", agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaTimePart.seconds().count()); +// NRF_LOG_INFO("item %s", agendaSvc.getAgendaPiece(itemIdx).data()); if (agendaDate == todayDate) { lv_label_set_text_fmt(agendaItem, "%02lldh%02lld\n %s", agendaTimePart.hours().count(), agendaTimePart.minutes().count(), agendaSvc.getAgendaPiece(itemIdx).data()); diff --git a/src/displayapp/screens/Agenda.h b/src/displayapp/screens/Agenda.h index e0d7eba5..1e180d19 100644 --- a/src/displayapp/screens/Agenda.h +++ b/src/displayapp/screens/Agenda.h @@ -1,17 +1,19 @@ #pragma once #include "displayapp/screens/Screen.h" +#include "components/datetime/DateTimeController.h" #include namespace Pinetime { namespace Controllers { class AgendaService; + class DateTime; } namespace Applications { namespace Screens { class Agenda : public Screen { public: - Agenda(DisplayApp* app, Pinetime::Controllers::AgendaService& agendaSvc); + Agenda(DisplayApp* app, Pinetime::Controllers::AgendaService& agendaSvc, Pinetime::Controllers::DateTime &dateTimeController); ~Agenda() override; void Refresh() override; @@ -19,6 +21,8 @@ namespace Pinetime { private: Pinetime::Controllers::AgendaService& agendaSvc; + Controllers::DateTime& dateTimeController; + lv_obj_t* agendaItems[4]; uint8_t pagingOffset; };