|
|
@@ -6,19 +6,30 @@ import 'package:injectable/injectable.dart';
|
|
|
import 'package:keyboard/base/base_controller.dart';
|
|
|
import 'package:keyboard/data/bean/upload_info.dart';
|
|
|
import 'package:keyboard/resource/string.gen.dart';
|
|
|
+import 'package:keyboard/utils/atmob_log.dart';
|
|
|
+import 'package:keyboard/utils/toast_util.dart';
|
|
|
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
|
|
|
|
|
|
+import '../../../../data/api/request/intimacy_reply_analyze_request.dart';
|
|
|
+import '../../../../data/api/response/intimacy_reply_analyze_response.dart';
|
|
|
import '../../../../data/bean/option_select_config.dart';
|
|
|
import '../../../../data/bean/option_select_item.dart';
|
|
|
import '../../../../data/bean/reply_mode.dart';
|
|
|
+import '../../../../data/repository/account_repository.dart';
|
|
|
+import '../../../../data/repository/intimacy_analyze_repository.dart';
|
|
|
+import '../../../../utils/error_handler.dart';
|
|
|
+import '../../../../utils/http_handler.dart';
|
|
|
import '../../../../utils/image_picker_util.dart';
|
|
|
import '../../../../utils/intimacy_analyze_config_helper.dart';
|
|
|
import '../../../../utils/upload/upload_file_manager.dart';
|
|
|
import '../../../../utils/upload/upload_scene_type.dart';
|
|
|
+import '../../../store/store_page.dart';
|
|
|
|
|
|
/// 识图回复Controller
|
|
|
@injectable
|
|
|
class ScanImageReplyController extends BaseController {
|
|
|
+ final String _tag = "ScanImageReplyController";
|
|
|
+
|
|
|
/// 上传场景
|
|
|
final UploadSceneType uploadSceneType = UploadSceneType.scanImageReply;
|
|
|
|
|
|
@@ -28,6 +39,11 @@ class ScanImageReplyController extends BaseController {
|
|
|
/// 文件上传管理器
|
|
|
UploadFileManager uploadFileManager;
|
|
|
|
|
|
+ /// 亲密度分析模块的Repository
|
|
|
+ IntimacyAnalyzeRepository intimacyAnalyzeRepository;
|
|
|
+
|
|
|
+ AccountRepository accountRepository;
|
|
|
+
|
|
|
/// 回复语气选项列表
|
|
|
RxList<OptionSelectConfig> replyToneOptionSelectConfigList =
|
|
|
<OptionSelectConfig>[].obs;
|
|
|
@@ -48,11 +64,13 @@ class ScanImageReplyController extends BaseController {
|
|
|
Rxn<ReplyMode> currentReplyMode = Rxn();
|
|
|
|
|
|
/// 回复语气列表
|
|
|
- RxList<String> replyToneList = <String>["真好", "真好看", "真的很好看~"].obs;
|
|
|
+ RxList<String> replyToneList = <String>[].obs;
|
|
|
|
|
|
ScanImageReplyController(
|
|
|
this.intimacyAnalyzeConfigHelper,
|
|
|
this.uploadFileManager,
|
|
|
+ this.intimacyAnalyzeRepository,
|
|
|
+ this.accountRepository,
|
|
|
);
|
|
|
|
|
|
@override
|
|
|
@@ -84,7 +102,9 @@ class ScanImageReplyController extends BaseController {
|
|
|
|
|
|
/// 初始化回复模式
|
|
|
void _initReplyModeList() {
|
|
|
- var modeList = intimacyAnalyzeConfigHelper.intimacyAnalyzeReplyConfig.value?.modes ?? [];
|
|
|
+ var modeList =
|
|
|
+ intimacyAnalyzeConfigHelper.intimacyAnalyzeReplyConfig.value?.modes ??
|
|
|
+ [];
|
|
|
replyModelList.addAll(modeList);
|
|
|
replyModelList.refresh();
|
|
|
|
|
|
@@ -139,7 +159,64 @@ class ScanImageReplyController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/// 点击获取回复按钮
|
|
|
- void clickGetReplyBtn() {}
|
|
|
+ void clickGetReplyBtn() async {
|
|
|
+ // 非Vip,跳转到商店页
|
|
|
+ bool isVip = accountRepository.memberStatusInfo.value?.isMember ?? false;
|
|
|
+ if (!isVip) {
|
|
|
+ ToastUtil.show(StringName.needVipTip);
|
|
|
+ StorePage.start();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上传的图片后端地址
|
|
|
+ List<String> imageList = [uploadInfo.value?.fileBackendPath ?? ""];
|
|
|
+ // 选择的回复语气
|
|
|
+ String title = currentSelectReplyToneOption.value?.name ?? "";
|
|
|
+ // 当前选择的回复模式
|
|
|
+ String mode = currentReplyMode.value?.value ?? "";
|
|
|
+
|
|
|
+ if (imageList.isEmpty) {
|
|
|
+ ToastUtil.show(StringName.noUploadScreenshotTip);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (title.isEmpty) {
|
|
|
+ ToastUtil.show(StringName.noChooseReplyToneTip);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (mode.isEmpty) {
|
|
|
+ ToastUtil.show(StringName.noChooseModeTip);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 请求分析截图
|
|
|
+ IntimacyReplyAnalyzeResponse response = await intimacyAnalyzeRepository
|
|
|
+ .intimacyReplyAnalyze(
|
|
|
+ IntimacyReplyAnalyzeRequest(imageList, title, mode),
|
|
|
+ );
|
|
|
+ var newList =
|
|
|
+ response.choices?.map((item) {
|
|
|
+ return item.delta?.content ?? "";
|
|
|
+ }) ??
|
|
|
+ [];
|
|
|
+ replyToneList.clear();
|
|
|
+ replyToneList.addAll(newList);
|
|
|
+ replyToneList.refresh();
|
|
|
+ } catch (error) {
|
|
|
+ AtmobLog.e(_tag, error.toString());
|
|
|
+ if (error is ServerErrorException) {
|
|
|
+ // 需要Vip权限
|
|
|
+ if (error.code == 1005) {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ StorePage.start();
|
|
|
+ } else {
|
|
|
+ ToastUtil.show(error.message);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ErrorHandler.toastError(error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
/// 删除上传信息
|
|
|
void deleteUploadInfo(UploadInfo info) {
|