diff --git a/lib/pages/capture.dart b/lib/pages/capture.dart index 2672f06..7275fe2 100644 --- a/lib/pages/capture.dart +++ b/lib/pages/capture.dart @@ -48,7 +48,6 @@ class _CaptureRoute extends State { CameraController controller; CaptureModel model; - String openTime; var _state = Options.photo; bool _initializing = false; @@ -57,9 +56,7 @@ class _CaptureRoute extends State { bool _loading = false; final String uuid; - _CaptureRoute({this.uuid}) { - openTime = timestamp(); - } + _CaptureRoute({this.uuid}); @override Widget build(BuildContext context) { @@ -175,7 +172,7 @@ class _CaptureRoute extends State { var image = await ImagePicker.pickImage(source: ImageSource.camera); if (image == null) return null; final String dirPath = - '${Application.appDir}/Categories/${_category.name}/${openTime}_$uuid/Photos'; + '${Application.appDir}/Categories/${_category.name}/$uuid/Photos'; await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.jpg'; await image.copy(filePath); @@ -187,7 +184,7 @@ class _CaptureRoute extends State { var video = await ImagePicker.pickVideo(source: ImageSource.camera); if (video == null) return null; final String dirPath = - '${Application.appDir}/Categories/${_category.name}/${openTime}_$uuid/Movies'; + '${Application.appDir}/Categories/${_category.name}/$uuid/Movies'; await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.mp4'; await video.copy(filePath); @@ -251,7 +248,7 @@ class _CaptureRoute extends State { Future startAudioRecord() async { final String dirPath = - '${Application.appDir}/Categories/${_category.name}/${openTime}_$uuid/Audios'; + '${Application.appDir}/Categories/${_category.name}/$uuid/Audios'; await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.aac'; @@ -272,7 +269,7 @@ class _CaptureRoute extends State { } final String dirPath = - '${Application.appDir}/Categories/${_category.name}/${openTime}_$uuid/Movies'; + '${Application.appDir}/Categories/${_category.name}/$uuid/Movies'; await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.mp4'; @@ -315,7 +312,7 @@ class _CaptureRoute extends State { return null; } final String dirPath = - '${Application.appDir}/Categories/${_category.name}/${openTime}_$uuid/Pictures'; + '${Application.appDir}/Categories/${_category.name}/$uuid/Pictures'; await Directory(dirPath).create(recursive: true); final String filePath = '$dirPath/${timestamp()}.jpg'; diff --git a/lib/pages/selected-series.dart b/lib/pages/selected-series.dart index 6486f89..edaca89 100644 --- a/lib/pages/selected-series.dart +++ b/lib/pages/selected-series.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; +import 'package:open_directory/open_directory.dart'; +import '../config/application.dart'; import '../utils/card.dart'; import '../pages/item-view.dart'; import '../models/CaptureModel.dart'; @@ -236,17 +238,22 @@ class _SelectedSeriesRoute extends State title: Text( _makeTitle(_selectedSeries.title), ), - // actions: [ - // FlatButton( - // child: Text( - // "Open as", - // style: TextStyle( - // color: whiteColor, - // ), - // ), - // onPressed: _openIntent, - // ) - // ], + actions: [ + FlatButton( + child: Text( + "Open as", + style: TextStyle( + color: whiteColor, + ), + ), + onPressed: () { + final String dirPath = '${Application.appDir}/Categories/${_selectedCategory.name}/${_selectedSeries.uuid}'; + canOpen(dirPath).then((result) { + openDirectory(dirPath); + }); + }, + ) + ], ), body: _items.length > 0 ? _tabBarView() : _listView(), bottomNavigationBar: _items.length > 0 ? _bottomBar() : null, diff --git a/packages/flutter_video_launcher/lib/video_launcher.dart b/packages/flutter_video_launcher/lib/video_launcher.dart index 80870f3..ca31491 100644 --- a/packages/flutter_video_launcher/lib/video_launcher.dart +++ b/packages/flutter_video_launcher/lib/video_launcher.dart @@ -10,7 +10,7 @@ const _channel = const MethodChannel('bz.rxla.flutter/video_launcher'); /// The returned future completes with a [PlatformException] on invalid URLs and /// schemes which cannot be handled, that is when [canLaunchVideo] would complete /// with false. -Future launchVideo(String urlString, {bool isLocal:false}) { +Future launchVideo(String urlString, {bool isLocal:false}) { return _channel.invokeMethod( /* FIXME had some trouble to send a false BOOL to objC => for now I send 1 || 0 */ 'launchVideo',{"url":urlString, "isLocal":isLocal ? 1 : 0 }, diff --git a/packages/open_directory/.gitignore b/packages/open_directory/.gitignore new file mode 100644 index 0000000..14c7d4c --- /dev/null +++ b/packages/open_directory/.gitignore @@ -0,0 +1,9 @@ +.DS_Store +.atom/ +.idea +.packages +.pub/ +build/ +ios/.generated/ +packages +pubspec.lock diff --git a/packages/open_directory/android/.gitignore b/packages/open_directory/android/.gitignore new file mode 100644 index 0000000..5c4ef82 --- /dev/null +++ b/packages/open_directory/android/.gitignore @@ -0,0 +1,12 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures + +/gradle +/gradlew +/gradlew.bat diff --git a/packages/open_directory/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java b/packages/open_directory/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java new file mode 100644 index 0000000..3e2671c --- /dev/null +++ b/packages/open_directory/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java @@ -0,0 +1,25 @@ +package io.flutter.plugins; + +import io.flutter.plugin.common.PluginRegistry; +import net.zibaei.open_directory.OpenDirectoryPlugin; + +/** + * Generated file. Do not edit. + */ +public final class GeneratedPluginRegistrant { + public static void registerWith(PluginRegistry registry) { + if (alreadyRegisteredWith(registry)) { + return; + } + OpenDirectoryPlugin.registerWith(registry.registrarFor("net.zibaei.open_directory.OpenDirectoryPlugin")); + } + + private static boolean alreadyRegisteredWith(PluginRegistry registry) { + final String key = GeneratedPluginRegistrant.class.getCanonicalName(); + if (registry.hasPlugin(key)) { + return true; + } + registry.registrarFor(key); + return false; + } +} diff --git a/packages/open_directory/android/build.gradle b/packages/open_directory/android/build.gradle new file mode 100644 index 0000000..70b9447 --- /dev/null +++ b/packages/open_directory/android/build.gradle @@ -0,0 +1,32 @@ +group 'net.zibaei.open_directory' +version '1.0-SNAPSHOT' + +buildscript { + repositories { + jcenter() + } + + dependencies { + classpath 'com.android.tools.build:gradle:2.3.0' + } +} + +allprojects { + repositories { + jcenter() + } +} + +apply plugin: 'com.android.library' + +android { + compileSdkVersion 25 + buildToolsVersion '25.0.3' + + defaultConfig { + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + lintOptions { + disable 'InvalidPackage' + } +} diff --git a/packages/open_directory/android/gradle.properties b/packages/open_directory/android/gradle.properties new file mode 100644 index 0000000..8bd86f6 --- /dev/null +++ b/packages/open_directory/android/gradle.properties @@ -0,0 +1 @@ +org.gradle.jvmargs=-Xmx1536M diff --git a/packages/open_directory/android/settings.gradle b/packages/open_directory/android/settings.gradle new file mode 100644 index 0000000..8e83a55 --- /dev/null +++ b/packages/open_directory/android/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'open_directory' diff --git a/packages/open_directory/android/src/main/AndroidManifest.xml b/packages/open_directory/android/src/main/AndroidManifest.xml new file mode 100644 index 0000000..240e09e --- /dev/null +++ b/packages/open_directory/android/src/main/AndroidManifest.xml @@ -0,0 +1,7 @@ + + + + diff --git a/packages/open_directory/android/src/main/java/net/zibaei/open_directory/OpenDirectoryPlugin.java b/packages/open_directory/android/src/main/java/net/zibaei/open_directory/OpenDirectoryPlugin.java new file mode 100644 index 0000000..0f80590 --- /dev/null +++ b/packages/open_directory/android/src/main/java/net/zibaei/open_directory/OpenDirectoryPlugin.java @@ -0,0 +1,57 @@ +package net.zibaei.open_directory; + +import android.app.Activity; +import android.content.ComponentName; +import android.content.Intent; +import android.net.Uri; +import io.flutter.plugin.common.MethodCall; +import io.flutter.plugin.common.MethodChannel; +import io.flutter.plugin.common.PluginRegistry; + +import java.io.File; +import java.util.HashMap; + +public class OpenDirectoryPlugin implements MethodChannel.MethodCallHandler { + private final Activity activity; + + public static void registerWith(PluginRegistry.Registrar registrar) { + MethodChannel channel = + new MethodChannel(registrar.messenger(), "net.zibaei.flutter/open_directory"); + OpenDirectoryPlugin instance = new OpenDirectoryPlugin(registrar.activity()); + channel.setMethodCallHandler(instance); + } + + private OpenDirectoryPlugin(Activity activity) { + this.activity = activity; + } + + @Override + public void onMethodCall(MethodCall call, MethodChannel.Result result) { + String uri = ((HashMap) call.arguments()).get("uri").toString(); + if (call.method.equals("canOpen")) { + canOpen(uri, result); + } else if (call.method.equals("openDirectory")) { + openDirectory(uri, result); + } else { + result.notImplemented(); + } + } + + private void openDirectory(String uri, MethodChannel.Result result) { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); + intent.setDataAndType(Uri.parse(uri), "resource/folder"); + activity.startActivity(intent); + result.success(null); + } + + private void canOpen(String uri, MethodChannel.Result result) { + boolean canLaunch; + Intent launchIntent = new Intent(Intent.ACTION_VIEW); + launchIntent.setDataAndType(Uri.parse(uri), "resource/folder"); + ComponentName componentName = launchIntent.resolveActivity(activity.getPackageManager()); + canLaunch = componentName != null + && !"{com.android.fallback/com.android.fallback.Fallback}" + .equals(componentName.toShortString()); + result.success(canLaunch); + } +} diff --git a/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.h b/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.h new file mode 100644 index 0000000..3b700eb --- /dev/null +++ b/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.h @@ -0,0 +1,14 @@ +// +// Generated file. Do not edit. +// + +#ifndef GeneratedPluginRegistrant_h +#define GeneratedPluginRegistrant_h + +#import + +@interface GeneratedPluginRegistrant : NSObject ++ (void)registerWithRegistry:(NSObject*)registry; +@end + +#endif /* GeneratedPluginRegistrant_h */ diff --git a/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.m b/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.m new file mode 100644 index 0000000..b3b9ba7 --- /dev/null +++ b/packages/open_directory/ios/Runner/GeneratedPluginRegistrant.m @@ -0,0 +1,14 @@ +// +// Generated file. Do not edit. +// + +#import "GeneratedPluginRegistrant.h" +#import + +@implementation GeneratedPluginRegistrant + ++ (void)registerWithRegistry:(NSObject*)registry { + [OpenDirectoryPlugin registerWithRegistrar:[registry registrarForPlugin:@"OpenDirectoryPlugin"]]; +} + +@end diff --git a/packages/open_directory/lib/open_directory.dart b/packages/open_directory/lib/open_directory.dart new file mode 100644 index 0000000..6cc4bfc --- /dev/null +++ b/packages/open_directory/lib/open_directory.dart @@ -0,0 +1,14 @@ +import 'dart:async'; + +import 'package:flutter/services.dart'; + +const _channel = const MethodChannel('net.zibaei.flutter/open_directory'); + +Future openDirectory(String uriString) { + return _channel.invokeMethod('openDirectory', {"uri": uriString}); +} + +Future canOpen(String uriString) async { + if (uriString == null) return false; + return await _channel.invokeMethod('canOpen', {"uri": uriString}); +} diff --git a/packages/open_directory/open_directory.iml b/packages/open_directory/open_directory.iml new file mode 100644 index 0000000..7f9681f --- /dev/null +++ b/packages/open_directory/open_directory.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/packages/open_directory/pubspec.yaml b/packages/open_directory/pubspec.yaml new file mode 100644 index 0000000..2518761 --- /dev/null +++ b/packages/open_directory/pubspec.yaml @@ -0,0 +1,16 @@ +name: open_directory +description: Open Directory plugin +version: 0.3.0 +author: Ahmadreza Zibaei + +flutter: + plugin: + androidPackage: net.zibaei.open_directory + pluginClass: OpenDirectoryPlugin + +dependencies: + flutter: + sdk: flutter + +environment: + sdk: ">=2.0.0 <2.2.0" diff --git a/pubspec.lock b/pubspec.lock index 213f31a..0f49548 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -284,6 +284,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.4.4" + open_directory: + dependency: "direct main" + description: + path: "packages/open_directory" + relative: true + source: path + version: "0.3.0" package_config: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 752eeaa..92c699c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,9 +33,13 @@ dependencies: audioplayers: 0.7.8 archive: 2.0.4 image_picker: 0.4.10 + video_launcher: path: './packages/flutter_video_launcher' + open_directory: + path: './packages/open_directory' + dev_dependencies: flutter_test: sdk: flutter