Skip to content

Commit

Permalink
[Infrastructure] Updated the notif. package to the latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Aug 19, 2023
1 parent edfa406 commit f7aef86
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 28 deletions.
8 changes: 8 additions & 0 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ android {
compileSdkVersion localProperties.getProperty('flutter.compileSdkVersion').toInteger()

compileOptions {
// Flag to enable support for the new language APIs
coreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
Expand All @@ -55,6 +57,7 @@ android {


defaultConfig {
multiDexEnabled true
applicationId "com.miraisoft.shiori"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
Expand Down Expand Up @@ -107,4 +110,9 @@ dependencies {
def appCenterSdkVersion = '4.4.5'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"

// Required by the notifications plugin
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
implementation 'androidx.window:window:1.0.0'
implementation 'androidx.window:window-java:1.0.0'
}
2 changes: 0 additions & 2 deletions android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
@com.google.gson.annotations.SerializedName <fields>;
}

-keepattributes InnerClasses

# Retain generic signatures of TypeToken and its subclasses with R8 version 3.0 and higher.
-keep,allowobfuscation,allowshrinking class com.google.gson.reflect.TypeToken
-keep,allowobfuscation,allowshrinking class * extends com.google.gson.reflect.TypeToken
Expand Down
7 changes: 1 addition & 6 deletions lib/domain/services/notification_service.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:shiori/domain/enums/enums.dart';

abstract class NotificationService {
void init();

//TODO: REMOVE THE PLUGIN DEPENDENCY FROM THIS LAYER
Future<void> registerCallBacks({
DidReceiveLocalNotificationCallback? onIosReceiveLocalNotification,
SelectNotificationCallback? onSelectNotification,
});
Future<void> registerCallBacks();

Future<bool> requestIOSPermissions();

Expand Down
19 changes: 8 additions & 11 deletions lib/infrastructure/notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,16 @@ class NotificationServiceImpl implements NotificationService {
}

@override
Future<void> registerCallBacks({
DidReceiveLocalNotificationCallback? onIosReceiveLocalNotification,
SelectNotificationCallback? onSelectNotification,
}) async {
Future<void> registerCallBacks() async {
try {
if (!isPlatformSupported) {
return Future.value();
}
const android = AndroidInitializationSettings('ic_notification');
final iOS = IOSInitializationSettings(onDidReceiveLocalNotification: onIosReceiveLocalNotification);
const macOS = MacOSInitializationSettings();
final initializationSettings = InitializationSettings(android: android, iOS: iOS, macOS: macOS);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings, onSelectNotification: onSelectNotification);
const iOS = DarwinInitializationSettings();
const macOS = DarwinInitializationSettings();
const initializationSettings = InitializationSettings(android: android, iOS: iOS, macOS: macOS);
await _flutterLocalNotificationsPlugin.initialize(initializationSettings);
} catch (e, s) {
_loggingService.error(runtimeType, 'registerCallBacks: Unknown error occurred', e, s);
}
Expand Down Expand Up @@ -128,7 +125,7 @@ class NotificationServiceImpl implements NotificationService {
scheduledDate,
specifics,
uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
androidAllowWhileIdle: true,
androidScheduleMode: AndroidScheduleMode.exactAllowWhileIdle,
payload: payload,
);
}
Expand All @@ -152,8 +149,8 @@ class NotificationServiceImpl implements NotificationService {
largeIcon: const DrawableResourceAndroidBitmap(_largeIcon),
tag: _getTagFromNotificationType(type),
);
const iOS = IOSNotificationDetails(presentAlert: true, presentBadge: true, presentSound: true, threadIdentifier: _channelId);
const macOS = MacOSNotificationDetails(presentAlert: true, presentBadge: true, presentSound: true, threadIdentifier: _channelId);
const iOS = DarwinNotificationDetails(presentAlert: true, presentBadge: true, presentSound: true, threadIdentifier: _channelId);
const macOS = DarwinNotificationDetails(presentAlert: true, presentBadge: true, presentSound: true, threadIdentifier: _channelId);

return NotificationDetails(android: android, iOS: iOS, macOS: macOS);
}
Expand Down
9 changes: 1 addition & 8 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ Future<void> main() async {
setWindowMaxSize(Size.infinite);
}
final notificationService = getIt<NotificationService>();
final notifFuture = notificationService.registerCallBacks(
onSelectNotification: _onSelectNotification,
onIosReceiveLocalNotification: _onDidReceiveLocalNotification,
);
final notifFuture = notificationService.registerCallBacks();
//TODO: CHECK THE NOTIFICATION LOGIC
//TODO: WEBVIEW SUPPORT IN MACOS
if (!Platform.isMacOS) {
Expand All @@ -42,10 +39,6 @@ Future<void> main() async {
runApp(MyApp());
}

Future<dynamic> _onDidReceiveLocalNotification(int id, String? title, String? body, String? payload) async {}

Future<void> _onSelectNotification(String? json) async {}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies:
flutter_bloc: ^7.3.1
flutter_colorpicker: ^1.0.3
flutter_inappwebview: ^5.7.2+3
flutter_local_notifications: ^9.5.3+1
flutter_local_notifications: ^15.1.0+1
flutter_localizations:
sdk: flutter
flutter_markdown: ^0.6.17+1
Expand Down

0 comments on commit f7aef86

Please sign in to comment.