Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@
## 1.2.1

* Improved package classes & methods documentation
* Moved SnapchatButton to it's own file
* Moved SnapchatButton to it's own file

## 1.2.2
44 changes: 30 additions & 14 deletions android/src/main/java/com/jacobbrasil/snapkit/SnapkitPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
import com.snapchat.kit.sdk.creative.api.SnapCreativeKitApi;
import com.snapchat.kit.sdk.creative.exceptions.SnapMediaSizeException;
import com.snapchat.kit.sdk.creative.exceptions.SnapStickerSizeException;
import com.snapchat.kit.sdk.creative.exceptions.SnapVideoLengthException;
import com.snapchat.kit.sdk.creative.media.SnapMediaFactory;
import com.snapchat.kit.sdk.creative.media.SnapPhotoFile;
import com.snapchat.kit.sdk.creative.media.SnapSticker;
import com.snapchat.kit.sdk.creative.media.SnapVideoFile;
import com.snapchat.kit.sdk.creative.models.SnapContent;
import com.snapchat.kit.sdk.creative.models.SnapLiveCameraContent;
import com.snapchat.kit.sdk.creative.models.SnapPhotoContent;
import com.snapchat.kit.sdk.creative.models.SnapVideoContent;
import com.snapchat.kit.sdk.login.models.MeData;
import com.snapchat.kit.sdk.login.models.UserDataResponse;
import com.snapchat.kit.sdk.login.networking.FetchUserDataCallback;
Expand Down Expand Up @@ -115,8 +118,19 @@ public void onFailure(boolean isNetworkError, int statusCode) {
}

break;
// case "VIDEO":
// break;
case "VIDEO":
try {
SnapVideoFile videoFile = this.mediaFactory.getSnapVideoFromFile(new File((String) call.argument("videoPath")));
content = new SnapVideoContent(videoFile);
} catch (SnapMediaSizeException | SnapVideoLengthException e) {
result.error("SendMediaError", "Could not create SnapVideoFile", e);
return;
} catch (NullPointerException e) {
result.error("SendMediaError", "Could not find Video file", e);
return;
}

