Explorar o código

[new]增加生成成功通知

zk hai 1 ano
pai
achega
03139724d5

BIN=BIN
assets/images/icon_home_talk_record_card.webp


BIN=BIN
assets/images/icon_home_talk_select_card.webp


+ 2 - 0
lib/data/repositories/task_repository.dart

@@ -11,6 +11,7 @@ import 'package:flutter/cupertino.dart';
 import '../../dialog/analyse_status_dialog.dart';
 import '../../module/talk/view.dart';
 import '../../utils/http_handler.dart';
+import '../../utils/notification_util.dart';
 import '../api/request/talk_query_request.dart';
 import '../api/response/tasks_running_response.dart';
 import '../consts/error_code.dart';
@@ -105,6 +106,7 @@ class TaskRepository {
     talkRepository.renovateTalkData(element);
     if (element.status.value == TalkStatus.analysisSuccess) {
       debugPrint('生成成功-${element.id}');
+      NotificationUtil.showAnalyseSuccessNotification(element.id);
       showAnalyseSuccessDialog(onViewClick: () {
         TalkPage.start(element);
       });

+ 11 - 5
lib/module/talk/controller.dart

@@ -39,15 +39,16 @@ import '../../data/repositories/talk_repository.dart';
 import '../../dialog/add_agenda_dialog.dart';
 import '../../dialog/alert_dialog.dart';
 import '../../dialog/talk_share_dialog.dart';
+import '../../utils/common_utils.dart';
 import '../../utils/event_bus.dart';
 import '../../utils/system_share_util.dart';
 import '../../utils/toast_util.dart';
-import '../record/controller.dart';
 import 'original/view.dart';
 import 'package:share_plus/share_plus.dart';
 
 class TalkController extends BaseController {
   static const String argumentItem = 'argument_item';
+  static const String argumentTalkId = 'argument_talk_id';
   static const String argumentEventTag = 'argument_event_tag';
 
   final String uploadNoPrompts = "UPLOAD_NO_PROMPTS";
@@ -225,6 +226,15 @@ class TalkController extends BaseController {
     TalkBean? bean = parameters?[argumentItem];
     if (bean != null) {
       talkBean.value = bean;
+    } else {
+      String? talkId = parameters?[argumentTalkId];
+      if (talkId != null) {
+        talkRepository.talkInfo(talkId).then((data) {
+          talkBean.value = data.talkInfo;
+        }).catchError((error) {
+          ErrorHandler.toastError(error);
+        });
+      }
     }
     eventTag = parameters?[argumentEventTag];
   }
@@ -556,10 +566,6 @@ class TalkController extends BaseController {
     }
   }
 
-  void backToSpecificPage(String targetRoute) {
-    Get.until((route) => Get.currentRoute == targetRoute);
-  }
-
   Future<bool> checkLogin() async {
     if (!accountRepository.isLogin.value) {
       bool isLogin = await LoginPage.start(fromType: LoginFromType.talkDetail);

+ 2 - 3
lib/module/talk/original/controller.dart

@@ -24,9 +24,8 @@ class OriginalController extends BaseController {
   @override
   void onReady() {
     super.onReady();
-    _talkStatusListener =
-        talkController.talkBean.value?.status.listen((status) {
-      if (status == TalkStatus.analysisSuccess) {
+    _talkStatusListener = talkController.talkBean.listen((bean) {
+      if (bean?.status.value == TalkStatus.analysisSuccess) {
         requestOriginal();
       }
     });

+ 1 - 2
lib/module/talk/summary/controller.dart

@@ -26,8 +26,7 @@ class SummaryController extends BaseController {
   @override
   void onReady() {
     super.onReady();
-    _talkStatusListener =
-        talkController.talkBean.value?.status.listen((status) {
+    _talkStatusListener = talkController.talkBean.listen((status) {
       _dealTalkUpdate();
     });
     _dealTalkUpdate();

+ 0 - 2
lib/module/talk/todo/controller.dart

@@ -10,9 +10,7 @@ import 'package:flutter/cupertino.dart';
 import 'package:get/get.dart';
 import '../../../data/bean/agenda_list_all_bean.dart';
 import '../../../data/bean/talks.dart';
-import '../../../data/repositories/account_repository.dart';
 import '../../../utils/event_bus.dart';
-import '../../login/view.dart';
 import '../controller.dart';
 
 class TodoController extends BaseController {

+ 13 - 0
lib/module/talk/view.dart

@@ -19,12 +19,25 @@ class TalkPage extends BasePage<TalkController> {
   const TalkPage({super.key});
 
   static void start(TalkBean item, {String eventTag = EventId.id_002}) {
+    if (Get.currentRoute == RoutePath.talkDetail) {
+      Get.back();
+    }
     Get.toNamed(RoutePath.talkDetail, arguments: {
       TalkController.argumentItem: item,
       TalkController.argumentEventTag: eventTag,
     });
   }
 
+  static void startById(String talkId, {String eventTag = ''}) {
+    if (Get.currentRoute == RoutePath.talkDetail) {
+      Get.back();
+    }
+    Get.toNamed(RoutePath.talkDetail, arguments: {
+      TalkController.argumentTalkId: talkId,
+      TalkController.argumentEventTag: eventTag,
+    });
+  }
+
   @override
   Widget buildBody(BuildContext context) {
     return WillPopScope(

+ 6 - 0
lib/utils/common_utils.dart

@@ -1,6 +1,8 @@
 import 'dart:io';
 
 import 'package:electronic_assistant/device/atmob_platform_info.dart';
+import 'package:get/get.dart';
+import 'package:get/get_core/src/get_main.dart';
 
 bool getBoolValue(bool? value) {
   return value ?? false;
@@ -23,3 +25,7 @@ String? getDeviceId() {
   }
   return null;
 }
+
+void backToSpecificPage(String targetRoute) {
+  Get.until((route) => Get.currentRoute == targetRoute);
+}

+ 59 - 0
lib/utils/notification_util.dart

@@ -1,4 +1,7 @@
 import 'package:custom_notification/custom_notification.dart';
+import 'package:electronic_assistant/data/bean/talks.dart';
+import 'package:electronic_assistant/module/talk/view.dart';
+import 'package:flutter_local_notifications/flutter_local_notifications.dart';
 
 class NotificationUtil {
   NotificationUtil._();
@@ -18,4 +21,60 @@ class NotificationUtil {
         notificationId, isRecording, formatDuration(recordDuration),
         channelId: channelId, channelName: channelName);
   }
+
+  static int _analyseNotificationId = 2000;
+
+  static int getAnalyseNotificationId() {
+    return _analyseNotificationId++;
+  }
+
+  static void showAnalyseSuccessNotification(String talkId) async {
+    final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
+        FlutterLocalNotificationsPlugin();
+
+    const AndroidInitializationSettings initializationSettingsAndroid =
+        AndroidInitializationSettings('@mipmap/ic_launcher');
+
+    const InitializationSettings initializationSettings =
+        InitializationSettings(
+      android: initializationSettingsAndroid,
+    );
+
+    await flutterLocalNotificationsPlugin.initialize(
+      initializationSettings,
+      onDidReceiveNotificationResponse:
+          (NotificationResponse notificationResponse) async {
+        if (notificationResponse.payload != null) {
+          TalkPage.startById(notificationResponse.payload!);
+        }
+      },
+    );
+    const AndroidNotificationDetails androidPlatformChannelSpecifics =
+        AndroidNotificationDetails(
+      'talk_analyse_success',
+      '谈话分析通知',
+      channelDescription: '谈话分析成功',
+      importance: Importance.max,
+      priority: Priority.high,
+    );
+
+    const NotificationDetails platformChannelSpecifics =
+        NotificationDetails(android: androidPlatformChannelSpecifics);
+
+    await flutterLocalNotificationsPlugin.show(
+      getAnalyseNotificationId(),
+      '小听谈话分析完成',
+      '老板,谈话分析已完成,快点击查看吧。',
+      platformChannelSpecifics,
+      payload: talkId,
+    );
+  }
+
+// static void showAnalyseResultNotification(
+//     int notificationId, bool isSuccess, String talkId,
+//     {required String channelId, required String channelName}) {
+//   CustomNotification.showAnalyseResultNotification(
+//       notificationId, isSuccess, talkId,
+//       channelId: channelId, channelName: channelName);
+// }
 }

+ 8 - 0
plugin/custom_notification/lib/custom_notification.dart

@@ -11,6 +11,14 @@ class CustomNotification {
         channelId: channelId, channelName: channelName);
   }
 
+  static Future<void> showAnalyseResultNotification(
+      int notificationId, bool isSuccess, String talkId,
+      {required String channelId, required String channelName}) {
+    return CustomNotificationPlatform.instance.showAnalyseResultNotification(
+        notificationId, isSuccess, talkId,
+        channelId: channelId, channelName: channelName);
+  }
+
   static Stream<String> recordActionStream() {
     return CustomNotificationPlatform.instance.recordActionStream();
   }

+ 7 - 0
plugin/custom_notification/lib/custom_notification_platform_interface.dart

@@ -31,6 +31,13 @@ abstract class CustomNotificationPlatform extends PlatformInterface {
         'showRecordNotification() has not been implemented.');
   }
 
+  Future<void> showAnalyseResultNotification(
+      int notificationId, bool isSuccess, String talkId,
+      {required String channelId, required String channelName}) {
+    throw UnimplementedError(
+        'showAnalyseResultNotification() has not been implemented.');
+  }
+
   Stream<String> recordActionStream() {
     throw UnimplementedError('recordActionStream() has not been implemented.');
   }

+ 32 - 0
pubspec.lock

@@ -497,6 +497,30 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "3.0.2"
+  flutter_local_notifications:
+    dependency: "direct main"
+    description:
+      name: flutter_local_notifications
+      sha256: "49eeef364fddb71515bc78d5a8c51435a68bccd6e4d68e25a942c5e47761ae71"
+      url: "https://pub.dev"
+    source: hosted
+    version: "17.2.3"
+  flutter_local_notifications_linux:
+    dependency: transitive
+    description:
+      name: flutter_local_notifications_linux
+      sha256: c49bd06165cad9beeb79090b18cd1eb0296f4bf4b23b84426e37dd7c027fc3af
+      url: "https://pub.dev"
+    source: hosted
+    version: "4.0.1"
+  flutter_local_notifications_platform_interface:
+    dependency: transitive
+    description:
+      name: flutter_local_notifications_platform_interface
+      sha256: "85f8d07fe708c1bdcf45037f2c0109753b26ae077e9d9e899d55971711a4ea66"
+      url: "https://pub.dev"
+    source: hosted
+    version: "7.2.0"
   flutter_plugin_android_lifecycle:
     dependency: transitive
     description:
@@ -1452,6 +1476,14 @@ packages:
       url: "https://pub.dev"
     source: hosted
     version: "2.1.4"
+  timezone:
+    dependency: transitive
+    description:
+      name: timezone
+      sha256: "2236ec079a174ce07434e89fcd3fcda430025eb7692244139a9cf54fdcf1fc7d"
+      url: "https://pub.dev"
+    source: hosted
+    version: "0.9.4"
   timing:
     dependency: transitive
     description:

+ 3 - 0
pubspec.yaml

@@ -139,6 +139,9 @@ dependencies:
   custom_notification:
     path: plugin/custom_notification
 
+  #notification
+  flutter_local_notifications: ^17.2.3
+
 dev_dependencies:
   flutter_test:
     sdk: flutter