Merge branch '12-benachrichtigung-aufs-handy-erstellen-2' into 'main'

Resolve "Benachrichtigung aufs Handy erstellen"

See merge request Crondung/hsma_cpd!13
main
Julian Gegner 2023-02-26 13:05:37 +00:00
commit 6895638814
8 changed files with 61 additions and 21 deletions

View File

@ -30,6 +30,7 @@ android {
ndkVersion flutter.ndkVersion ndkVersion flutter.ndkVersion
compileOptions { compileOptions {
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8 sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8
} }
@ -51,6 +52,7 @@ android {
targetSdkVersion flutter.targetSdkVersion targetSdkVersion flutter.targetSdkVersion
versionCode flutterVersionCode.toInteger() versionCode flutterVersionCode.toInteger()
versionName flutterVersionName versionName flutterVersionName
multiDexEnabled true
} }
buildTypes { buildTypes {
@ -68,4 +70,5 @@ flutter {
dependencies { dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
} }

View File

@ -6,7 +6,7 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.1.2' classpath 'com.android.tools.build:gradle:7.1.2' //needs to be >= 4.2.2 for local notifications
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
} }
} }

View File

@ -13,7 +13,7 @@
}, },
"sleep_query": { "sleep_query": {
"days": ["Dienstag", "Samstag"], "days": ["Dienstag", "Samstag"],
"hours": 11, "hours": 15,
"minutes": 30 "minutes": 42
} }
} }

View File

@ -1,5 +1,6 @@
import UIKit import UIKit
import Flutter import Flutter
import flutter_local_notifications
@UIApplicationMain @UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate { @objc class AppDelegate: FlutterAppDelegate {
@ -7,7 +8,13 @@ import Flutter
_ application: UIApplication, _ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool { ) -> Bool {
FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in
GeneratedPluginRegistrant.register(with: registry)
}
GeneratedPluginRegistrant.register(with: self) GeneratedPluginRegistrant.register(with: self)
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self as? UNUserNotificationCenterDelegate
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions) return super.application(application, didFinishLaunchingWithOptions: launchOptions)
} }
} }

View File

