mirror of
https://github.com/skoelle/m5stack-dashboard.git
synced 2026-09-17 16:50:23 +00:00
67 lines
1.8 KiB
C++
67 lines
1.8 KiB
C++
#include "calendar_detail_screen.h"
|
|
#include "../../include/text_utils.h"
|
|
#include <M5Stack.h>
|
|
#include "../../include/theme.h"
|
|
#include "../icons/icons.h"
|
|
#include "../api/calendar_api.h"
|
|
|
|
namespace {
|
|
CalendarData lastCalendar;
|
|
bool ok = false;
|
|
|
|
String formatEventTime(const CalendarEvent &ev) {
|
|
if (ev.allDay) {
|
|
int tIdx = ev.startAt.indexOf('T');
|
|
return tIdx > 0 ? ev.startAt.substring(0, tIdx) : ev.startAt;
|
|
} else {
|
|
int tIdx = ev.startAt.indexOf('T');
|
|
if (tIdx > 0 && ev.startAt.length() >= tIdx + 6) {
|
|
return ev.startAt.substring(tIdx + 1, tIdx + 6);
|
|
}
|
|
return ev.startAt;
|
|
}
|
|
}
|
|
}
|
|
|
|
void renderCalendarDetailScreen(bool forceRefresh) {
|
|
if (forceRefresh || !ok) {
|
|
CalendarData c = fetchCalendar();
|
|
ok = c.valid;
|
|
if (c.valid) lastCalendar = c;
|
|
}
|
|
|
|
M5.Lcd.fillScreen(Theme::BG);
|
|
M5.Lcd.setTextColor(Theme::TEXT, Theme::BG);
|
|
M5.Lcd.setTextSize(2);
|
|
M5.Lcd.setCursor(10, 10);
|
|
M5.Lcd.print("Alle Termine");
|
|
|
|
if (!ok) {
|
|
Icons::drawRetryIcon(30, 60, 12);
|
|
M5.Lcd.setTextColor(Theme::TEXT_DIM, Theme::BG);
|
|
M5.Lcd.setCursor(50, 55);
|
|
M5.Lcd.print("Keine Verbindung");
|
|
return;
|
|
}
|
|
|
|
int y = 40;
|
|
for (const auto &ev : lastCalendar.events) {
|
|
if (y > 215) break;
|
|
|
|
M5.Lcd.setTextColor(Theme::TEXT, Theme::BG);
|
|
M5.Lcd.setTextSize(1);
|
|
M5.Lcd.setCursor(10, y);
|
|
M5.Lcd.print(sanitizeGermanText(ev.summary.substring(0, 28)));
|
|
|
|
M5.Lcd.setTextColor(Theme::TEXT_DIM, Theme::BG);
|
|
M5.Lcd.setCursor(230, y);
|
|
M5.Lcd.print(formatEventTime(ev));
|
|
|
|
y += 18;
|
|
}
|
|
|
|
M5.Lcd.setTextColor(Theme::TEXT_DIM, Theme::BG);
|
|
M5.Lcd.setCursor(10, 228);
|
|
M5.Lcd.print("A:Wetter B:Home C:MVG");
|
|
}
|