mirror of
https://github.com/skoelle/m5stack-dashboard.git
synced 2026-09-18 00:50:24 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
#include "calendar_detail_screen.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(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");
|
||||
}
|
||||
Reference in New Issue
Block a user