Forráskód Böngészése

[new]调整谈话分享流程

zk 1 éve
szülő
commit
b3388ab39c

BIN
assets/images/icon_share_file_png.webp


+ 8 - 3
lib/dialog/talk_share_dialog.dart

@@ -21,7 +21,7 @@ void showTalkShareDialog(String? title, TalkShareCallback callback) {
     if (shareType.value == ShareTalkType.summary) {
       return '[${StringName.talkTabSummary.tr}] $title.txt';
     } else if (shareType.value == ShareTalkType.mindMap) {
-      return '[${StringName.talkMindMap.tr}] $title.png';
+      return '$title.png';
     } else {
       return '[${StringName.talkTabOriginal.tr}] $title.txt';
     }
@@ -44,8 +44,13 @@ void showTalkShareDialog(String? title, TalkShareCallback callback) {
                 children: [
                   Row(
                     children: [
-                      Assets.images.iconTalkTxt
-                          .image(width: 28.w, height: 32.w),
+                      Obx(() {
+                        return shareType.value == ShareTalkType.mindMap
+                            ? Assets.images.iconShareFilePng
+                                .image(width: 28.w, height: 32.w)
+                            : Assets.images.iconTalkTxt
+                                .image(width: 28.w, height: 32.w);
+                      }),
                       SizedBox(width: 6.w),
                       Expanded(child: Obx(() {
                         return Text(getFileName(),

+ 43 - 14
lib/module/talk/controller.dart

@@ -638,17 +638,46 @@ class TalkController extends BaseController {
     }
     eventReport(EventId.event_101004);
     showTalkShareDialog(talkBean.value?.title.value,
-        (type, shareTo, fileName, tag) {
-      if (type == ShareTalkType.summary || type == ShareTalkType.original) {
-        _shareSummaryOrOriginal(
-            talkBean.value!.id, fileName, type, shareTo, tag);
-      } else if (type == ShareTalkType.mindMap) {
-        _shareMindMap(fileName, talkBean.value?.summary.value);
+        (type, shareTo, fileName, tag) async {
+      try {
+        await isInstalled(shareTo);
+        if (type == ShareTalkType.summary || type == ShareTalkType.original) {
+          _shareSummaryOrOriginal(
+              talkBean.value!.id, fileName, type, shareTo, tag);
+        } else if (type == ShareTalkType.mindMap) {
+          _shareMindMap(fileName, talkBean.value?.summary.value, tag);
+        }
+      } catch (error) {
+        if (error is SystemShareException) {
+          ToastUtil.showToast(error.message);
+        } else {
+          ErrorHandler.toastError(error);
+        }
       }
     });
   }
 
-  void _shareMindMap(String title, String? summary) {
+  Future<bool> isInstalled(ShareTo shareTo) async {
+    if (shareTo == ShareTo.wechat) {
+      bool isInstalled =
+          await SystemShareUtil.isInstalled(SystemShareUtil.wechatPageName);
+      if (!isInstalled) {
+        throw SystemShareException('未安装微信');
+      }
+    } else if (shareTo == ShareTo.qq) {
+      bool isInstalled =
+          await SystemShareUtil.isInstalled(SystemShareUtil.qqPageName);
+      if (!isInstalled) {
+        throw SystemShareException('未安装QQ');
+      }
+    }
+    // else if(shareTo == ShareTo.ios){
+    //    //ios不用判断
+    // }
+    return true;
+  }
+
+  void _shareMindMap(String title, String? summary, String tag) {
     if (_temporaryController.value != null) {
       _temporaryController.value?.dispose();
       _temporaryController.value = null;
@@ -690,17 +719,17 @@ class TalkController extends BaseController {
       if (shareTo == ShareTo.ios) {
         await Share.shareXFiles([XFile(file.path)], subject: fileName);
       } else if (shareTo == ShareTo.wechat) {
-        await SystemShareUtil.shareWechatFile(file.path);
+        await SystemShareUtil.shareSystemFile(
+            SystemShareUtil.wechatPageName, file.path,
+            shareTitle: '分享到微信', shareFileType: 'text/*');
       } else if (shareTo == ShareTo.qq) {
-        await SystemShareUtil.shareQQFile(file.path);
+        await SystemShareUtil.shareSystemFile(
+            SystemShareUtil.qqPageName, file.path,
+            shareTitle: '分享到QQ', shareFileType: 'text/*');
       }
       SmartDialog.dismiss(tag: tag);
     }).catchError((error) {
-      if (error is SystemShareException) {
-        ToastUtil.showToast(error.message);
-      } else {
-        ErrorHandler.toastError(error);
-      }
+      throw error;
     });
   }
 

+ 6 - 21
lib/utils/system_share_util.dart

@@ -5,29 +5,14 @@ import 'package:system_share/system_share.dart';
 class SystemShareUtil {
   SystemShareUtil._();
 
-  static Future<void> shareWechatFile(String filePath) async {
-    if (Platform.isAndroid) {
-      String wechatPackageName = 'com.tencent.mm';
-      //检查是否安装微信
-      bool isInstalled = await SystemShare.isInstalled(wechatPackageName);
-      if (!isInstalled) {
-        throw SystemShareException('未安装微信');
-      }
-      SystemShare.shareFile(filePath, wechatPackageName, '分享到微信',
-          shareFileType: 'text/*');
-    }
-  }
+  static const wechatPageName = 'com.tencent.mm';
+  static const qqPageName = 'com.tencent.mobileqq';
 
-  static Future<void> shareQQFile(String filePath) async {
+  static Future<void> shareSystemFile(String packageName, String filePath,
+      {String? shareTitle, String? shareFileType}) async {
     if (Platform.isAndroid) {
-      String qqPackageName = 'com.tencent.mobileqq';
-      //检查是否安装微信
-      bool isInstalled = await SystemShare.isInstalled(qqPackageName);
-      if (!isInstalled) {
-        throw SystemShareException('未安装QQ');
-      }
-      SystemShare.shareFile(filePath, qqPackageName, '分享到QQ',
-          shareFileType: 'text/*');
+      return SystemShare.shareFile(filePath, packageName, shareTitle,
+          shareFileType: shareFileType);
     }
   }
 

+ 3 - 2
plugin/system_share/lib/system_share.dart

@@ -9,9 +9,10 @@ class SystemShare {
     return SystemSharePlatform.instance.isInstalled(packageName);
   }
 
-  static void shareFile(String filePath, String packageName, String? shareTitle,
+  static Future<void> shareFile(
+      String filePath, String packageName, String? shareTitle,
       {String? shareFileType}) {
-    SystemSharePlatform.instance.shareFile(
+    return SystemSharePlatform.instance.shareFile(
         filePath, packageName, shareTitle, shareFileType: shareFileType);
   }
 }

+ 4 - 3
plugin/system_share/lib/system_share_method_channel.dart

@@ -17,9 +17,10 @@ class MethodChannelSystemShare extends SystemSharePlatform {
   }
 
   @override
-  void shareFile(String filePath, String packageName, String? shareTitle,
-      {String? shareFileType}) {
-    methodChannel.invokeMethod("shareFile", {
+  Future<void> shareFile(
+      String filePath, String packageName, String? shareTitle,
+      {String? shareFileType}) async {
+    return await methodChannel.invokeMethod("shareFile", {
       "filePath": filePath,
       "packageName": packageName,
       "shareTitle": shareTitle,

+ 2 - 1
plugin/system_share/lib/system_share_platform_interface.dart

@@ -29,7 +29,8 @@ abstract class SystemSharePlatform extends PlatformInterface {
     throw UnimplementedError('isInstalled() has not been implemented.');
   }
 
-  void shareFile(String filePath, String packageName, String? shareTitle,
+  Future<void> shareFile(
+      String filePath, String packageName, String? shareTitle,
       {String? shareFileType}) async {
     throw UnimplementedError('shareFile() has not been implemented.');
   }