Skip to content

Commit

Permalink
feat(): release capacitor plugin for medias
Browse files Browse the repository at this point in the history
  • Loading branch information
stewones committed Mar 31, 2019
0 parents commit 62a47e1
Show file tree
Hide file tree
Showing 45 changed files with 2,418 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist/
node_modules/


Pods
Build
*.iml
.idea
13 changes: 13 additions & 0 deletions CapacitorMedia.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Pod::Spec.new do |s|
s.name = 'CapacitorMedia'
s.version = '0.0.1'
s.summary = 'Enable some media features for Capacitor, such as create albums, save videos and gifs.'
s.license = 'MIT'
s.homepage = 'https://github.com/stewwan/capacitor-media'
s.author = 'Stewan Silva'
s.source = { :git => 'https://github.com/stewwan/capacitor-media', :tag => s.version.to_s }
s.source_files = 'ios/Plugin/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
s.ios.deployment_target = '11.0'
s.dependency 'Capacitor'
end
79 changes: 79 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# capacitor-media

Capacitor plugin to activate media features such as saving videos and gifs into user's photo gallery

## API

- savePhoto
- saveVideo
- saveGif
- createAlbum
- getAlbums
- getMedias `only ios for now`

## Usage

```js
import { Media } from "capacitor-media";
const media = new Media();

//
// Save video to a specfic album
media
.saveVideo({ path: "/path/to/the/file", album: "My Album" })
.then(console.log)
.catch(console.log);

//
// Get a list of user albums
media
.getAlbums()
.then(console.log) // -> { albums: [{name:'My Album'}, {name:'My Another Album'}]}
.catch(console.log);
```

## iOS setup

- `ionic start my-cap-app --capacitor`
- `cd my-cap-app`
- `npm install —-save capacitor-media`
- `mkdir www && touch www/index.html`
- `npx cap add ios`
- `npx cap open ios`
- sign your app at xcode (general tab)

> Tip: every time you change a native code you may need to clean up the cache (Product > Clean build folder) and then run the app again.
## Android setup

- `ionic start my-cap-app --capacitor`
- `cd my-cap-app`
- `npm install —-save capacitor-media`
- `mkdir www && touch www/index.html`
- `npx cap add android`
- `npx cap open android`
- `[extra step]` in android case we need to tell Capacitor to initialise the plugin:

> on your `MainActivity.java` file add `import io.stewan.capacitor.media.MediaPlugin;` and then inside the init callback `add(MediaPlugin.class);`
Now you should be set to go. Try to run your client using `ionic cap run android --livereload`.

> Tip: every time you change a native code you may need to clean up the cache (Build > Clean Project | Build > Rebuild Project) and then run the app again.
## Sample app

(coming soon)

## You may also like

- [capacitor-intercom](https://github.com/stewwan/capacitor-intercom)
- [capacitor-fcm](https://github.com/stewwan/capacitor-fcm)
- [capacitor-twitter](https://github.com/stewwan/capacitor-twitter)

Cheers 🍻

Follow me [@Twitter](https://twitter.com/StewanSilva)

## License

MIT
9 changes: 9 additions & 0 deletions android/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
*.iml
.gradle
/local.properties
/.idea/workspace.xml
/.idea/libraries
.DS_Store
/build
/captures
.externalNativeBuild
1 change: 1 addition & 0 deletions android/capacitor-media/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
50 changes: 50 additions & 0 deletions android/capacitor-media/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
}
}

apply plugin: 'com.android.library'

android {
compileSdkVersion 27
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
}
}

repositories {
google()
jcenter()
mavenCentral()
maven {
url "https://dl.bintray.com/ionic-team/capacitor"
}
}


dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'ionic-team:capacitor-android:1+'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}

21 changes: 21 additions & 0 deletions android/capacitor-media/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.getcapacitor.android;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
* Instrumented test, which will execute on an Android device.
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();

assertEquals("com.getcapacitor.android", appContext.getPackageName());
}
}
4 changes: 4 additions & 0 deletions android/capacitor-media/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="io.stewan.capacitor.media.capacitormedia">
</manifest>
Loading

0 comments on commit 62a47e1

Please sign in to comment.