Compare commits

..

1 commit

Author SHA1 Message Date
Lea 1932e215d1
jesus fucking christ
i am never going to touch android dev again
2023-10-06 20:21:43 +02:00
7 changed files with 47 additions and 3 deletions

View file

@ -2,6 +2,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.VIBRATE" /> <uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" /> <uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
<application <application
android:label="hrt" android:label="hrt"
android:name="${applicationName}" android:name="${applicationName}"
@ -32,5 +33,15 @@
<meta-data <meta-data
android:name="flutterEmbedding" android:name="flutterEmbedding"
android:value="2" /> android:value="2" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" />
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED"/>
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
</intent-filter>
</receiver>
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />
</application> </application>
</manifest> </manifest>

View file

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
tools:keep="@drawable/*" />

View file

@ -69,7 +69,7 @@ class _HomePageState extends State<HomePage> {
} }
}); });
sendNotification(); scheduleNotification();
}, },
), ),
), ),

View file

@ -1,8 +1,12 @@
// ignore_for_file: avoid_print // ignore_for_file: avoid_print
import 'dart:io';
import 'package:flutter_local_notifications/flutter_local_notifications.dart'; import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:flutter_native_timezone/flutter_native_timezone.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
import 'package:timezone/data/latest.dart'; import 'package:timezone/data/latest.dart';
import 'package:timezone/standalone.dart';
import 'package:timezone/timezone.dart'; import 'package:timezone/timezone.dart';
const details = NotificationDetails( const details = NotificationDetails(
@ -44,17 +48,24 @@ void sendNotification() async {
void scheduleNotification() async { void scheduleNotification() async {
_initializePlugin(); _initializePlugin();
initializeTimeZones(); initializeTimeZones();
var timezone = await FlutterNativeTimezone.getLocalTimezone();
setLocalLocation(getLocation(timezone));
// [Hours, Minutes] // [Hours, Minutes]
var times = [ var times = [
[12, 00], [12, 00],
[18, 00], [18, 00],
[19, 50],
[19, 51],
[20, 52],
[20, 53],
]; ];
if (times.isEmpty) return; if (times.isEmpty) return;
final SharedPreferences prefs = await SharedPreferences.getInstance(); final SharedPreferences prefs = await SharedPreferences.getInstance();
var currentTime = TZDateTime.now(local); var currentTime = TZDateTime.now(local);
print(local.name);
// Map the time entries to TZDateTime objects // Map the time entries to TZDateTime objects
var notificationTimes = times var notificationTimes = times
@ -70,13 +81,15 @@ void scheduleNotification() async {
// For all entries in the past, add 1 day // For all entries in the past, add 1 day
for (var time for (var time
in notificationTimes.where((time) => time.compareTo(currentTime) < 0)) { in notificationTimes.where((time) => time.compareTo(currentTime) <= 0)) {
notificationTimes.remove(time); notificationTimes.remove(time);
notificationTimes.add(time.add(const Duration(days: 1))); notificationTimes.add(time.add(const Duration(days: 1)));
print("trolling ${time.toString()}");
} }
// Sort the array so we can find the closest time // Sort the array so we can find the closest time
notificationTimes.sort((a, b) => a.compareTo(b)); notificationTimes.sort((a, b) => a.compareTo(b));
print(notificationTimes.map((e) => e.toString()).join(" - "));
var notificationTime = notificationTimes[0]; var notificationTime = notificationTimes[0];
if (prefs.getString('scheduled_notification') == if (prefs.getString('scheduled_notification') ==

View file

@ -22,7 +22,7 @@ void setupBackgroundTasks() async {
WidgetsFlutterBinding.ensureInitialized(); WidgetsFlutterBinding.ensureInitialized();
await Workmanager().initialize( await Workmanager().initialize(
callbackDispatcher, callbackDispatcher,
isInDebugMode: kDebugMode, isInDebugMode: true || kDebugMode,
); );
await Permission.notification.request(); await Permission.notification.request();

View file

@ -134,6 +134,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "7.0.0+1" version: "7.0.0+1"
flutter_native_timezone:
dependency: "direct main"
description:
name: flutter_native_timezone
sha256: ed7bfb982f036243de1c068e269182a877100c994f05143c8b26a325e28c1b02
url: "https://pub.dev"
source: hosted
version: "2.0.0"
flutter_test: flutter_test:
dependency: "direct dev" dependency: "direct dev"
description: flutter description: flutter
@ -144,6 +152,14 @@ packages:
description: flutter description: flutter
source: sdk source: sdk
version: "0.0.0" version: "0.0.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints: lints:
dependency: transitive dependency: transitive
description: description:

View file

@ -41,6 +41,7 @@ dependencies:
workmanager: ^0.5.2 workmanager: ^0.5.2
timezone: ^0.9.2 timezone: ^0.9.2
shared_preferences: ^2.2.1 shared_preferences: ^2.2.1
flutter_native_timezone: ^2.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: