Skip to content

Commit

Permalink
open_directory plugin added
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmdrz committed Oct 14, 2018
1 parent b6ee8e2 commit 1f7d9d3
Show file tree
Hide file tree
Showing 18 changed files with 254 additions and 21 deletions.
15 changes: 6 additions & 9 deletions lib/pages/capture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class _CaptureRoute extends State<CaptureRoute> {

CameraController controller;
CaptureModel model;
String openTime;

var _state = Options.photo;
bool _initializing = false;
Expand All @@ -57,9 +56,7 @@ class _CaptureRoute extends State<CaptureRoute> {
bool _loading = false;

final String uuid;
_CaptureRoute({this.uuid}) {
openTime = timestamp();
}
_CaptureRoute({this.uuid});

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -175,7 +172,7 @@ class _CaptureRoute extends State<CaptureRoute> {
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);
Expand All @@ -187,7 +184,7 @@ class _CaptureRoute extends State<CaptureRoute> {
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);
Expand Down Expand Up @@ -251,7 +248,7 @@ class _CaptureRoute extends State<CaptureRoute> {

Future<String> 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';

Expand All @@ -272,7 +269,7 @@ class _CaptureRoute extends State<CaptureRoute> {
}

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';

Expand Down Expand Up @@ -315,7 +312,7 @@ class _CaptureRoute extends State<CaptureRoute> {
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';

Expand Down
29 changes: 18 additions & 11 deletions lib/pages/selected-series.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -236,17 +238,22 @@ class _SelectedSeriesRoute extends State<SelectedSeriesRoute>
title: Text(
_makeTitle(_selectedSeries.title),
),
// actions: <Widget>[
// FlatButton(
// child: Text(
// "Open as",
// style: TextStyle(
// color: whiteColor,
// ),
// ),
// onPressed: _openIntent,
// )
// ],
actions: <Widget>[
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,
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter_video_launcher/lib/video_launcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<Null> launchVideo(String urlString, {bool isLocal:false}) {
Future<dynamic> 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 },
Expand Down
9 changes: 9 additions & 0 deletions packages/open_directory/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.DS_Store
.atom/
.idea
.packages
.pub/
build/
ios/.generated/
packages
pubspec.lock
12 changes: 12 additions & 0 deletions packages/open_directory/android/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures

/gradle
/gradlew
/gradlew.bat
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions packages/open_directory/android/build.gradle
Original file line number Diff line number Diff line change
@@ -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'
}
}
1 change: 1 addition & 0 deletions packages/open_directory/android/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.gradle.jvmargs=-Xmx1536M
1 change: 1 addition & 0 deletions packages/open_directory/android/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = 'open_directory'
7 changes: 7 additions & 0 deletions packages/open_directory/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.zibaei.open_directory"
android:versionCode="1"
android:versionName="0.3.0">

<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="21" />
</manifest>
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 14 additions & 0 deletions packages/open_directory/ios/Runner/GeneratedPluginRegistrant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Generated file. Do not edit.
//

#ifndef GeneratedPluginRegistrant_h
#define GeneratedPluginRegistrant_h

#import <Flutter/Flutter.h>

@interface GeneratedPluginRegistrant : NSObject
+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry;
@end

#endif /* GeneratedPluginRegistrant_h */
14 changes: 14 additions & 0 deletions packages/open_directory/ios/Runner/GeneratedPluginRegistrant.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Generated file. Do not edit.
//

#import "GeneratedPluginRegistrant.h"
#import <open_directory/OpenDirectoryPlugin.h>

@implementation GeneratedPluginRegistrant

+ (void)registerWithRegistry:(NSObject<FlutterPluginRegistry>*)registry {
[OpenDirectoryPlugin registerWithRegistrar:[registry registrarForPlugin:@"OpenDirectoryPlugin"]];
}

@end
14 changes: 14 additions & 0 deletions packages/open_directory/lib/open_directory.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import 'dart:async';

import 'package:flutter/services.dart';

const _channel = const MethodChannel('net.zibaei.flutter/open_directory');

Future<dynamic> openDirectory(String uriString) {
return _channel.invokeMethod('openDirectory', {"uri": uriString});
}

Future<bool> canOpen(String uriString) async {
if (uriString == null) return false;
return await _channel.invokeMethod('canOpen', {"uri": uriString});
}
16 changes: 16 additions & 0 deletions packages/open_directory/open_directory.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.pub" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
<orderEntry type="library" name="Dart Packages" level="project" />
</component>
</module>
16 changes: 16 additions & 0 deletions packages/open_directory/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: open_directory
description: Open Directory plugin
version: 0.3.0
author: Ahmadreza Zibaei <ahmadreza@zibaei.net>

flutter:
plugin:
androidPackage: net.zibaei.open_directory
pluginClass: OpenDirectoryPlugin

dependencies:
flutter:
sdk: flutter

environment:
sdk: ">=2.0.0 <2.2.0"
7 changes: 7 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1f7d9d3

Please sign in to comment.