Skip to content

Commit 792ea9e

Browse files
committed
feat(notification): first part; targetSdk 35
1 parent f3ed668 commit 792ea9e

File tree

11 files changed

+109
-63
lines changed

11 files changed

+109
-63
lines changed

android/app/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ if (flutterVersionName == null) {
2323
}
2424

2525
android {
26-
compileSdkVersion 34
26+
compileSdkVersion 35
27+
28+
namespace "org.brightdv.boxbox"
2729

2830
compileOptions {
2931
sourceCompatibility JavaVersion.VERSION_17

android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public static void registerWith(@NonNull FlutterEngine flutterEngine) {
2020
} catch (Exception e) {
2121
Log.e(TAG, "Error registering plugin add_2_calendar, com.javih.add_2_calendar.Add2CalendarPlugin", e);
2222
}
23+
try {
24+
flutterEngine.getPlugins().add(new me.carda.awesome_notifications.AwesomeNotificationsPlugin());
25+
} catch (Exception e) {
26+
Log.e(TAG, "Error registering plugin awesome_notifications, me.carda.awesome_notifications.AwesomeNotificationsPlugin", e);
27+
}
2328
try {
2429
flutterEngine.getPlugins().add(new com.bbflight.background_downloader.BDPlugin());
2530
} catch (Exception e) {
@@ -105,5 +110,10 @@ public static void registerWith(@NonNull FlutterEngine flutterEngine) {
105110
} catch (Exception e) {
106111
Log.e(TAG, "Error registering plugin wakelock_plus, dev.fluttercommunity.plus.wakelock.WakelockPlusPlugin", e);
107112
}
113+
try {
114+
flutterEngine.getPlugins().add(new dev.fluttercommunity.workmanager.WorkmanagerPlugin());
115+
} catch (Exception e) {
116+
Log.e(TAG, "Error registering plugin workmanager, dev.fluttercommunity.workmanager.WorkmanagerPlugin", e);
117+
}
108118
}
109119
}

android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip

android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pluginManagement {
1818

1919
plugins {
2020
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
21-
id "com.android.application" version "7.4.1" apply false
21+
id "com.android.application" version "8.1.0" apply false
2222
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
2323
}
2424

ios/Runner/GeneratedPluginRegistrant.m

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
@import add_2_calendar;
1313
#endif
1414

15+
#if __has_include(<awesome_notifications/AwesomeNotificationsPlugin.h>)
16+
#import <awesome_notifications/AwesomeNotificationsPlugin.h>
17+
#else
18+
@import awesome_notifications;
19+
#endif
20+
1521
#if __has_include(<background_downloader/BackgroundDownloaderPlugin.h>)
1622
#import <background_downloader/BackgroundDownloaderPlugin.h>
1723
#else
@@ -114,10 +120,17 @@
114120
@import wakelock_plus;
115121
#endif
116122

123+
#if __has_include(<workmanager/WorkmanagerPlugin.h>)
124+
#import <workmanager/WorkmanagerPlugin.h>
125+
#else
126+
@import workmanager;
127+
#endif
128+
117129
@implementation GeneratedPluginRegistrant
118130

119131
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
120132
[Add2CalendarPlugin registerWithRegistrar:[registry registrarForPlugin:@"Add2CalendarPlugin"]];
133+
[AwesomeNotificationsPlugin registerWithRegistrar:[registry registrarForPlugin:@"AwesomeNotificationsPlugin"]];
121134
[BackgroundDownloaderPlugin registerWithRegistrar:[registry registrarForPlugin:@"BackgroundDownloaderPlugin"]];
122135
[ConnectivityPlusPlugin registerWithRegistrar:[registry registrarForPlugin:@"ConnectivityPlusPlugin"]];
123136
[FPPDeviceInfoPlusPlugin registerWithRegistrar:[registry registrarForPlugin:@"FPPDeviceInfoPlusPlugin"]];
@@ -135,6 +148,7 @@ + (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
135148
[URLLauncherPlugin registerWithRegistrar:[registry registrarForPlugin:@"URLLauncherPlugin"]];
136149
[FVPVideoPlayerPlugin registerWithRegistrar:[registry registrarForPlugin:@"FVPVideoPlayerPlugin"]];
137150
[WakelockPlusPlugin registerWithRegistrar:[registry registrarForPlugin:@"WakelockPlusPlugin"]];
151+
[WorkmanagerPlugin registerWithRegistrar:[registry registrarForPlugin:@"WorkmanagerPlugin"]];
138152
}
139153

140154
@end

lib/api/formula1.dart

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class Formula1 {
7676
return newsList;
7777
}
7878

79-
FutureOr<List<News>> getMoreNews(
79+
FutureOr<Map> getRawNews(
8080
int offset, {
8181
String? tagId,
8282
String? articleType,
@@ -122,6 +122,19 @@ class Formula1 {
122122
Hive.box('requests').put('news', responseAsJson);
123123
Hive.box('requests').put('newsLastSavedFormat', 'f1');
124124
}
125+
return responseAsJson;
126+
}
127+
128+
FutureOr<List<News>> getMoreNews(
129+
int offset, {
130+
String? tagId,
131+
String? articleType,
132+
}) async {
133+
Map responseAsJson = await getRawNews(
134+
offset,
135+
tagId: tagId,
136+
articleType: articleType,
137+
);
125138
return formatResponse(responseAsJson);
126139
}
127140

lib/main.dart

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import 'dart:async';
2323

2424
import 'package:adaptive_theme/adaptive_theme.dart';
2525
import 'package:background_downloader/background_downloader.dart';
26+
import 'package:boxbox/api/formula1.dart';
2627
import 'package:boxbox/config/router.dart';
27-
// import 'package:awesome_notifications/awesome_notifications.dart';
28+
import 'package:awesome_notifications/awesome_notifications.dart';
2829
import 'package:boxbox/helpers/constants.dart';
2930
import 'package:boxbox/helpers/route_handler.dart';
30-
// import 'package:boxbox/Screens/article.dart';
3131
import 'package:boxbox/helpers/team_background_color.dart';
3232
import 'package:flutter/material.dart';
3333
import 'package:flutter/foundation.dart' show kIsWeb;
@@ -36,6 +36,7 @@ import 'package:go_router/go_router.dart';
3636
import 'package:hive_flutter/hive_flutter.dart';
3737
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
3838
import 'package:timeago/timeago.dart' as timeago;
39+
import 'package:workmanager/workmanager.dart';
3940

4041
void main() async {
4142
WidgetsFlutterBinding.ensureInitialized();
@@ -50,10 +51,8 @@ void main() async {
5051

5152
if (!kIsWeb) {
5253
await FileDownloader().trackTasks();
53-
}
5454

55-
/* if (!kIsWeb) {
56-
AwesomeNotifications().initialize(
55+
await AwesomeNotifications().initialize(
5756
'resource://drawable/notification_icon',
5857
[
5958
NotificationChannel(
@@ -75,29 +74,29 @@ void main() async {
7574
),
7675
],
7776
);
78-
} */
77+
}
7978

80-
/* Workmanager().initialize(
79+
await Workmanager().initialize(
8180
callbackDispatcher,
82-
isInDebugMode: false,
8381
);
84-
Workmanager().registerPeriodicTask(
82+
await Workmanager().registerPeriodicTask(
8583
'newsLoader',
8684
"Load news in background",
8785
existingWorkPolicy: ExistingWorkPolicy.replace,
88-
frequency: const Duration(hours: 2),
86+
frequency: const Duration(seconds: 30),
8987
initialDelay: const Duration(hours: 2),
90-
); */
88+
);
9189

9290
GoRouter.optionURLReflectsImperativeAPIs = true;
9391

9492
runApp(const MyApp());
9593
}
9694

97-
/* int createUniqueId() {
95+
int createUniqueId() {
9896
return DateTime.now().millisecondsSinceEpoch.remainder(100000);
9997
}
10098

99+
@pragma('vm:entry-point')
101100
void callbackDispatcher() {
102101
Workmanager().executeTask(
103102
(task, inputData) async {
@@ -108,7 +107,7 @@ void callbackDispatcher() {
108107
bool useDataSaverMode =
109108
settingsBox.get('useDataSaverMode', defaultValue: false) as bool;
110109
try {
111-
Map<String, dynamic> fetchedData = await F1NewsFetcher().getRawNews();
110+
Map fetchedData = await Formula1().getRawNews(0);
112111
if (cachedNews.isNotEmpty &&
113112
fetchedData['items'][0]['id'] != cachedNews['items'][0]['id']) {
114113
String imageUrl =
@@ -167,7 +166,7 @@ void callbackDispatcher() {
167166
}
168167
},
169168
);
170-
} */
169+
}
171170

172171
void setTimeagoLocaleMessages() {
173172
timeago.setLocaleMessages('ar', timeago.ArMessages());
@@ -248,43 +247,24 @@ void setTimeagoLocaleMessages() {
248247
timeago.setLocaleMessages('zh', timeago.ZhMessages());
249248
}
250249

251-
/* class NotificationController {
252-
static Future<void> startListeningNotificationEvents(
253-
BuildContext context) async {
254-
AwesomeNotifications().setListeners(
255-
onActionReceivedMethod: (receivedAction) async =>
256-
receivedAction.payload?['id'] == null
257-
? Navigator.push(
258-
context,
259-
MaterialPageRoute(
260-
builder: (context) => Scaffold(
261-
appBar: AppBar(
262-
title: const Text('wrong payload'),
263-
backgroundColor:
264-
Theme.of(context).colorScheme.onPrimary,
265-
),
266-
body: Center(
267-
child: Text(
268-
receivedAction.payload.toString(),
269-
),
270-
),
271-
),
272-
),
273-
)
274-
: Navigator.push(
275-
context,
276-
MaterialPageRoute(
277-
builder: (context) => ArticleScreen(
278-
receivedAction.payload!['id']!,
279-
receivedAction.payload!['title']!,
280-
false,
281-
),
282-
),
283-
),
250+
class NotificationController {
251+
@pragma("vm:entry-point")
252+
static Future<void> onActionReceivedMethod(
253+
ReceivedAction receivedAction) async {
254+
RouterLocalConfig.router.pushNamed(
255+
'article',
256+
pathParameters: receivedAction.payload?['title'] != null
257+
? {
258+
'id': receivedAction.payload?['id'] ?? '',
259+
'articleName': receivedAction.payload!['title']!,
260+
}
261+
: {
262+
'id': receivedAction.payload?['id'] ?? '',
263+
},
284264
);
285265
}
286266
}
287-
*/
267+
288268
class MyApp extends StatefulWidget {
289269
const MyApp({Key? key}) : super(key: key);
290270

@@ -300,11 +280,13 @@ class _MyAppState extends State<MyApp> {
300280
super.initState();
301281
if (!kIsWeb) {
302282
// notifications service
303-
// NotificationController.startListeningNotificationEvents(context);
283+
AwesomeNotifications().setListeners(
284+
onActionReceivedMethod: NotificationController.onActionReceivedMethod,
285+
);
304286

305287
// For sharing or opening urls/text coming from outside the app while the app is in the memory
306288
_intentDataStreamSubscription =
307-
ReceiveSharingIntent.getMediaStream().listen(
289+
ReceiveSharingIntent.instance.getMediaStream().listen(
308290
(List<SharedMediaFile>? value) {
309291
if (value?.isNotEmpty ?? false) {
310292
if (value?[0] != null) {
@@ -318,7 +300,7 @@ class _MyAppState extends State<MyApp> {
318300
);
319301

320302
// For sharing or opening urls/text coming from outside the app while the app is closed
321-
ReceiveSharingIntent.getInitialMedia().then(
303+
ReceiveSharingIntent.instance.getInitialMedia().then(
322304
(List<SharedMediaFile>? value) {
323305
if (value?.isNotEmpty ?? false) {
324306
if (value?[0] != null) {

linux/flutter/generated_plugin_registrant.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
#include "generated_plugin_registrant.h"
88

9+
#include <awesome_notifications/awesome_notifications_plugin.h>
910
#include <url_launcher_linux/url_launcher_plugin.h>
1011

1112
void fl_register_plugins(FlPluginRegistry* registry) {
13+
g_autoptr(FlPluginRegistrar) awesome_notifications_registrar =
14+
fl_plugin_registry_get_registrar_for_plugin(registry, "AwesomeNotificationsPlugin");
15+
awesome_notifications_plugin_register_with_registrar(awesome_notifications_registrar);
1216
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
1317
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
1418
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);

linux/flutter/generated_plugins.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#
44

55
list(APPEND FLUTTER_PLUGIN_LIST
6+
awesome_notifications
67
url_launcher_linux
78
)
89

pubspec.lock

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ packages:
6565
url: "https://pub.dev"
6666
source: hosted
6767
version: "3.0.0"
68+
awesome_notifications:
69+
dependency: "direct main"
70+
description:
71+
name: awesome_notifications
72+
sha256: "0d5fa4457f2ba4e536adc3ef6af709cdcecf4a05a1f3035981e9afa2f899b2a8"
73+
url: "https://pub.dev"
74+
source: hosted
75+
version: "0.10.1"
6876
background_downloader:
6977
dependency: "direct main"
7078
description:
@@ -849,11 +857,12 @@ packages:
849857
receive_sharing_intent:
850858
dependency: "direct main"
851859
description:
852-
name: receive_sharing_intent
853-
sha256: "2b2d5c6ff9098820447d217eae4f9f671e2d894a0d2ec33099a2fdd946a44996"
854-
url: "https://pub.dev"
855-
source: hosted
856-
version: "1.6.6"
860+
path: "."
861+
ref: master
862+
resolved-ref: "2cea396843cd3ab1b5ec4334be4233864637874e"
863+
url: "https://github.com/KasemJaffer/receive_sharing_intent"
864+
source: git
865+
version: "1.8.1"
857866
river_player:
858867
dependency: "direct main"
859868
description:
@@ -1363,6 +1372,14 @@ packages:
13631372
url: "https://pub.dev"
13641373
source: hosted
13651374
version: "2.0.0"
1375+
workmanager:
1376+
dependency: "direct main"
1377+
description:
1378+
name: workmanager
1379+
sha256: "746a50c535af15b6dc225abbd9b52ab272bcd292c535a104c54b5bc02609c38a"
1380+
url: "https://pub.dev"
1381+
source: hosted
1382+
version: "0.7.0"
13661383
xdg_directories:
13671384
dependency: transitive
13681385
description:

0 commit comments

Comments
 (0)