Skip to content

Commit

Permalink
Handle account auth (npomfret#7)
Browse files Browse the repository at this point in the history
* Update RNCloudFsModule.java

* Update build.gradle

* bump version
  • Loading branch information
brunobar79 authored Dec 2, 2020
1 parent cc7436a commit 0b03ea5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 14 deletions.
6 changes: 5 additions & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}

allprojects {
Expand Down
49 changes: 37 additions & 12 deletions android/src/main/java/org/rncloudfs/RNCloudFsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,13 @@ public void fileExists(ReadableMap options, final Promise promise) {

})
.addOnFailureListener(exception ->{
Log.e(TAG, "Couldn't read file.", exception);
promise.reject(exception);
try{
UserRecoverableAuthIOException e = (UserRecoverableAuthIOException)exception;
this.reactContext.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION, null);
} catch(Exception e){
Log.e(TAG, "Couldn't read file.", exception);
promise.reject(exception);
}
});
}
}
Expand All @@ -108,8 +113,13 @@ public void deleteFromCloud(ReadableMap options, final Promise promise) {

})
.addOnFailureListener(exception ->{
Log.e(TAG, "Couldn't delete file.", exception);
promise.reject(exception);
try{
UserRecoverableAuthIOException e = (UserRecoverableAuthIOException)exception;
this.reactContext.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION, null);
} catch(Exception e){
Log.e(TAG, "Couldn't delete file.", exception);
promise.reject(exception);
}
});
}
}
Expand Down Expand Up @@ -202,8 +212,13 @@ public void copyToCloud(ReadableMap options, final Promise promise) throws Execu
Log.d(TAG, "Saving " + fileId);
promise.resolve(fileId);
}).addOnFailureListener(exception -> {
Log.e(TAG, "Couldn't create file.", exception);
promise.reject(exception);
try{
UserRecoverableAuthIOException e = (UserRecoverableAuthIOException)exception;
this.reactContext.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION, null);
} catch(Exception e){
Log.e(TAG, "Couldn't create file.", exception);
promise.reject(exception);
}
});
}
}
Expand Down Expand Up @@ -329,10 +344,15 @@ private void handleSignInResult(Intent result) {
}
})
.addOnFailureListener(exception -> {
Log.e(TAG, "Unable to sign in.", exception);
if(this.signInPromise != null){
this.signInPromise.reject(exception);
this.signInPromise = null;
try{
UserRecoverableAuthIOException e = (UserRecoverableAuthIOException)exception;
this.reactContext.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION, null);
} catch(Exception e){
Log.e(TAG, "Unable to sign in.", exception);
if(this.signInPromise != null){
this.signInPromise.reject(exception);
this.signInPromise = null;
}
}
});
}
Expand All @@ -351,8 +371,13 @@ public void getGoogleDriveDocument(String fileId, Promise promise) {

})
.addOnFailureListener(exception ->{
Log.e(TAG, "Couldn't read file.", exception);
promise.reject(exception);
try{
UserRecoverableAuthIOException e = (UserRecoverableAuthIOException)exception;
this.reactContext.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION, null);
} catch(Exception e){
Log.e(TAG, "Couldn't read file.", exception);
promise.reject(exception);
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-cloud-fs",
"version": "2.1.0",
"version": "2.2.0",
"description": "",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 0b03ea5

Please sign in to comment.