improve ui

This commit is contained in:
2026-08-02 08:06:35 +02:00
parent c6c576174b
commit 65e62f6a39
25 changed files with 298 additions and 740 deletions
+10 -34
View File
@@ -1,7 +1,8 @@
#include "home_screen.h"
#include "../../include/text_utils.h"
#include <M5Stack.h>
#include "../../include/theme.h"
#include "../../include/text_utils.h"
#include "../../include/date_utils.h"
#include "../icons/icons.h"
#include "../api/weather_api.h"
#include "../api/calendar_api.h"
@@ -12,32 +13,15 @@ namespace {
bool weatherOk = false;
bool calendarOk = false;
unsigned long lastFetchMs = 0;
const unsigned long REFRESH_INTERVAL_MS = 10UL * 60UL * 1000UL; // 10 minutes
String formatEventTime(const CalendarEvent &ev) {
// Times are shown exactly as provided by the API, no timezone math.
if (ev.allDay) {
// start_at looks like "2026-08-03T00:00:00" -> show date part only
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); // HH:MM
}
return ev.startAt;
}
}
const unsigned long REFRESH_INTERVAL_MS = 10UL * 60UL * 1000UL;
void doFetch() {
WeatherData w = fetchWeather();
weatherOk = w.valid;
if (w.valid) lastWeather = w;
CalendarData c = fetchCalendar();
calendarOk = c.valid;
if (c.valid) lastCalendar = c;
lastFetchMs = millis();
}
@@ -50,21 +34,16 @@ namespace {
}
void updateHomeScreen() {
if (lastFetchMs == 0 || millis() - lastFetchMs >= REFRESH_INTERVAL_MS) {
doFetch();
}
if (lastFetchMs == 0 || millis() - lastFetchMs >= REFRESH_INTERVAL_MS) doFetch();
}
void renderHomeScreen(bool forceRefresh) {
if (forceRefresh || lastFetchMs == 0) {
doFetch();
}
if (forceRefresh || lastFetchMs == 0) doFetch();
M5.Lcd.fillScreen(Theme::BG);
// --- Weather block (top) ---
if (weatherOk) {
Icons::drawWeatherIcon(lastWeather.current.symbol, 45, 55, 24);
Icons::drawWeatherIcon(lastWeather.current.symbol, lastWeather.current.description, 45, 55, 24);
M5.Lcd.setTextColor(Theme::TEXT, Theme::BG);
M5.Lcd.setTextSize(4);
@@ -91,12 +70,10 @@ void renderHomeScreen(bool forceRefresh) {
M5.Lcd.drawFastHLine(10, 95, Theme::SCREEN_W - 20, Theme::BG_CARD);
// --- Calendar block (next 2 events) ---
Icons::drawCalendarIcon(20, 112, 16);
M5.Lcd.setTextColor(Theme::TEXT, Theme::BG);
M5.Lcd.setTextSize(2);
M5.Lcd.setCursor(10, 105);
Icons::drawCalendarIcon(20, 115, 14);
M5.Lcd.setCursor(35, 108);
M5.Lcd.setCursor(38, 104);
M5.Lcd.print("Termine");
if (calendarOk) {
@@ -112,16 +89,15 @@ void renderHomeScreen(bool forceRefresh) {
M5.Lcd.setTextColor(Theme::TEXT_DIM, Theme::BG);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(10, y + 20);
M5.Lcd.print(formatEventTime(ev));
M5.Lcd.print(DateUtils::formatShortDE(ev.startAt, ev.allDay));
y += 40;
y += 42;
shown++;
}
} else {
drawErrorState(20, 150, "Kalender n.a.");
}
// --- Footer hint ---
M5.Lcd.setTextColor(Theme::TEXT_DIM, Theme::BG);
M5.Lcd.setTextSize(1);
M5.Lcd.setCursor(10, 225);