Compare commits
1 commit
main
...
kill-yours
Author | SHA1 | Date | |
---|---|---|---|
Lea | 1932e215d1 |
|
@ -2,6 +2,7 @@
|
|||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<application
|
||||
android:label="hrt"
|
||||
android:name="${applicationName}"
|
||||
|
@ -32,5 +33,15 @@
|
|||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
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>
|
||||
</manifest>
|
||||
|
|
3
android/app/src/main/res/drawable/keep.xml
Normal file
3
android/app/src/main/res/drawable/keep.xml
Normal file
|
@ -0,0 +1,3 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools"
|
||||
tools:keep="@drawable/*" />
|
|
@ -69,7 +69,7 @@ class _HomePageState extends State<HomePage> {
|
|||
}
|
||||
});
|
||||
|
||||
sendNotification();
|
||||
scheduleNotification();
|
||||
},
|
||||
),
|
||||
),
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
// ignore_for_file: avoid_print
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
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:timezone/data/latest.dart';
|
||||
import 'package:timezone/standalone.dart';
|
||||
import 'package:timezone/timezone.dart';
|
||||
|
||||
const details = NotificationDetails(
|
||||
|
@ -44,17 +48,24 @@ void sendNotification() async {
|
|||
void scheduleNotification() async {
|
||||
_initializePlugin();
|
||||
initializeTimeZones();
|
||||
var timezone = await FlutterNativeTimezone.getLocalTimezone();
|
||||
setLocalLocation(getLocation(timezone));
|
||||
|
||||
// [Hours, Minutes]
|
||||
var times = [
|
||||
[12, 00],
|
||||
[18, 00],
|
||||
[19, 50],
|
||||
[19, 51],
|
||||
[20, 52],
|
||||
[20, 53],
|
||||
];
|
||||
|
||||
if (times.isEmpty) return;
|
||||
|
||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||
var currentTime = TZDateTime.now(local);
|
||||
print(local.name);
|
||||
|
||||
// Map the time entries to TZDateTime objects
|
||||
var notificationTimes = times
|
||||
|
@ -70,13 +81,15 @@ void scheduleNotification() async {
|
|||
|
||||
// For all entries in the past, add 1 day
|
||||
for (var time
|
||||
in notificationTimes.where((time) => time.compareTo(currentTime) < 0)) {
|
||||
in notificationTimes.where((time) => time.compareTo(currentTime) <= 0)) {
|
||||
notificationTimes.remove(time);
|
||||
notificationTimes.add(time.add(const Duration(days: 1)));
|
||||
print("trolling ${time.toString()}");
|
||||
}
|
||||
|
||||
// Sort the array so we can find the closest time
|
||||
notificationTimes.sort((a, b) => a.compareTo(b));
|
||||
print(notificationTimes.map((e) => e.toString()).join(" - "));
|
||||
var notificationTime = notificationTimes[0];
|
||||
|
||||
if (prefs.getString('scheduled_notification') ==
|
||||
|
|
|
@ -22,7 +22,7 @@ void setupBackgroundTasks() async {
|
|||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await Workmanager().initialize(
|
||||
callbackDispatcher,
|
||||
isInDebugMode: kDebugMode,
|
||||
isInDebugMode: true || kDebugMode,
|
||||
);
|
||||
|
||||
await Permission.notification.request();
|
||||
|
|
16
pubspec.lock
16
pubspec.lock
|
@ -134,6 +134,14 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: "direct dev"
|
||||
description: flutter
|
||||
|
@ -144,6 +152,14 @@ packages:
|
|||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
js:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: js
|
||||
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.7"
|
||||
lints:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
@ -41,6 +41,7 @@ dependencies:
|
|||
workmanager: ^0.5.2
|
||||
timezone: ^0.9.2
|
||||
shared_preferences: ^2.2.1
|
||||
flutter_native_timezone: ^2.0.0
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
|
Loading…
Reference in a new issue