Skip to content

Commit

Permalink
Merge pull request OpenFlutter#172 from lichfy/master
Browse files Browse the repository at this point in the history
分享文件
  • Loading branch information
JarvanMo authored Dec 20, 2019
2 parents b92a06b + 1562fd3 commit 7c9e7c7
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 1 deletion.
Binary file added android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Tue Aug 13 10:22:39 CST 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class WeChatPluginMethods {
public static final String SHARE_VIDEO = "shareVideo";
public static final String SHARE_WEB_PAGE = "shareWebPage";
public static final String SHARE_MINI_PROGRAM = "shareMiniProgram";
public static final String SHARE_FILE = "shareFile";

public static final String LAUNCH_MINI_PROGRAM = "launchMiniProgram";
public static final String PAY = "payWithFluwx";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ internal class FluwxShareHandler {
WeChatPluginMethods.SHARE_MUSIC -> shareMusic(call, result)
WeChatPluginMethods.SHARE_VIDEO -> shareVideo(call, result)
WeChatPluginMethods.SHARE_WEB_PAGE -> shareWebPage(call, result)
WeChatPluginMethods.SHARE_FILE -> shareFile(call,result)
else -> {
result.notImplemented()
}
Expand Down Expand Up @@ -359,6 +360,36 @@ internal class FluwxShareHandler {
}
}

private fun shareFile(call:MethodCall,result:MethodChannel.Result){
val file = WXFileObject()
val filePath:String? = call.argument("filePath")
file.filePath = filePath

val msg = WXMediaMessage()
msg.mediaObject = file
msg.title = call.argument("title")
msg.description = call.argument("description")
val thumbnail: String? = call.argument("thumbnail")

GlobalScope.launch(Dispatchers.Main, CoroutineStart.DEFAULT) {
if (thumbnail != null && thumbnail.isNotBlank()) {
msg.thumbData = getThumbnailByteArrayCommon(registrar, thumbnail)
}

val req = SendMessageToWX.Req()
setCommonArguments(call, req, msg)
req.message = msg
val done = WXAPiHandler.wxApi?.sendReq(req)
result.success(
mapOf(
WechatPluginKeys.PLATFORM to WechatPluginKeys.ANDROID,
WechatPluginKeys.RESULT to done
)
)
}

}

// private fun createWxImageObject(imagePath:String):WXImageObject?{
// var imgObj: WXImageObject? = null
// var imageFile:File? = null
Expand Down
13 changes: 13 additions & 0 deletions doc/SHARE.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,16 @@ Two kind of video:`videoUrl`和`videoLowBandUrl`.They are not coexisting,if bo
fluwx.share(model);
```

### Share File

```dart
var model = fluwx.WeChatShareFileModel(
filePath: _filePath,
scene: scene,
title: _title,
description: _description
);
fluwx.share(model);
```
File size is limited and cannot exceed 10M

13 changes: 13 additions & 0 deletions doc/SHARE_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,16 @@
);
fluwx.share(model);
```

### 分享文件

```dart
var model = fluwx.WeChatShareFileModel(
filePath: _filePath,
scene: scene,
title: _title,
description: _description
);
fluwx.share(model);
```
文件有大小限制,不能超过10M;文件路径还要考虑权限
1 change: 1 addition & 0 deletions ios/Classes/constants/FluwxMethods.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ extern NSString *const shareImage;
extern NSString *const shareMusic;
extern NSString *const shareVideo;
extern NSString *const shareWebPage;
extern NSString *const shareFile;
extern NSString *const shareMiniProgram;
extern NSString *const launchMiniProgram;

Expand Down
1 change: 1 addition & 0 deletions ios/Classes/constants/FluwxMethods.m
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
NSString *const shareImage = @"shareImage";
NSString *const shareMusic = @"shareMusic";
NSString *const shareVideo = @"shareVideo";
NSString *const shareFile = @"shareFile";
NSString *const shareWebPage = @"shareWebPage";
NSString *const shareMiniProgram = @"shareMiniProgram";
NSString *const LaunchMiniProgram = @"launchMiniProgram";
Expand Down
24 changes: 24 additions & 0 deletions ios/Classes/handler/FluwxShareHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ - (void)handleShare:(FlutterMethodCall *)call result:(FlutterResult)result {
[self shareVideo:call result:result];
} else if ([shareMiniProgram isEqualToString:call.method]) {
[self shareMiniProgram:call result:result];
} else if([shareFile isEqualToString:call.method]){
[self shareFile:call result:result];
}


Expand Down Expand Up @@ -371,6 +373,28 @@ - (void)shareVideo:(FlutterMethodCall *)call result:(FlutterResult)result {

}

- (void)shareFile:(FlutterMethodCall *)call result:(FlutterResult)result {
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
NSString *thumbnail = call.arguments[fluwxKeyThumbnail];
UIImage *thumbnailImage = [self getThumbnail:thumbnail size:32 * 1024];

NSString *filePath = call.arguments[@"filePath"];
NSData *data = [NSData dataWithContentsOfFile:filePath];

dispatch_async(dispatch_get_main_queue(), ^{
NSString *scene = call.arguments[fluwxKeyScene];
BOOL done = [WXApiRequestHandler sendFileData:data
fileExtension:call.arguments[@"fileExtension"]
Title:call.arguments[fluwxKeyTitle]
Description:call.arguments[fluwxKeyDescription]
ThumbImage:thumbnailImage
InScene:[StringToWeChatScene toScene:scene]];
result(@{fluwxKeyPlatform: fluwxKeyIOS, fluwxKeyResult: @(done)});
});
});
}

- (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
Expand Down
3 changes: 2 additions & 1 deletion lib/src/fluwx_iml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,8 @@ const Map<Type, String> _shareModelMethodMapper = {
WeChatShareMusicModel: "shareMusic",
WeChatShareVideoModel: "shareVideo",
WeChatShareWebPageModel: "shareWebPage",
WeChatShareMiniProgramModel: "shareMiniProgram"
WeChatShareMiniProgramModel: "shareMiniProgram",
WeChatShareFileModel:"shareFile",
};

const Map<int, AuthByQRCodeErrorCode> _authByQRCodeErrorCodes = {
Expand Down
45 changes: 45 additions & 0 deletions lib/src/models/wechat_share_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -385,3 +385,48 @@ class WeChatShareWebPageModel extends WeChatShareModel {
};
}
}

class WeChatShareFileModel extends WeChatShareModel {
final String transaction;
final String filePath;
final String fileExtension;
final String thumbnail;
final String title;
final String description;

WeChatShareFileModel({
String transaction,
this.filePath,
this.fileExtension:"pdf",
this.title: "",
this.description: "",
String thumbnail,
WeChatScene scene,
String messageExt,
String messageAction,
String mediaTagName,
}) : this.transaction = transaction ?? "text",
this.thumbnail = thumbnail ?? "",
assert(filePath != null),
super(
mediaTagName: mediaTagName,
messageAction: messageAction,
messageExt: messageExt,
scene: scene);

@override
Map toMap() {
return {
_transaction: transaction,
_scene: scene.toString(),
"filePath": filePath,
"fileExtension": fileExtension,
_thumbnail: thumbnail,
_title: title,
_description: description,
_mediaTagName: mediaTagName,
_messageAction: messageAction,
_messageExt: messageExt,
};
}
}

0 comments on commit 7c9e7c7

Please sign in to comment.