Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.francescocervone:rxdrive

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.francescocervone:rxdrive

RxJava wrapper for Google Drive Android API

  • 0.1
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

Android Arsenal Download

RxDrive

RxJava wrapper for Google Drive Android API

Why

Using Google Drive API for Android can be a little frustrating because sometimes you must define nested callbacks. If you want to avoid them, you should create an AsyncTask for each action and call synchronous methods (await()). Anyway, you have to write some ugly and confusing code.

The purpose of RxDrive is to use Google Drive APIs with the elegance and the advantages of RxJava.

No more nested callbacks, no more AsyncTasks.

Before you start

Before you start using this library, you need to follow the instructions to create a new project with Google Drive API access (https://developers.google.com/drive/android/get-started).

Features

Since this project is still a work in progress, additional features will come in next releases. Currently, RxDrive allows you to:

  • Authenticate users
  • Notify your app about changes of the connection state
  • Create files
  • Open files
  • Get metadata of Drive resources
  • List and query resources
  • Trash, untrash and delete Drive resources

Examples

Connecting

public class MyActivity extends AppCompatActivity {
    private RxDrive mRxDrive;
    private Subscription mSubscription;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    	...
    	mRxDrive = new RxDrive(new GoogleApiClient.Builder(this)
    		.addApi(Drive.API)
    		.addScope(Drive.SCOPE_FILE) //If you want to access to user files
    		.addScope(Drive.SCOPE_APPFOLDER) //If you want to access to the app folder
    	);
    }
    	
    @Override
    protected void onStart() {
        ...
        mSubscription = mRxDrive.connectionObservable()
                .subscribe(new Action1<ConnectionState>() {
                    @Override
                    public void call(ConnectionState connectionState) {
                        switch (connectionState.getState()) {
                            case CONNECTED:
                                doSomething(connectionState.getBundle());
                                break;
                            case SUSPENDED:
                                doSomethingElse(connectionState.getCause());
                                break;
                            case FAILED:
                                mRxDrive.resolveConnection(MyActivity.this, connectionState.getConnectionResult());
                                break;
                            case UNABLE_TO_RESOLVE:
                                showMessageToUser(connectionState.getConnectionResult());
                                break;
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) { ... }
                });
        mRxDrive.connect();
    }
    
    @Override
    protected void onStop() {
        ...
        mRxDrive.disconnect();
        mSubscription.unsubscribe();
    }
    
    @Override
    protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
        mRxDrive.onActivityResult(requestCode, resultCode, data);
    }
}

Creating a file

mRxDrive.createFile(mRxDrive.getAppFolder(), uriOrFile, optionalName, optionalMimeType)
    .subscribe(new Action1<DriveId>() {
        @Override
        public void call(DriveId driveId) { ... }
    }, new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) { ... }
    });

Listing children of a folder

mRxDrive.listChildren(mRxDrive.getAppFolder())
    .subscribe(new Action1<List<DriveId>>() {
        @Override
        public void call(List<DriveId> driveIds) { ... }
    }, new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) { ... }
    });

Querying for children of a folder

Query query = new Query.Builder()
	.addFilter(Filters.eq(SearchableField.TITLE, "HelloWorld.java"))
	.build()
mRxDrive.queryChildren(mRxDrive.getAppFolder(), query)
    .subscribe(new Action1<List<DriveId>>() {
        @Override
        public void call(List<DriveId> driveIds) { ... }
    }, new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) { ... }
    });

Getting metadata

mRxDrive.getMetadata(someDriveId)
	.subscribe(new Action1<Metadata>() {
	    @Override
        public void call(Metadata metadata) { ... }
	}, new Action1<Throwable>() {
	    @Override
        public void call(Throwable throwable) { ... }
	}

Opening a file

mRxDrive.open(mDriveId, new Subscriber<Progress>() {
        @Override
        public void onCompleted() { ... }
    
        @Override
        public void onError(Throwable e) { ... }
    
        @Override
        public void onNext(Progress progress) {
            mTextView.setText(progress.getPercentage() + "%");
        }
    })
    .subscribe(new Action1<InputStream>() {
    	@Override
    	public void call(InputStream inputStream) { ... }
    }, new Action1<Throwable>() {
    	@Override
    	public void call(Throwable throwable) { ... }
    });

Gradle

Add in your root build.gradle:

repositories {
	jcenter()
}

Add in your app build.gradle the dependency:

dependencies {
  ...
  compile 'com.francescocervone:rxdrive:0.1.1'
}

FAQs

Package last updated on 25 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc