nc-photos/app/lib/mobile/notification.dart

73 lines
2.1 KiB
Dart
Raw Normal View History

2022-04-08 21:16:10 +02:00
import 'package:logging/logging.dart';
import 'package:nc_photos/platform/notification.dart' as itf;
2022-03-11 15:44:43 +01:00
import 'package:nc_photos_plugin/nc_photos_plugin.dart' as plugin;
2022-12-16 16:01:04 +01:00
import 'package:np_codegen/np_codegen.dart';
2022-12-16 16:01:04 +01:00
part 'notification.g.dart';
@npLog
2022-04-08 21:16:10 +02:00
class NotificationManager implements itf.NotificationManager {
@override
notify(itf.Notification n) {
if (n is itf.LogSaveSuccessfulNotification) {
return plugin.Notification.notifyLogSaveSuccessful(n.result);
} else if (n is AndroidDownloadSuccessfulNotification) {
return plugin.Notification.notifyDownloadSuccessful(
n.fileUris, n.mimeTypes, n.notificationId);
} else if (n is AndroidDownloadProgressNotification) {
return plugin.Notification.notifyDownloadProgress(
n.progress, n.max, n.currentItemTitle, n.notificationId);
} else {
_log.shout("[notify] Unknown type: ${n.runtimeType}");
throw UnsupportedError("Unsupported notification");
}
}
@override
2022-04-08 21:16:10 +02:00
dismiss(dynamic id) async {
if (id != null) {
return plugin.Notification.dismiss(id);
} else {
return;
}
}
}
class AndroidDownloadSuccessfulNotification implements itf.Notification {
const AndroidDownloadSuccessfulNotification(
this.fileUris,
this.mimeTypes, {
this.notificationId,
});
final List<String> fileUris;
2021-07-23 22:05:57 +02:00
final List<String?> mimeTypes;
2022-04-08 21:16:10 +02:00
final dynamic notificationId;
}
2022-04-08 21:16:10 +02:00
class AndroidDownloadProgressNotification implements itf.Notification {
const AndroidDownloadProgressNotification(
2021-10-02 11:12:54 +02:00
this.progress,
this.max, {
this.currentItemTitle,
2022-04-08 21:16:10 +02:00
this.notificationId,
2021-10-02 11:12:54 +02:00
});
2022-04-08 21:16:10 +02:00
AndroidDownloadProgressNotification copyWith({
int? progress,
2021-10-02 11:12:54 +02:00
String? currentItemTitle,
2022-04-08 21:16:10 +02:00
dynamic notificationId,
}) =>
AndroidDownloadProgressNotification(
progress ?? this.progress,
max,
currentItemTitle: currentItemTitle ?? this.currentItemTitle,
notificationId: notificationId ?? this.notificationId,
);
2022-04-08 21:16:10 +02:00
final int progress;
2021-10-02 11:12:54 +02:00
final int max;
2022-04-08 21:16:10 +02:00
final String? currentItemTitle;
final dynamic notificationId;
2021-10-02 11:12:54 +02:00
}