@ -38,7 +38,9 @@ Future<List<TZDateTime>> getDatesforSleep() async {
List<TZDateTime> createTZDateTimes( List<TZDateTime> createTZDateTimes(
List<String>? selectedDays, int? selectedHours, int? selectedMinutes) { List<String>? selectedDays, int? selectedHours, int? selectedMinutes) {
List<TZDateTime> tzDateTimes = []; final List<TZDateTime> tzDateTimes = [];
final DateTime now = DateTime.now();
final Duration offset = now.timeZoneOffset;
if (selectedDays == null || if (selectedDays == null ||
selectedHours == null || selectedHours == null ||
selectedMinutes == null) { selectedMinutes == null) {
@ -47,10 +49,14 @@ List<TZDateTime> createTZDateTimes(
final Iterable<int?> selectedDaysInt = final Iterable<int?> selectedDaysInt =
selectedDays.map((day) => weekDays[day]); selectedDays.map((day) => weekDays[day]);
for (int i = 0; i < trainingTime; i++) { for (int i = 0; i < trainingTime; i++) {
final DateTime date = DateTime.now().add(Duration(days: i)); final DateTime date = DateTime(now.year, now.month, now.day, selectedHours,
if (selectedDaysInt.contains(date.weekday)) { selectedMinutes, 0, 0, 0)
.add(Duration(days: i));
if (selectedDaysInt.contains(date.weekday) &&
date.isAfter(DateTime.now())) {
tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day, tzDateTimes.add(TZDateTime.local(date.year, date.month, date.day,
selectedHours, selectedMinutes, 0, 0, 0)); selectedHours, selectedMinutes, 0, 0, 0)
.subtract(offset));
} }
} }
return tzDateTimes; return tzDateTimes;

View File

@ -18,11 +18,11 @@ class NotificationService {
Future<void> initNotification() async { Future<void> initNotification() async {
// Android initialization // Android initialization
const AndroidInitializationSettings initializationSettingsAndroid = const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('@mipmap/ic_launcher'); AndroidInitializationSettings('mipmap/ic_launcher');
// ios initialization // ios initialization
const IOSInitializationSettings initializationSettingsIOS = const DarwinInitializationSettings initializationSettingsIOS =
IOSInitializationSettings( DarwinInitializationSettings(
requestAlertPermission: false, requestAlertPermission: false,
requestBadgePermission: false, requestBadgePermission: false,
requestSoundPermission: false, requestSoundPermission: false,
@ -36,16 +36,40 @@ class NotificationService {
await flutterLocalNotificationsPlugin.initialize(initializationSettings); await flutterLocalNotificationsPlugin.initialize(initializationSettings);
} }
Future<void> showNotification() async {
await flutterLocalNotificationsPlugin.show(
0,
'test',
'test',
//schedule the notification to show after 2 seconds.
const NotificationDetails(
// Android details
android: AndroidNotificationDetails('main_channel', 'Main Channel',
channelDescription: "ashwin",
importance: Importance.max,
priority: Priority.max),
// iOS details
iOS: DarwinNotificationDetails(
sound: 'default.wav',
presentAlert: true,
presentBadge: true,
presentSound: true,
),
),
);
}
Future<void> setAllNotifications() async { Future<void> setAllNotifications() async {
List<TZDateTime> moodDates = await getDatesforMood(); List<TZDateTime> moodDates = await getDatesforMood();
List<TZDateTime> sleepDates = await getDatesforSleep(); List<TZDateTime> sleepDates = await getDatesforSleep();
int index = 0;
for (var date in moodDates) { for (var date in moodDates) {
setNotification(1, "Mood", "Evaluate your mood", date); setNotification(index, "Mood", "Evaluate your mood", date);
print("mood"); index++;
} }
for (var date in sleepDates) { for (var date in sleepDates) {
setNotification(1, "Sleep", "Evaluate your sleep", date); setNotification(index, "Sleep", "Evaluate your sleep", date);
print("sleep"); index++;
} }
} }
@ -63,7 +87,7 @@ class NotificationService {
importance: Importance.max, importance: Importance.max,
priority: Priority.max), priority: Priority.max),
// iOS details // iOS details
iOS: IOSNotificationDetails( iOS: DarwinNotificationDetails(
sound: 'default.wav', sound: 'default.wav',
presentAlert: true, presentAlert: true,
presentBadge: true, presentBadge: true,

View File

@ -152,21 +152,21 @@ packages:
name: flutter_local_notifications name: flutter_local_notifications
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "9.9.1" version: "13.0.0"
flutter_local_notifications_linux: flutter_local_notifications_linux:
dependency: transitive dependency: transitive
description: description:
name: flutter_local_notifications_linux name: flutter_local_notifications_linux
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.5.1" version: "3.0.0+1"
flutter_local_notifications_platform_interface: flutter_local_notifications_platform_interface:
dependency: transitive dependency: transitive
description: description:
name: flutter_local_notifications_platform_interface name: flutter_local_notifications_platform_interface
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "5.0.0" version: "6.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -433,7 +433,7 @@ packages:
name: timezone name: timezone
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.0" version: "0.9.1"
typed_data: typed_data:
dependency: transitive dependency: transitive
description: description:

View File

@ -38,11 +38,11 @@ dependencies:
# The following adds the Cupertino Icons font to your application. # The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons. # Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.2 cupertino_icons: ^1.0.2
flutter_local_notifications: ^9.3.1 timezone: ^0.9.0
timezone: ^0.8.0
shared_preferences: ^2.0.17 shared_preferences: ^2.0.17
audioplayers: ^3.0.1 audioplayers: ^3.0.1
mobile_scanner: ^3.0.0 mobile_scanner: ^3.0.0
flutter_local_notifications: ^13.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: