Kaynağa Gözat

[new]增加分析进度

zk 1 yıl önce
ebeveyn
işleme
59f8594872

+ 11 - 0
lib/data/bean/talks.dart

@@ -47,6 +47,13 @@ class TalkBean {
   @JsonKey(name: 'uploadType')
   int? uploadType;
 
+  @JsonKey(name: 'progress', fromJson: _intFromJson, includeToJson: false)
+  Rxn<int> progress = Rxn(0);
+
+  @JsonKey(
+      name: 'progressContent', fromJson: _stringFromJson, includeToJson: false)
+  Rxn<String> progressContent = Rxn('');
+
   TalkBean({
     required this.id,
     this.taskId,
@@ -62,6 +69,8 @@ class TalkBean {
     this.oversizeFile,
     this.uploadType,
     this.localAudioUrl,
+    required this.progress,
+    required this.progressContent,
   });
 
   factory TalkBean.fromJson(Map<String, dynamic> json) =>
@@ -85,6 +94,8 @@ class TalkBean {
     oversizeFile = talkBean.oversizeFile;
     uploadType = talkBean.uploadType;
     localAudioUrl = talkBean.localAudioUrl;
+    progress.value = talkBean.progress.value;
+    progressContent.value = talkBean.progressContent.value;
   }
 }
 

+ 2 - 6
lib/data/repositories/talk_repository.dart

@@ -200,15 +200,11 @@ class TalkRepository {
         notificationTitle: '正在上传录音',
         notificationText: '请勿关闭应用',
         callback: setUploadCallback);
-    _uploadingTalkProgress[talkId] = RxDouble(0);
+    RxDouble progressRx = getUploadProgress(talkId);
     return atmobFileApi
         .uploadTalkFile(TalkFileRequest(talkId, duration, file: file).toJson(),
             onSendProgress: (count, total) {
-          if (_uploadingTalkProgress[talkId] == null) {
-            _uploadingTalkProgress[talkId] = RxDouble(0);
-          } else {
-            _uploadingTalkProgress[talkId]!.value = count / total;
-          }
+          progressRx.value = count / total;
         })
         .then(HttpHandler.handle(true))
         .then((response) {

+ 30 - 0
lib/module/talk/common_view.dart

@@ -10,6 +10,7 @@ import '../../data/bean/agenda.dart';
 import '../../resource/assets.gen.dart';
 import '../../resource/colors.gen.dart';
 import '../../resource/string.gen.dart';
+import '../../utils/gradient_rounded_linear_progress_bar.dart';
 
 Widget getAddAgendaView(String addTxt, {VoidCallback? onClick}) {
   return GestureDetector(
@@ -38,6 +39,35 @@ Widget getAddAgendaView(String addTxt, {VoidCallback? onClick}) {
   );
 }
 
+//
+Widget getTalkAnalyseView(String analyseTxt, double progress) {
+  return SizedBox(
+    width: double.infinity,
+    child: Column(
+      children: [
+        SizedBox(height: 138.h),
+        SizedBox(
+            width: 100.w,
+            height: 100.w,
+            child: Assets.anim.talkAnalyse.image()),
+        SizedBox(height: 24.h),
+        GradientRoundedLinearProgressBar(
+          height: 12.w,
+          width: 220.w,
+          borderRadius: 10,
+          backgroundColor: '#F6F5F8'.toColor(),
+          progress: progress / 100,
+          gradientColors: ["#9075FF".toColor(), "#4366FF".toColor()],
+        ),
+        SizedBox(height: 10.h),
+        Text('$analyseTxt  $progress%',
+            style:
+                TextStyle(fontSize: 12.sp, color: ColorName.secondaryTextColor))
+      ],
+    ),
+  );
+}
+
 Widget getTalkUploadingView(RxDouble progress) {
   return SizedBox(
     width: double.infinity,

+ 29 - 21
lib/module/talk/controller.dart

@@ -1,4 +1,5 @@
 import 'dart:async';
+import 'dart:ffi';
 import 'dart:io';
 
 import 'package:connectivity_plus/connectivity_plus.dart';
@@ -55,6 +56,9 @@ class TalkController extends BaseController {
 
   final Rxn<TalkBean> talkBean = Rxn();
 
+  StreamSubscription? _talkUploadListener;
+  final RxDouble uploadProgress = RxDouble(0);
+
   final isShowElectricLow = false.obs;
 
   bool isAudioLoading = false;
@@ -112,6 +116,7 @@ class TalkController extends BaseController {
     return _agendaNameController!;
   }
 
+  String? paramId;
   String? eventTag;
 
   bool isLocalFileHas = false;
@@ -121,17 +126,11 @@ class TalkController extends BaseController {
   @override
   void onReady() {
     super.onReady();
-
     _initAudioPlayer();
-    _initListener();
     _getArguments();
     eventReport(EventId.event_101001, params: {EventId.id: eventTag});
   }
 
-  RxDouble getUploadingProgress() {
-    return talkRepository.getUploadProgress(talkBean.value!.id);
-  }
-
   void eventReport(String eventId, {Map<String, dynamic>? params}) {
     if (talkBean.value == null || talkBean.value?.isExample == true) {
       return;
@@ -177,24 +176,27 @@ class TalkController extends BaseController {
     });
   }
 
-  void _initListener() {
-    _talkBeanListener = talkBean.listen((bean) {
-      _dealTalkUpdate(bean);
-    });
-  }
-
-  void _dealTalkUpdate(TalkBean? bean) async {
-    String? id = talkBean.value?.id;
+  void _dealTalk(TalkBean? bean) async {
+    String? id = bean?.id;
     if (id == null) {
       return;
     }
-    if (talkRepository.isUploadingTalk(id) &&
-        talkBean.value?.status.value == TalkStatus.notAnalysis) {
+    _loadAudioFile(bean);
+    if (bean?.status.value == TalkStatus.notAnalysis) {
+      setUploadingProgress(id);
+    }
+    if (bean?.status.value == TalkStatus.notAnalysis &&
+        talkRepository.isUploadingTalk(id)) {
       isUploading.value = true;
     } else {
       isUploading.value = false;
     }
-    _loadAudioFile(bean);
+  }
+
+  void setUploadingProgress(String id) {
+    talkRepository.getUploadProgress(id).listen((progress) {
+      uploadProgress.value = (progress * 20).toFormattedDouble(1);
+    });
   }
 
   Future<void> _loadAudioFile(TalkBean? bean, {bool? loadPlay}) async {
@@ -226,11 +228,13 @@ class TalkController extends BaseController {
     TalkBean? bean = parameters?[argumentItem];
     if (bean != null) {
       talkBean.value = bean;
+      _dealTalk(bean);
     } else {
-      String? talkId = parameters?[argumentTalkId];
-      if (talkId != null) {
-        talkRepository.talkInfo(talkId).then((data) {
+      paramId = parameters?[argumentTalkId];
+      if (paramId != null) {
+        talkRepository.talkInfo(paramId!).then((data) {
           talkBean.value = data.talkInfo;
+          _dealTalk(data.talkInfo);
         }).catchError((error) {
           ErrorHandler.toastError(error);
         });
@@ -390,7 +394,7 @@ class TalkController extends BaseController {
         isShowElectricLow.value = true;
       }
     }).catchError((error) {
-      ToastUtil.showToast(error);
+      ErrorHandler.toastError(error);
     });
   }
 
@@ -405,6 +409,9 @@ class TalkController extends BaseController {
     WakelockPlus.enable();
     talkRepository.uploadTalkFile(talkId, duration, file).then((taskId) {
       isUploadedFile = true;
+      isUploading.value = false;
+      talkBean.value?.progressContent.value = '录音上传中,请勿关闭小听';
+      talkBean.value?.progress.value = 20;
       talkBean.value?.status.value = TalkStatus.analysing;
       taskRepository.addTask(taskId);
     }).catchError((error) {
@@ -611,6 +618,7 @@ class TalkController extends BaseController {
   @override
   void onClose() {
     super.onClose();
+    _talkUploadListener?.cancel();
     _talkBeanListener?.cancel();
     _audioPlayer.dispose();
     _agendaContentController?.dispose();

+ 9 - 1
lib/module/talk/original/controller.dart

@@ -18,17 +18,24 @@ class OriginalController extends BaseController {
 
   final originalList = <TalkOriginal>[].obs;
 
+  StreamSubscription? _talkBeanListener;
   StreamSubscription? _talkStatusListener;
   StreamSubscription? _audioPlayingListener;
 
   @override
   void onReady() {
     super.onReady();
-    _talkStatusListener = talkController.talkBean.listen((bean) {
+    _talkBeanListener = talkController.talkBean.listen((bean) {
       if (bean?.status.value == TalkStatus.analysisSuccess) {
         requestOriginal();
       }
     });
+    _talkStatusListener =
+        talkController.talkBean.value?.status.listen((status) {
+      if (status == TalkStatus.analysisSuccess) {
+        requestOriginal();
+      }
+    });
     requestOriginal();
     setPlayAutoSelection();
   }
@@ -100,6 +107,7 @@ class OriginalController extends BaseController {
   @override
   void onClose() {
     super.onClose();
+    _talkBeanListener?.cancel();
     _talkStatusListener?.cancel();
     _audioPlayingListener?.cancel();
   }

+ 15 - 1
lib/module/talk/original/view.dart

@@ -28,7 +28,21 @@ class OriginalView extends BasePage<OriginalController> {
               TalkStatus.analysisFail) {
         return getTalkFailView();
       } else if (controller.originalList.isEmpty) {
-        return getTalkLoadingView();
+        return getTalkAnalyseView(
+            controller.talkController.isUploading.value == true &&
+                    controller.talkController.talkBean.value?.status.value ==
+                        TalkStatus.notAnalysis
+                ? '录音上传中,请勿关闭小听'
+                : controller
+                        .talkController.talkBean.value?.progressContent.value ??
+                    '',
+            controller.talkController.isUploading.value == true &&
+                    controller.talkController.talkBean.value?.status.value ==
+                        TalkStatus.notAnalysis
+                ? controller.talkController.uploadProgress.value
+                : controller.talkController.talkBean.value?.progress.value
+                        ?.toDouble() ??
+                    0.0);
       } else {
         return ListView.builder(
           padding: EdgeInsets.only(bottom: 150.h),

+ 18 - 2
lib/module/talk/summary/view.dart

@@ -122,8 +122,24 @@ class SummaryView extends BasePage<SummaryController> {
       } else if (controller.summaryBean.value?.status.value ==
               TalkStatus.analysing ||
           controller.summaryBean.value?.status.value ==
-              TalkStatus.waitAnalysis) {
-        return getTalkLoadingView();
+              TalkStatus.waitAnalysis ||
+          controller.summaryBean.value?.status.value ==
+              TalkStatus.notAnalysis) {
+        return getTalkAnalyseView(
+            controller.talkController.isUploading.value == true &&
+                    controller.talkController.talkBean.value?.status.value ==
+                        TalkStatus.notAnalysis
+                ? '录音上传中,请勿关闭小听'
+                : controller
+                        .talkController.talkBean.value?.progressContent.value ??
+                    '',
+            controller.talkController.isUploading.value == true &&
+                    controller.talkController.talkBean.value?.status.value ==
+                        TalkStatus.notAnalysis
+                ? controller.talkController.uploadProgress.value
+                : controller.talkController.talkBean.value?.progress.value
+                        ?.toDouble() ??
+                    0.0);
       } else {
         return Container();
       }

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

@@ -30,6 +30,8 @@ class TodoController extends BaseController {
 
   bool get isEditModel => _talkController.isEditModelRx.value;
 
+  TalkController get talkController => _talkController;
+
   @override
   void onReady() {
     super.onReady();

+ 17 - 2
lib/module/talk/todo/view.dart

@@ -177,8 +177,23 @@ class TodoView extends BasePage<TodoController> {
       return getTalkFailView();
     } else if (controller.talkBean.value?.status.value ==
             TalkStatus.analysing ||
-        controller.talkBean.value?.status.value == TalkStatus.waitAnalysis) {
-      return getTalkLoadingView();
+        controller.talkBean.value?.status.value == TalkStatus.waitAnalysis ||
+        controller.talkBean.value?.status.value == TalkStatus.notAnalysis) {
+      return getTalkAnalyseView(
+          controller.talkController.isUploading.value == true &&
+                  controller.talkController.talkBean.value?.status.value ==
+                      TalkStatus.notAnalysis
+              ? '录音上传中,请勿关闭小听'
+              : controller
+                      .talkController.talkBean.value?.progressContent.value ??
+                  '',
+          controller.talkController.isUploading.value == true &&
+                  controller.talkController.talkBean.value?.status.value ==
+                      TalkStatus.notAnalysis
+              ? controller.talkController.uploadProgress.value
+              : controller.talkController.talkBean.value?.progress.value
+                      ?.toDouble() ??
+                  0.0);
     } else if (controller.talkBean.value?.status.value ==
         TalkStatus.analysisSuccess) {
       return _buildTodoContent();

+ 2 - 6
lib/module/talk/view.dart

@@ -212,11 +212,10 @@ class TalkPage extends BasePage<TalkController> {
 
   Widget buildTalkContentView() {
     return Obx(() {
-      if (controller.talkBean.value?.status.value == TalkStatus.notAnalysis) {
+      if (controller.talkBean.value?.status.value == TalkStatus.notAnalysis &&
+          controller.isUploading.value != true) {
         if (controller.isShowElectricLow.value) {
           return buildElectricLowView();
-        } else if (controller.isUploading.value == true) {
-          return buildElectricUploading();
         } else {
           return buildNotAnalysisView();
         }
@@ -226,9 +225,6 @@ class TalkPage extends BasePage<TalkController> {
     });
   }
 
-  Widget buildElectricUploading() {
-    return getTalkUploadingView(controller.getUploadingProgress());
-  }
 
   Widget buildTabContentView() {
     return Expanded(

+ 4 - 0
lib/utils/expand.dart

@@ -111,4 +111,8 @@ extension DoubleExtension on double {
       return toStringAsFixed(fractionDigits);
     }
   }
+
+  double toFormattedDouble(int fractionDigits) {
+    return double.parse(toStringAsFixed(fractionDigits));
+  }
 }

+ 47 - 0
lib/utils/gradient_rounded_linear_progress_bar.dart

@@ -0,0 +1,47 @@
+import 'package:flutter/material.dart';
+
+class GradientRoundedLinearProgressBar extends StatelessWidget {
+  final double progress;
+  final double height;
+  final double width;
+  final Color backgroundColor;
+  final List<Color> gradientColors;
+  final double borderRadius;
+
+  const GradientRoundedLinearProgressBar({
+    super.key,
+    required this.progress,
+    this.height = 12.0,
+    this.width = 220.0,
+    this.backgroundColor = Colors.grey,
+    required this.gradientColors,
+    this.borderRadius = 8.0,
+  });
+
+  @override
+  Widget build(BuildContext context) {
+    return ClipRRect(
+      borderRadius: BorderRadius.circular(borderRadius),
+      child: Container(
+        height: height,
+        width: width,
+        color: backgroundColor,
+        child: Stack(
+          children: [
+            Container(
+              width: progress * width,
+              decoration: BoxDecoration(
+                borderRadius: BorderRadius.circular(borderRadius),
+                gradient: LinearGradient(
+                  colors: gradientColors,
+                  begin: Alignment.centerLeft,
+                  end: Alignment.centerRight,
+                ),
+              ),
+            ),
+          ],
+        ),
+      ),
+    );
+  }
+}