added german translation and store stuff for app

This commit is contained in:
Jan Pleterski
2026-11-13 10:56:11 +01:00
parent d4bc01f202
commit 30708c73b1
47 changed files with 530 additions and 160 deletions
+17 -32
View File
@@ -63,33 +63,9 @@ class NotificationService {
AndroidFlutterLocalNotificationsPlugin>();
await androidPlugin?.createNotificationChannel(_channel);
await requestPermissions();
await _requestExactAlarmsOnce();
} catch (_) {}
}
// Android 12+ needs "Alarms & reminders" access for on-time delivery.
// Ask once; without it we fall back to inexact alarms.
Future<void> _requestExactAlarmsOnce() async {
final android = _plugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>();
if (android == null) return;
if (await android.canScheduleExactNotifications() ?? true) return;
final prefs = await SharedPreferences.getInstance();
if (prefs.getBool('exactAlarmAsked') ?? false) return;
await prefs.setBool('exactAlarmAsked', true);
await android.requestExactAlarmsPermission();
}
Future<AndroidScheduleMode> _scheduleMode() async {
final android = _plugin.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>();
final canExact = await android?.canScheduleExactNotifications() ?? true;
return canExact
? AndroidScheduleMode.exactAllowWhileIdle
: AndroidScheduleMode.inexactAllowWhileIdle;
}
/// Fetches the calendar and reschedules all reminders. Call on app start
/// and whenever notification settings change.
Future<void> rescheduleFromCalendar() async {
@@ -140,9 +116,8 @@ class NotificationService {
final notifyDezuranje = prefs.getBool('notifyDezuranje') ?? true;
final notifySestanek = prefs.getBool('notifySestanek') ?? true;
final notifyTekma = prefs.getBool('notifyTekma') ?? true;
final isSlovenian = (prefs.getString('language') ?? 'English') == 'Slovenian';
final language = prefs.getString('language') ?? 'Slovenian';
final now = DateTime.now();
final mode = await _scheduleMode();
await _plugin.cancelAll();
@@ -166,23 +141,32 @@ class NotificationService {
await _scheduleNotification(
id: notifId++,
title: event.summary ?? 'Event',
body: isSlovenian
? (hours == 1 ? 'Začne se čez 1 uro' : 'Začne se čez $hours ur')
: (hours == 1 ? 'Starts in 1 hour' : 'Starts in $hours hours'),
body: _startsIn(hours, language),
scheduledDate: notifyAt,
mode: mode,
);
}
}
} catch (_) {}
}
static String _startsIn(int hours, String language) {
switch (language) {
case 'Slovenian':
final mod = hours % 100;
final unit = mod == 1 ? 'uro' : mod == 2 ? 'uri' : (mod == 3 || mod == 4) ? 'ure' : 'ur';
return 'Začne se čez $hours $unit';
case 'German':
return hours == 1 ? 'Beginnt in 1 Stunde' : 'Beginnt in $hours Stunden';
default:
return hours == 1 ? 'Starts in 1 hour' : 'Starts in $hours hours';
}
}
Future<void> _scheduleNotification({
required int id,
required String title,
required String body,
required DateTime scheduledDate,
required AndroidScheduleMode mode,
}) async {
final tzDate = tz.TZDateTime.from(scheduledDate, tz.local);
await _plugin.zonedSchedule(
@@ -191,7 +175,8 @@ class NotificationService {
body,
tzDate,
_notifDetails,
androidScheduleMode: mode,
// Inexact: avoids the SCHEDULE_EXACT_ALARM permission (Play policy).
androidScheduleMode: AndroidScheduleMode.inexactAllowWhileIdle,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime,
);