├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ └── styles.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ └── ic_launcher.png
│ │ │ ├── values-w820dp
│ │ │ │ └── dimens.xml
│ │ │ └── layout
│ │ │ │ ├── layout_drive_file.xml
│ │ │ │ ├── activity_image.xml
│ │ │ │ └── activity_main.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── francescocervone
│ │ │ └── rxdrive
│ │ │ └── sample
│ │ │ ├── DriveFileAdapter.java
│ │ │ ├── ImageActivity.java
│ │ │ └── MainActivity.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── francescocervone
│ │ │ └── rxdrive
│ │ │ └── sample
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── francescocervone
│ │ └── rxdrive
│ │ └── sample
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── rxdrive
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── com
│ │ │ └── francescocervone
│ │ │ └── rxdrive
│ │ │ ├── RxDriveException.java
│ │ │ ├── IOUtils.java
│ │ │ ├── Progress.java
│ │ │ ├── ConnectionState.java
│ │ │ └── RxDrive.java
│ ├── test
│ │ └── java
│ │ │ └── com
│ │ │ └── francescocervone
│ │ │ └── rxdrive
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── francescocervone
│ │ └── rxdrive
│ │ └── ApplicationTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── .travis.yml
├── gradle.properties
├── LICENSE
├── install.gradle
├── bintray.gradle
├── gradlew.bat
├── gradlew
└── README.md
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/rxdrive/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':rxdrive'
2 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxDrive
3 |
4 |
--------------------------------------------------------------------------------
/rxdrive/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RxDrive
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/francescocervone/RxDrive/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Oct 22 16:05:41 CEST 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/rxdrive/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/rxdrive/src/test/java/com/francescocervone/rxdrive/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/francescocervone/rxdrive/sample/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive.sample;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * To work on unit tests, switch the Test Artifact in the Build Variants view.
9 | */
10 | public class ExampleUnitTest {
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 | }
--------------------------------------------------------------------------------
/rxdrive/src/main/java/com/francescocervone/rxdrive/RxDriveException.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 | import com.google.android.gms.common.api.Status;
4 |
5 | public class RxDriveException extends RuntimeException {
6 |
7 | private Status mStatus;
8 |
9 | public RxDriveException(Status status) {
10 |
11 | mStatus = status;
12 | }
13 |
14 | public Status getStatus() {
15 | return mStatus;
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/rxdrive/src/androidTest/java/com/francescocervone/rxdrive/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/francescocervone/rxdrive/sample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive.sample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/rxdrive/src/main/java/com/francescocervone/rxdrive/IOUtils.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 |
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.io.OutputStream;
7 |
8 | class IOUtils {
9 | static void copy(InputStream inputStream, OutputStream outputStream) throws IOException {
10 | byte[] buffer = new byte[1024];
11 | int n;
12 | while ((n = inputStream.read(buffer)) > 0) {
13 | outputStream.write(buffer, 0, n);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | # Built application files
9 | *.apk
10 | *.ap_
11 |
12 | # Files for the Dalvik VM
13 | *.dex
14 |
15 | # Java class files
16 | *.class
17 |
18 | # Generated files
19 | bin/
20 | gen/
21 | out/
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | # Android Studio Navigation editor temp files
30 | .navigation/
31 |
32 | # Android Studio captures folder
33 | captures/
34 |
35 | # Keystore files
36 | *.jks
37 | *.asc
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: android
2 |
3 | jdk:
4 | - oraclejdk8
5 |
6 | android:
7 | components:
8 | - tools
9 | - android-25
10 | - build-tools-25.0.3
11 | - platform-tools
12 | - extra-android-m2repository
13 | - extra-android-support
14 | - extra-google-google_play_services
15 | - extra-google-m2repository
16 |
17 | before_script:
18 | - echo "sdk.dir=$ANDROID_HOME" > local.properties
19 | script:
20 | - ./gradlew check
21 |
22 | before_cache:
23 | - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
24 | cache:
25 | directories:
26 | - $HOME/.gradle/caches/
27 | - $HOME/.gradle/wrapper/
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Ciccio/AndroidSDK/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/rxdrive/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/Ciccio/AndroidSDK/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_drive_file.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
13 |
14 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_image.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/rxdrive/src/main/java/com/francescocervone/rxdrive/Progress.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 | public class Progress {
4 | private long mBytesDownloaded;
5 | private long mBytesExpected;
6 |
7 | Progress(long bytesDownloaded, long bytesExpected) {
8 | mBytesDownloaded = bytesDownloaded;
9 | mBytesExpected = bytesExpected;
10 | }
11 |
12 | public long getBytesDownloaded() {
13 | return mBytesDownloaded;
14 | }
15 |
16 | public long getBytesExpected() {
17 | return mBytesExpected;
18 | }
19 |
20 | public double getPercentage() {
21 | if (mBytesExpected == -1) {
22 | return 100;
23 | }
24 | return (mBytesDownloaded * 100d) / mBytesExpected;
25 | }
26 |
27 | public boolean isCompleted() {
28 | return mBytesExpected == mBytesDownloaded;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
20 |
21 |
26 |
27 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 Francesco Cervone
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/install.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.github.dcendents.android-maven"
2 |
3 | group = publishedGroupId // Maven Group ID for the artifact
4 |
5 | install {
6 | repositories.mavenInstaller {
7 | // This generates POM.xml with proper parameters
8 | pom {
9 | project {
10 | packaging "aar"
11 | groupId publishedGroupId
12 | artifactId artifact
13 |
14 | // Add your description here
15 | name libraryName
16 | description libraryDescription
17 | url siteUrl
18 |
19 | // Set your license
20 | licenses {
21 | license {
22 | name licenseName
23 | url licenseUrl
24 | }
25 | }
26 | developers {
27 | developer {
28 | id developerId
29 | name developerName
30 | email developerEmail
31 | }
32 | }
33 | scm {
34 | connection gitUrl
35 | developerConnection gitUrl
36 | url siteUrl
37 |
38 | }
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.application"
2 |
3 | android {
4 | compileSdkVersion rootProject.ext.compileSdk
5 | buildToolsVersion rootProject.ext.buildToolsVersion
6 |
7 | defaultConfig {
8 | applicationId "com.francescocervone.rxdrive.sample"
9 | minSdkVersion rootProject.ext.minSdk
10 | targetSdkVersion rootProject.ext.targetSdk
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
18 | }
19 | }
20 | lintOptions {
21 | abortOnError false
22 | }
23 |
24 | compileOptions {
25 | sourceCompatibility JavaVersion.VERSION_1_8
26 | targetCompatibility JavaVersion.VERSION_1_8
27 | }
28 | }
29 |
30 | dependencies {
31 | implementation fileTree(dir: "libs", include: ["*.jar"])
32 | testImplementation "junit:junit:4.12"
33 | implementation "io.reactivex.rxjava2:rxandroid:2.0.1"
34 | implementation "io.reactivex.rxjava2:rxjava:2.1.5"
35 | implementation "commons-io:commons-io:2.4"
36 | implementation "com.android.support:appcompat-v7:26.1.0"
37 | implementation "com.android.support:recyclerview-v7:26.1.0"
38 | implementation "com.github.chrisbanes:PhotoView:1.3.1"
39 | implementation "com.github.bumptech.glide:glide:4.2.0"
40 | implementation project(":rxdrive")
41 | }
42 |
--------------------------------------------------------------------------------
/bintray.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.jfrog.bintray"
2 |
3 | version = libraryVersion
4 |
5 | if (project.hasProperty("android")) { // Android libraries
6 | task sourcesJar(type: Jar) {
7 | classifier = "sources"
8 | from android.sourceSets.main.java.srcDirs
9 | }
10 |
11 | task javadoc(type: Javadoc) {
12 | source = android.sourceSets.main.java.srcDirs
13 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
14 | }
15 | } else { // Java libraries
16 | task sourcesJar(type: Jar, dependsOn: classes) {
17 | classifier = "sources"
18 | from sourceSets.main.allSource
19 | }
20 | }
21 |
22 | task javadocJar(type: Jar, dependsOn: javadoc) {
23 | classifier = "javadoc"
24 | from javadoc.destinationDir
25 | }
26 |
27 | artifacts {
28 | archives javadocJar
29 | archives sourcesJar
30 | }
31 |
32 | // Bintray
33 | Properties properties = new Properties()
34 | properties.load(project.rootProject.file("local.properties").newDataInputStream())
35 |
36 | bintray {
37 | user = properties.getProperty("bintray.user")
38 | key = properties.getProperty("bintray.apikey")
39 |
40 | configurations = ["archives"]
41 | pkg {
42 | repo = bintrayRepo
43 | name = bintrayName
44 | desc = libraryDescription
45 | websiteUrl = siteUrl
46 | vcsUrl = gitUrl
47 | licenses = allLicenses
48 | publish = true
49 | publicDownloadNumbers = true
50 | version {
51 | desc = libraryDescription
52 | gpg {
53 | sign = true //Determines whether to GPG sign the files. The default is false
54 | passphrase = properties.getProperty("bintray.gpg.password")
55 | //Optional. The passphrase for GPG signing"
56 | }
57 | }
58 | }
59 | }
--------------------------------------------------------------------------------
/rxdrive/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: "com.android.library"
2 |
3 | ext {
4 | bintrayRepo = "maven"
5 | bintrayName = "rxdrive"
6 |
7 | publishedGroupId = "com.francescocervone"
8 | libraryName = "RxDrive"
9 | artifact = "rxdrive"
10 |
11 | libraryDescription = "RxJava wrapper for Google Drive Android API"
12 |
13 | siteUrl = "https://github.com/francescocervone/RxDrive"
14 | gitUrl = "https://github.com/francescocervone/RxDrive.git"
15 |
16 | libraryVersion = "0.3"
17 |
18 | developerId = "francescocervone"
19 | developerName = "Francesco Cervone"
20 | developerEmail = "cervonefrancesco@gmail.com"
21 |
22 | licenseName = "The MIT License (MIT)"
23 | licenseUrl = "https://opensource.org/licenses/MIT"
24 | allLicenses = ["MIT"]
25 | }
26 |
27 | android {
28 | compileSdkVersion rootProject.ext.compileSdk
29 | buildToolsVersion rootProject.ext.buildToolsVersion
30 |
31 | defaultConfig {
32 | minSdkVersion rootProject.ext.minSdk
33 | targetSdkVersion rootProject.ext.targetSdk
34 | versionCode 4
35 | versionName "0.3"
36 | }
37 | buildTypes {
38 | release {
39 | minifyEnabled false
40 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
41 | }
42 | }
43 | lintOptions {
44 | textReport true
45 | textOutput "stdout"
46 | abortOnError true
47 | }
48 |
49 | compileOptions {
50 | sourceCompatibility JavaVersion.VERSION_1_8
51 | targetCompatibility JavaVersion.VERSION_1_8
52 | }
53 | }
54 |
55 | if (JavaVersion.current().isJava8Compatible()) {
56 | allprojects {
57 | tasks.withType(Javadoc) {
58 | options.addStringOption("Xdoclint:none", "-quiet")
59 | }
60 | }
61 | }
62 |
63 | dependencies {
64 | compileOnly "io.reactivex.rxjava2:rxjava:2.1.5"
65 | api "com.google.android.gms:play-services-drive:11.4.2"
66 | implementation fileTree(dir: "libs", include: ["*.jar"])
67 | testImplementation "junit:junit:4.12"
68 | }
69 |
70 | apply from: "../install.gradle"
71 | apply from: "../bintray.gradle"
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/francescocervone/rxdrive/sample/DriveFileAdapter.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive.sample;
2 |
3 | import android.support.annotation.NonNull;
4 | import android.support.v7.widget.RecyclerView;
5 | import android.util.Log;
6 | import android.view.LayoutInflater;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.Button;
10 | import android.widget.TextView;
11 |
12 | import com.francescocervone.rxdrive.RxDrive;
13 | import com.google.android.gms.drive.DriveId;
14 | import com.google.android.gms.drive.Metadata;
15 |
16 | import java.util.ArrayList;
17 | import java.util.List;
18 |
19 | import io.reactivex.android.schedulers.AndroidSchedulers;
20 | import io.reactivex.schedulers.Schedulers;
21 |
22 | public class DriveFileAdapter extends RecyclerView.Adapter {
23 | private static final String TAG = DriveFileAdapter.class.getName();
24 | private RxDrive mRxDrive;
25 |
26 | private List mResources = new ArrayList<>();
27 |
28 | private OnDriveIdClickListener mListener;
29 |
30 | public static class DriveFileViewHolder extends RecyclerView.ViewHolder {
31 |
32 | private TextView mTextView;
33 | private Button mRemoveButton;
34 |
35 | public DriveFileViewHolder(View itemView) {
36 | super(itemView);
37 | mTextView = itemView.findViewById(R.id.percentage);
38 | mRemoveButton = itemView.findViewById(R.id.remove);
39 | }
40 | }
41 |
42 | public DriveFileAdapter(@NonNull RxDrive rxDrive) {
43 | mRxDrive = rxDrive;
44 | }
45 |
46 | public DriveFileAdapter(@NonNull RxDrive rxDrive, @NonNull List resources) {
47 | this(rxDrive);
48 | mResources = resources;
49 | }
50 |
51 | public void setDriveIdClickListener(OnDriveIdClickListener listener) {
52 | mListener = listener;
53 | }
54 |
55 | public void setResources(List resources) {
56 | mResources = resources;
57 | notifyDataSetChanged();
58 | }
59 |
60 | public void addResource(Metadata resource) {
61 | mResources.add(resource);
62 | notifyItemInserted(mResources.size() - 1);
63 | }
64 |
65 | @Override
66 | public DriveFileViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
67 | View view = LayoutInflater.from(parent.getContext())
68 | .inflate(R.layout.layout_drive_file, parent, false);
69 | return new DriveFileViewHolder(view);
70 | }
71 |
72 | @Override
73 | public void onBindViewHolder(final DriveFileViewHolder holder, int position) {
74 | final Metadata metadata = mResources.get(position);
75 | holder.mTextView.setText(metadata.getTitle());
76 | holder.itemView.setOnClickListener(v -> mListener.onDriveIdClick(metadata.getDriveId()));
77 | holder.mRemoveButton.setOnClickListener(v -> mRxDrive.delete(metadata.getDriveId().asDriveResource())
78 | .subscribeOn(Schedulers.io())
79 | .observeOn(AndroidSchedulers.mainThread())
80 | .subscribe(() -> remove(holder.getAdapterPosition()), this::log));
81 | }
82 |
83 | private void remove(int position) {
84 | mResources.remove(position);
85 | notifyItemRemoved(position);
86 | }
87 |
88 | @Override
89 | public int getItemCount() {
90 | return mResources.size();
91 | }
92 |
93 | private void log(Object object) {
94 | Log.d(TAG, "log: " + object);
95 | if (object instanceof Throwable) {
96 | ((Throwable) object).printStackTrace();
97 | }
98 | }
99 |
100 | interface OnDriveIdClickListener {
101 | void onDriveIdClick(DriveId driveId);
102 | }
103 | }
104 |
--------------------------------------------------------------------------------
/rxdrive/src/main/java/com/francescocervone/rxdrive/ConnectionState.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive;
2 |
3 | import android.os.Bundle;
4 |
5 | import com.google.android.gms.common.ConnectionResult;
6 | import com.google.android.gms.common.api.GoogleApiClient;
7 |
8 | public class ConnectionState {
9 |
10 | public enum State {
11 | CONNECTED,
12 | SUSPENDED,
13 | FAILED,
14 | UNABLE_TO_RESOLVE
15 | }
16 |
17 | public enum ConnectionSuspendedCause {
18 | NETWORK_LOST,
19 | SERVICE_DISCONNECTED
20 | }
21 |
22 | private State mState;
23 |
24 | private Bundle mBundle;
25 | private ConnectionSuspendedCause mCause;
26 | private ConnectionResult mConnectionResult;
27 |
28 | private ConnectionState(State state, Bundle bundle, ConnectionSuspendedCause cause, ConnectionResult connectionResult) {
29 | mState = state;
30 | mBundle = bundle;
31 | mCause = cause;
32 | mConnectionResult = connectionResult;
33 | }
34 |
35 | static ConnectionState connected(Bundle bundle) {
36 | return new Builder()
37 | .state(State.CONNECTED)
38 | .bundle(bundle)
39 | .build();
40 | }
41 |
42 | static ConnectionState suspended(int cause) {
43 | return new Builder()
44 | .state(State.SUSPENDED)
45 | .cause(cause == GoogleApiClient.ConnectionCallbacks.CAUSE_NETWORK_LOST ?
46 | ConnectionSuspendedCause.NETWORK_LOST :
47 | ConnectionSuspendedCause.SERVICE_DISCONNECTED)
48 | .build();
49 | }
50 |
51 | static ConnectionState failed(ConnectionResult result) {
52 | return new Builder()
53 | .state(State.FAILED)
54 | .result(result)
55 | .build();
56 | }
57 |
58 | static ConnectionState unableToResolve(ConnectionResult result) {
59 | return new Builder()
60 | .state(State.UNABLE_TO_RESOLVE)
61 | .result(result)
62 | .build();
63 | }
64 |
65 | /**
66 | * @return true if GoogleApiClient is connected
67 | */
68 | public boolean isConnected() {
69 | return mState == State.CONNECTED;
70 | }
71 |
72 | /**
73 | * @return true if GoogleApiClient connection is suspended
74 | */
75 | public boolean isSuspended() {
76 | return mState == State.SUSPENDED;
77 | }
78 |
79 | /**
80 | * @return true if connection to GoogleApiClient is failed
81 | */
82 | public boolean isFailed() {
83 | return mState == State.FAILED;
84 | }
85 |
86 | /**
87 | * @return true if startResolutionForResult failed
88 | * @see com.google.android.gms.common.ConnectionResult#startResolutionForResult
89 | */
90 | public boolean isUnableToResolve() {
91 | return mState == State.UNABLE_TO_RESOLVE;
92 | }
93 |
94 | /**
95 | * This method should be called when state is connected
96 | *
97 | * @return the Bundle object returned by GoogleApiClient
98 | */
99 | public Bundle getBundle() {
100 | return mBundle;
101 | }
102 |
103 | /**
104 | * This method should be called when connection is suspended
105 | *
106 | * @return the cause of the suspension of GoogleApiClient connection
107 | */
108 | public ConnectionSuspendedCause getCause() {
109 | return mCause;
110 | }
111 |
112 | /**
113 | * This method should be called when connection to GoogleApiClient is failed
114 | *
115 | * @return the ConnectionResult returned by GoogleApiClient, useful to try to resolve the problem
116 | */
117 | public ConnectionResult getConnectionResult() {
118 | return mConnectionResult;
119 | }
120 |
121 | /**
122 | * @return the current state of connection to GoogleApiClient
123 | */
124 | public State getState() {
125 | return mState;
126 | }
127 |
128 | private static class Builder {
129 | private State mState;
130 | private Bundle mBundle;
131 | private ConnectionSuspendedCause mCause;
132 | private ConnectionResult mConnectionResult;
133 |
134 | Builder() {
135 |
136 | }
137 |
138 | Builder state(State state) {
139 | mState = state;
140 | return this;
141 | }
142 |
143 | Builder bundle(Bundle bundle) {
144 | mBundle = bundle;
145 | return this;
146 | }
147 |
148 | Builder cause(ConnectionSuspendedCause cause) {
149 | mCause = cause;
150 | return this;
151 | }
152 |
153 | Builder result(ConnectionResult result) {
154 | mConnectionResult = result;
155 | return this;
156 | }
157 |
158 | ConnectionState build() {
159 | return new ConnectionState(mState, mBundle, mCause, mConnectionResult);
160 | }
161 | }
162 | }
163 |
--------------------------------------------------------------------------------
/app/src/main/java/com/francescocervone/rxdrive/sample/ImageActivity.java:
--------------------------------------------------------------------------------
1 | package com.francescocervone.rxdrive.sample;
2 |
3 | import android.graphics.drawable.Drawable;
4 | import android.os.Bundle;
5 | import android.support.annotation.NonNull;
6 | import android.support.annotation.Nullable;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.widget.ImageView;
9 | import android.widget.TextView;
10 |
11 | import com.bumptech.glide.Glide;
12 | import com.bumptech.glide.load.DataSource;
13 | import com.bumptech.glide.load.engine.GlideException;
14 | import com.bumptech.glide.request.RequestListener;
15 | import com.bumptech.glide.request.RequestOptions;
16 | import com.bumptech.glide.request.target.Target;
17 | import com.francescocervone.rxdrive.ConnectionState;
18 | import com.francescocervone.rxdrive.Progress;
19 | import com.francescocervone.rxdrive.RxDrive;
20 | import com.google.android.gms.common.api.GoogleApiClient;
21 | import com.google.android.gms.drive.Drive;
22 | import com.google.android.gms.drive.DriveId;
23 |
24 | import org.apache.commons.io.IOUtils;
25 |
26 | import java.io.IOException;
27 | import java.io.InputStream;
28 |
29 | import io.reactivex.Observable;
30 | import io.reactivex.Observer;
31 | import io.reactivex.android.schedulers.AndroidSchedulers;
32 | import io.reactivex.disposables.CompositeDisposable;
33 | import io.reactivex.disposables.Disposable;
34 | import io.reactivex.schedulers.Schedulers;
35 | import uk.co.senab.photoview.PhotoViewAttacher;
36 |
37 | public class ImageActivity extends AppCompatActivity {
38 |
39 | public static final String IMAGE_EXTRA = "image";
40 | private TextView mTextView;
41 | private ImageView mImageView;
42 | private PhotoViewAttacher mAttacher;
43 | private RxDrive mRxDrive;
44 | private CompositeDisposable mSubscriptions = new CompositeDisposable();
45 | private DriveId mDriveId;
46 |
47 | @Override
48 | protected void onCreate(Bundle savedInstanceState) {
49 | super.onCreate(savedInstanceState);
50 | setContentView(R.layout.activity_image);
51 |
52 | mDriveId = getIntent().getParcelableExtra(IMAGE_EXTRA);
53 | if (mDriveId == null) {
54 | finish();
55 | return;
56 | }
57 |
58 | mTextView = findViewById(R.id.percentage);
59 | mImageView = findViewById(R.id.image);
60 | mAttacher = new PhotoViewAttacher(mImageView, true);
61 |
62 | mRxDrive = new RxDrive(new GoogleApiClient.Builder(this).addScope(Drive.SCOPE_APPFOLDER));
63 | }
64 |
65 | @Override
66 | protected void onStart() {
67 | super.onStart();
68 | setupConnection();
69 | mRxDrive.connect();
70 | }
71 |
72 | @Override
73 | protected void onStop() {
74 | super.onStop();
75 | mRxDrive.disconnect();
76 | mSubscriptions.clear();
77 | }
78 |
79 | private void setupConnection() {
80 | Disposable disposable = mRxDrive.connectionObservable()
81 | .observeOn(Schedulers.io())
82 | .filter(ConnectionState::isConnected)
83 | .flatMapSingle(connectionState -> mRxDrive.open(mDriveId, getProgressObserver()))
84 | .observeOn(AndroidSchedulers.mainThread())
85 | .onErrorResumeNext(Observable.empty())
86 | .subscribe(this::loadImage);
87 | mSubscriptions.add(disposable);
88 | }
89 |
90 | private void loadImage(InputStream inputStream) {
91 | try {
92 | Glide.with(this)
93 | .load(IOUtils.toByteArray(inputStream))
94 | .apply(new RequestOptions()
95 | .fitCenter())
96 | .listener(getRequestListener())
97 | .into(mImageView);
98 | } catch (IOException e) {
99 | e.printStackTrace();
100 | }
101 | }
102 |
103 | @NonNull
104 | private RequestListener getRequestListener() {
105 | return new RequestListener() {
106 | @Override
107 | public boolean onLoadFailed(@Nullable GlideException e, Object model, Target target, boolean isFirstResource) {
108 | return false;
109 | }
110 |
111 | @Override
112 | public boolean onResourceReady(Drawable resource, Object model, Target target, DataSource dataSource, boolean isFirstResource) {
113 | mAttacher.update();
114 | return false;
115 | }
116 | };
117 | }
118 |
119 | @NonNull
120 | private Observer