break;
default:
content = new SnapLiveCameraContent();
break;
Expand All @@ -125,18 +139,20 @@ public void onFailure(boolean isNetworkError, int statusCode) {
content.setCaptionText((String)call.argument("caption"));
content.setAttachmentUrl((String)call.argument("attachmentUrl"));

try {
File file = new File((String) ((Map<String, Object>)call.argument("sticker")).get("imagePath"));
SnapSticker sticker = this.mediaFactory.getSnapStickerFromFile(file);
sticker.setPosX(0.5f);
sticker.setPosY(0.5f);
content.setSnapSticker(sticker);
} catch (SnapStickerSizeException e) {
result.error("SendMediaError", "Could not create SnapSticker", e);
return;
} catch (NullPointerException e) {
result.error("SendMediaError", "Could not find Sticker file", e);
return;
if (call.argument("sticker") != null) {
try {
File file = new File((String) ((Map<String, Object>) call.argument("sticker")).get("imagePath"));
SnapSticker sticker = this.mediaFactory.getSnapStickerFromFile(file);
sticker.setPosX(0.5f);
sticker.setPosY(0.5f);
content.setSnapSticker(sticker);
} catch (SnapStickerSizeException e) {
result.error("SendMediaError", "Could not create SnapSticker", e);
return;
} catch (NullPointerException e) {
result.error("SendMediaError", "Could not find Sticker file", e);
return;
}
}

this.creativeKitApi.send(content);
Expand Down
2 changes: 1 addition & 1 deletion example/android/.settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=
eclipse.preferences.version=1
gradle.user.home=
java.home=/Library/Java/JavaVirtualMachines/adoptopenjdk-11.jdk/Contents/Home
java.home=/Library/Java/JavaVirtualMachines/jdk-11.0.12.jdk/Contents/Home
jvm.arguments=
offline.mode=false
override.workspace.settings=true
Expand Down
Empty file added example/assets/fonts/.gitkeep
Empty file.
Empty file added example/assets/images/.gitkeep
Empty file.
Empty file added example/assets/videos/.gitkeep
Empty file.
Binary file added example/assets/videos/ForBiggerBlazes.mp4
Binary file not shown.
Binary file added example/assets/videos/TestVideo.mp4
Binary file not shown.
Binary file added example/assets/videos/small.mp4
Binary file not shown.
20 changes: 13 additions & 7 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:io';

import 'package:flutter/material.dart';
import 'dart:async';

Expand Down Expand Up @@ -186,13 +188,17 @@ class _MyAppState
),
floatingActionButton: FloatingActionButton(
onPressed: () {
_snapkit.share(SnapchatMediaType.PHOTO,
image: NetworkImage(
'https://picsum.photos/${(this.context.size!.width.round())}/${this.context.size!.height.round()}.jpg'),
sticker: SnapchatSticker(
image: Image.asset('images/icon-256x256.png').image),
caption: 'Snapkit Example Caption!',
attachmentUrl: 'https://JacobBrasil.com/');
// _snapkit.share(SnapchatMediaType.PHOTO,
// image: NetworkImage(
// 'https://picsum.photos/${(this.context.size!.width.round())}/${this.context.size!.height.round()}.jpg'),
// sticker: SnapchatSticker(
// image: Image.asset('assets/images/icon-256x256.png').image),
// caption: 'Snapkit Example Caption!',
// attachmentUrl: 'https://JacobBrasil.com/');
_snapkit.share(
SnapchatMediaType.VIDEO,
videoPath: 'assets/videos/TestVideo.mp4',
);
},
child: Icon(Icons.camera),
),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.2.1"
version: "1.2.2"
source_span:
dependency: transitive
description:
Expand Down
3 changes: 2 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ flutter:

# To add assets to your application, add an assets section, like this:
assets:
- images/icon-256x256.png
- assets/images/
- assets/videos/
# - images/a_dot_ham.jpeg

# An image asset can refer to one or more resolution-specific "variants", see
Expand Down
11 changes: 9 additions & 2 deletions ios/Classes/SwiftSnapkitPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class SwiftSnapkitPlugin: NSObject, FlutterPlugin {

let mediaType = args["mediaType"] as? String
let imagePath = args["imagePath"] as? String
let videoUrl = args["videoUrl"] as? String
let videoPath = args["videoPath"] as? String

var content: SCSDKSnapContent?

Expand All @@ -94,7 +94,14 @@ public class SwiftSnapkitPlugin: NSObject, FlutterPlugin {
let photo = SCSDKSnapPhoto(image: uiImage)
content = SCSDKPhotoSnapContent(snapPhoto: photo)
case "VIDEO":
let video = SCSDKSnapVideo(videoUrl: URL(string: videoUrl!)!)
let fileUrl = URL(fileURLWithPath: videoPath!, isDirectory: false)
if (!FileManager.default.fileExists(atPath: fileUrl.path)) {
result(FlutterError(code: "SendMediaArgsError", message: "Video could not be found in filesystem", details: fileUrl.path))
}

print(fileUrl.path)

let video = SCSDKSnapVideo(videoUrl: fileUrl)
content = SCSDKVideoSnapContent(snapVideo: video)
default:
content = SCSDKNoSnapContent()
Expand Down
28 changes: 21 additions & 7 deletions lib/snapkit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ class Snapkit {
Future<void> share(
SnapchatMediaType mediaType, {
ImageProvider<Object>? image,
String? videoUrl,
String? videoPath,
SnapchatSticker? sticker,
String? caption,
String? attachmentUrl,
}) async {
assert(caption != null ? caption.length <= 250 : true);

Completer<File?> c = new Completer<File?>();
Completer<File?> imageCompleter = new Completer<File?>();
Completer<File?> videoCompleter = new Completer<File?>();

if (mediaType == SnapchatMediaType.PHOTO) {
assert(image != null);
Expand All @@ -180,21 +181,34 @@ class Snapkit {
File file = await new File('$path/image.png').writeAsBytes(
buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

c.complete(file);
imageCompleter.complete(file);
}));
} else {
c.complete(null);
imageCompleter.complete(null);
}

if (mediaType == SnapchatMediaType.VIDEO) assert(videoUrl != null);
if (mediaType == SnapchatMediaType.VIDEO) {
assert(videoPath != null);
String path = (await getTemporaryDirectory()).path;
ByteData byteData = await rootBundle.load(videoPath!);
ByteBuffer buffer = byteData.buffer;

File file = await new File('$path/video.mp4').writeAsBytes(
buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));

videoCompleter.complete(file);
} else {
videoCompleter.complete(null);
}

File? imageFile = await c.future;
File? imageFile = await imageCompleter.future;
File? videoFile = await videoCompleter.future;

await _channel.invokeMethod('sendMedia', <String, dynamic>{
'mediaType':
mediaType.toString().substring(mediaType.toString().indexOf('.') + 1),
'imagePath': imageFile?.path,
'videoUrl': videoUrl,
'videoPath': videoFile?.path,
'sticker': sticker != null ? await sticker.toMap() : null,
'caption': caption,
'attachmentUrl': attachmentUrl
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: snapkit
description: A Flutter Plugin for integrating with Snapchat's SnapKit on iOS & Android
version: 1.2.1
version: 1.2.2
homepage: https://github.com/TimmyRB/snapkit

environment:
Expand Down