|
|
@@ -6,6 +6,7 @@ import 'package:electronic_assistant/data/api/request/talk_create_request.dart';
|
|
|
import 'package:electronic_assistant/data/api/request/talk_delete_request.dart';
|
|
|
import 'package:electronic_assistant/data/api/request/talk_file_request.dart';
|
|
|
import 'package:get/get.dart';
|
|
|
+
|
|
|
import '../../utils/http_handler.dart';
|
|
|
import '../api/request/talk_generate_request.dart';
|
|
|
import '../api/request/talk_paginate_request.dart';
|
|
|
@@ -23,6 +24,8 @@ class TalkRepository {
|
|
|
|
|
|
final Set<String> _uploadingTalkIds = {};
|
|
|
|
|
|
+ final Map<String, RxDouble> _uploadingTalkProgress = {};
|
|
|
+
|
|
|
final _talkList = RxList<TalkBean>();
|
|
|
|
|
|
RxList<TalkBean> get talkList => _talkList;
|
|
|
@@ -142,15 +145,30 @@ class TalkRepository {
|
|
|
Future<String> uploadTalkFile(String talkId, double duration, File file) {
|
|
|
_uploadingTalkIds.add(talkId);
|
|
|
return atmobFileApi
|
|
|
- .uploadTalkFile(TalkFileRequest(talkId, duration, file: file).toJson())
|
|
|
+ .uploadTalkFile(TalkFileRequest(talkId, duration, file: file).toJson(),
|
|
|
+ onSendProgress: (count, total) {
|
|
|
+ if (_uploadingTalkProgress[talkId] == null) {
|
|
|
+ _uploadingTalkProgress[talkId] = RxDouble(0);
|
|
|
+ } else {
|
|
|
+ _uploadingTalkProgress[talkId]!.value = count / total;
|
|
|
+ }
|
|
|
+ })
|
|
|
.then(HttpHandler.handle(true))
|
|
|
.then((response) {
|
|
|
- _uploadingTalkIds.remove(talkId);
|
|
|
- return response.taskId;
|
|
|
- }).catchError((error) {
|
|
|
- _uploadingTalkIds.remove(talkId);
|
|
|
- throw error;
|
|
|
- });
|
|
|
+ _uploadingTalkIds.remove(talkId);
|
|
|
+ return response.taskId;
|
|
|
+ })
|
|
|
+ .catchError((error) {
|
|
|
+ _uploadingTalkIds.remove(talkId);
|
|
|
+ throw error;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ RxDouble getUploadProgress(String talkId) {
|
|
|
+ if (_uploadingTalkProgress[talkId] == null) {
|
|
|
+ _uploadingTalkProgress[talkId] = RxDouble(0);
|
|
|
+ }
|
|
|
+ return _uploadingTalkProgress[talkId]!;
|
|
|
}
|
|
|
}
|
|
|
|