misc formatting

This commit is contained in:
Salakar 2017-03-02 11:38:43 +00:00
parent c652d73c9f
commit 4d9255c3e9
9 changed files with 374 additions and 380 deletions

View File

@ -11,19 +11,19 @@ import io.invertase.firebase.messaging.RNFirebaseMessaging;
public class RNFirebaseInstanceIdService extends FirebaseInstanceIdService {
private static final String TAG = "FSInstanceIdService";
private static final String TAG = "FSInstanceIdService";
/**
*
*/
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_TOKEN);
Bundle bundle = new Bundle();
bundle.putString("token", refreshedToken);
i.putExtras(bundle);
sendBroadcast(i);
}
/**
*
*/
@Override
public void onTokenRefresh() {
String refreshedToken = FirebaseInstanceId.getInstance().getToken();
Log.d(TAG, "Refreshed token: " + refreshedToken);
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_TOKEN);
Bundle bundle = new Bundle();
bundle.putString("token", refreshedToken);
i.putExtras(bundle);
sendBroadcast(i);
}
}

View File

@ -11,64 +11,64 @@ import io.invertase.firebase.messaging.RNFirebaseMessaging;
public class RNFirebaseMessagingService extends FirebaseMessagingService {
private static final String TAG = "FSMessagingService";
private static final String TAG = "FSMessagingService";
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Remote message received");
// debug
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_NOTIFICATION);
i.putExtra("data", remoteMessage);
sendOrderedBroadcast(i, null);
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Remote message received");
// debug
Log.d(TAG, "From: " + remoteMessage.getFrom());
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
@Override
public void onMessageSent(String msgId) {
// Called when an upstream message has been successfully sent to the GCM connection server.
Log.d(TAG, "upstream message has been successfully sent");
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
sendOrderedBroadcast(i, null);
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
@Override
public void onSendError(String msgId, Exception exception) {
// Called when there was an error sending an upstream message.
Log.d(TAG, "error sending an upstream message");
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
i.putExtra("hasError", true);
SendException sendException = (SendException) exception;
i.putExtra("errorCode", sendException.getErrorCode());
switch(sendException.getErrorCode()){
case SendException.ERROR_INVALID_PARAMETERS:
i.putExtra("errorMessage", "Message was sent with invalid parameters.");
break;
case SendException.ERROR_SIZE:
i.putExtra("errorMessage", "Message exceeded the maximum payload size.");
break;
case SendException.ERROR_TOO_MANY_MESSAGES:
i.putExtra("errorMessage", "App has too many pending messages so this one was dropped.");
break;
case SendException.ERROR_TTL_EXCEEDED:
i.putExtra("errorMessage", "Message time to live (TTL) was exceeded before the message could be sent.");
break;
case SendException.ERROR_UNKNOWN:
default:
i.putExtra("errorMessage", "Unknown error.");
break;
}
sendOrderedBroadcast(i, null);
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_NOTIFICATION);
i.putExtra("data", remoteMessage);
sendOrderedBroadcast(i, null);
}
@Override
public void onMessageSent(String msgId) {
// Called when an upstream message has been successfully sent to the GCM connection server.
Log.d(TAG, "upstream message has been successfully sent");
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
sendOrderedBroadcast(i, null);
}
@Override
public void onSendError(String msgId, Exception exception) {
// Called when there was an error sending an upstream message.
Log.d(TAG, "error sending an upstream message");
Intent i = new Intent(RNFirebaseMessaging.INTENT_NAME_SEND);
i.putExtra("msgId", msgId);
i.putExtra("hasError", true);
SendException sendException = (SendException) exception;
i.putExtra("errorCode", sendException.getErrorCode());
switch (sendException.getErrorCode()) {
case SendException.ERROR_INVALID_PARAMETERS:
i.putExtra("errorMessage", "Message was sent with invalid parameters.");
break;
case SendException.ERROR_SIZE:
i.putExtra("errorMessage", "Message exceeded the maximum payload size.");
break;
case SendException.ERROR_TOO_MANY_MESSAGES:
i.putExtra("errorMessage", "App has too many pending messages so this one was dropped.");
break;
case SendException.ERROR_TTL_EXCEEDED:
i.putExtra("errorMessage", "Message time to live (TTL) was exceeded before the message could be sent.");
break;
case SendException.ERROR_UNKNOWN:
default:
i.putExtra("errorMessage", "Unknown error.");
break;
}
sendOrderedBroadcast(i, null);
}
}

View File

@ -69,8 +69,8 @@ public class RNFirebaseModule extends ReactContextBaseJavaModule implements Life
KeySetterFn fn = new KeySetterFn() {
public String setKeyOrDefault(
final String key,
final String defaultValue) {
final String key,
final String defaultValue) {
if (params.hasKey(key)) {
// User-set key
final String val = params.getString(key);

View File

@ -21,44 +21,45 @@ import io.invertase.firebase.messaging.RNFirebaseMessaging;
@SuppressWarnings("unused")
public class RNFirebasePackage implements ReactPackage {
private Context mContext;
private Context mContext;
public RNFirebasePackage() {
}
/**
* @param reactContext react application context that can be used to create modules
* @return list of native modules to register with the newly created catalyst instance
*/
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RNFirebaseModule(reactContext));
modules.add(new RNFirebaseAuth(reactContext));
modules.add(new RNFirebaseDatabase(reactContext));
modules.add(new RNFirebaseAnalytics(reactContext));
modules.add(new RNFirebaseStorage(reactContext));
modules.add(new RNFirebaseMessaging(reactContext));
return modules;
}
public RNFirebasePackage() {
}
/**
* @return list of JS modules to register with the newly created catalyst instance.
* <p/>
* IMPORTANT: Note that only modules that needs to be accessible from the native code should be
* listed here. Also listing a native module here doesn't imply that the JS implementation of it
* will be automatically included in the JS bundle.
*/
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
/**
* @param reactContext react application context that can be used to create modules
* @return list of native modules to register with the newly created catalyst instance
*/
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new RNFirebaseModule(reactContext));
modules.add(new RNFirebaseAuth(reactContext));
modules.add(new RNFirebaseDatabase(reactContext));
modules.add(new RNFirebaseAnalytics(reactContext));
modules.add(new RNFirebaseStorage(reactContext));
modules.add(new RNFirebaseMessaging(reactContext));
return modules;
}
/**
* @param reactContext
* @return a list of view managers that should be registered with {@link UIManagerModule}
*/
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
/**
* @return list of JS modules to register with the newly created catalyst instance.
* <p/>
* IMPORTANT: Note that only modules that needs to be accessible from the native code should be
* listed here. Also listing a native module here doesn't imply that the JS implementation of it
* will be automatically included in the JS bundle.
*/
@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}
/**
* @param reactContext
* @return a list of view managers that should be registered with {@link UIManagerModule}
*/
@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

View File

@ -41,8 +41,8 @@ public class Utils {
public static void sendEvent(final ReactContext context, final String eventName, final WritableMap params) {
if (context != null) {
context
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
.emit(eventName, params);
} else {
Log.d(TAG, "Missing context - cannot send event!");
}
@ -50,10 +50,10 @@ public class Utils {
// snapshot
public static WritableMap dataSnapshotToMap(
String name,
String path,
String modifiersString,
DataSnapshot dataSnapshot
String name,
String path,
String modifiersString,
DataSnapshot dataSnapshot
) {
WritableMap data = Arguments.createMap();

View File

@ -22,7 +22,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @return
*/
@Override
@ -36,7 +35,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param enabled
*/
@ReactMethod
@ -45,7 +43,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param screenName
* @param screenClassOverride
*/
@ -65,7 +62,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param milliseconds
*/
@ReactMethod
@ -74,7 +70,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param milliseconds
*/
@ReactMethod
@ -83,7 +78,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param id
*/
@ReactMethod
@ -92,7 +86,6 @@ public class RNFirebaseAnalytics extends ReactContextBaseJavaModule {
}
/**
*
* @param name
* @param value
*/

View File

@ -121,40 +121,40 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
@ReactMethod
public void createUserWithEmail(final String email, final String password, final Callback callback) {
mAuth.createUserWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
public void signInWithEmail(final String email, final String password, final Callback callback) {
mAuth.signInWithEmailAndPassword(email, password)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
@ -175,22 +175,22 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (user != null) {
AuthCredential credential = EmailAuthProvider.getCredential(email, password);
user
.linkWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "user linked with password credential");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.linkWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "user linked with password credential");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -209,42 +209,42 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
public void signInAnonymously(final Callback callback) {
Log.d(TAG, "signInAnonymously:called:");
mAuth.signInAnonymously()
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful());
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInAnonymously:onComplete:" + task.isSuccessful());
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
public void signInWithCustomToken(final String customToken, final Callback callback) {
mAuth.signInWithCustomToken(customToken)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCustomToken:onComplete:" + task.isSuccessful());
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
Log.d(TAG, "signInWithCustomToken:onComplete:" + task.isSuccessful());
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
@ -261,22 +261,22 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (user != null) {
user
.updateEmail(email)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.updateEmail(email)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User email address updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -288,21 +288,21 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (user != null) {
user.updatePassword(newPassword)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User password updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User password updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -311,22 +311,22 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
@ReactMethod
public void sendPasswordResetWithEmail(final String email, final Callback callback) {
mAuth.sendPasswordResetEmail(email)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
callback.invoke(null, resp);
} else {
callback.invoke(task.getException().toString());
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
callback.invoke(null, resp);
} else {
callback.invoke(task.getException().toString());
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
@ -334,24 +334,24 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
FirebaseUser user = mAuth.getCurrentUser();
if (user != null) {
user.delete()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User account deleted");
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("msg", "User account deleted");
callback.invoke(null, resp);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User account deleted");
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("msg", "User account deleted");
callback.invoke(null, resp);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -364,26 +364,26 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (user != null) {
user.sendEmailVerification()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("msg", "User verification email sent");
callback.invoke(null, resp);
} else {
WritableMap err = Arguments.createMap();
err.putInt("errorCode", ERROR_SENDING_VERIFICATION_EMAIL);
err.putString("errorMessage", task.getException().getMessage());
callback.invoke(err);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("msg", "User verification email sent");
callback.invoke(null, resp);
} else {
WritableMap err = Arguments.createMap();
err.putInt("errorCode", ERROR_SENDING_VERIFICATION_EMAIL);
err.putString("errorMessage", task.getException().getMessage());
callback.invoke(err);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -396,27 +396,27 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (user != null) {
user.getToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
try {
if (task.isSuccessful()) {
String token = task.getResult().getToken();
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("token", token);
callback.invoke(null, resp);
} else {
WritableMap err = Arguments.createMap();
err.putInt("errorCode", ERROR_FETCHING_TOKEN);
err.putString("errorMessage", task.getException().getMessage());
callback.invoke(err);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(@NonNull Task<GetTokenResult> task) {
try {
if (task.isSuccessful()) {
String token = task.getResult().getToken();
WritableMap resp = Arguments.createMap();
resp.putString("status", "complete");
resp.putString("token", token);
callback.invoke(null, resp);
} else {
WritableMap err = Arguments.createMap();
err.putInt("errorCode", ERROR_FETCHING_TOKEN);
err.putString("errorMessage", task.getException().getMessage());
callback.invoke(err);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -445,21 +445,21 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
UserProfileChangeRequest profileUpdates = profileBuilder.build();
user.updateProfile(profileUpdates)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
try {
if (task.isSuccessful()) {
Log.d(TAG, "User profile updated");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
} else {
callbackNoUser(callback, true);
}
@ -483,17 +483,17 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
callbackNoUser(callback, false);
} else {
user.reload()
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "user reloaded");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "user reloaded");
userCallback(mAuth.getCurrentUser(), callback);
} else {
userErrorCallback(task, callback);
}
});
}
});
}
}
@ -514,40 +514,40 @@ public class RNFirebaseAuth extends ReactContextBaseJavaModule {
public void googleLogin(String IdToken, final Callback callback) {
AuthCredential credential = GoogleAuthProvider.getCredential(IdToken, null);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
@ReactMethod
public void facebookLogin(String Token, final Callback callback) {
AuthCredential credential = FacebookAuthProvider.getCredential(Token);
mAuth.signInWithCredential(credential)
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
try {
if (task.isSuccessful()) {
userCallback(task.getResult().getUser(), callback);
} else {
userErrorCallback(task, callback);
}
} catch (Exception ex) {
userExceptionCallback(ex, callback);
}
});
}
});
}
// Internal helpers

View File

@ -341,8 +341,8 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
}
private RNFirebaseDatabaseReference getDBHandle(final String path,
final ReadableArray modifiersArray,
final String modifiersString) {
final ReadableArray modifiersArray,
final String modifiersString) {
String key = this.getDBListenerKey(path, modifiersString);
RNFirebaseDatabaseReference r = mDBListeners.get(key);

View File

@ -114,18 +114,18 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
Task<Uri> downloadTask = reference.getDownloadUrl();
downloadTask
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
callback.invoke(null, uri.toString());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
callback.invoke(makeErrorPayload(1, exception));
}
});
.addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
callback.invoke(null, uri.toString());
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
callback.invoke(makeErrorPayload(1, exception));
}
});
}
@ReactMethod
@ -187,8 +187,8 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
@Override
public void doInBackground(StreamDownloadTask.TaskSnapshot taskSnapshot, InputStream inputStream) throws IOException {
int indexOfLastSlash = localPath.lastIndexOf("/");
String pathMinusFileName = indexOfLastSlash>0 ? localPath.substring(0, indexOfLastSlash) + "/" : "/";
String filename = indexOfLastSlash>0 ? localPath.substring(indexOfLastSlash+1) : localPath;
String pathMinusFileName = indexOfLastSlash > 0 ? localPath.substring(0, indexOfLastSlash) + "/" : "/";
String filename = indexOfLastSlash > 0 ? localPath.substring(indexOfLastSlash + 1) : localPath;
File fileWithJustPath = new File(pathMinusFileName);
fileWithJustPath.mkdirs();
File fileWithFullPath = new File(pathMinusFileName, filename);
@ -255,42 +255,42 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
// register observers to listen for when the download is done or if it fails
uploadTask
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// handle unsuccessful uploads
Log.e(TAG, "Failed to upload file " + exception.getMessage());
//TODO: JS Error event
callback.invoke(makeErrorPayload(1, exception));
}
})
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successfully uploaded file " + taskSnapshot);
WritableMap resp = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_UPLOAD_SUCCESS, path, resp);
//TODO: A little hacky, but otherwise throws a not consumed exception
resp = getUploadTaskAsMap(taskSnapshot);
callback.invoke(null, resp);
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Got upload progress " + taskSnapshot);
WritableMap event = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_STATE_CHANGED, path, event);
}
})
.addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
@Override
public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Upload is paused " + taskSnapshot);
WritableMap event = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_STATE_CHANGED, path, event);
}
});
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
// handle unsuccessful uploads
Log.e(TAG, "Failed to upload file " + exception.getMessage());
//TODO: JS Error event
callback.invoke(makeErrorPayload(1, exception));
}
})
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Successfully uploaded file " + taskSnapshot);
WritableMap resp = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_UPLOAD_SUCCESS, path, resp);
//TODO: A little hacky, but otherwise throws a not consumed exception
resp = getUploadTaskAsMap(taskSnapshot);
callback.invoke(null, resp);
}
})
.addOnProgressListener(new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Got upload progress " + taskSnapshot);
WritableMap event = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_STATE_CHANGED, path, event);
}
})
.addOnPausedListener(new OnPausedListener<UploadTask.TaskSnapshot>() {
@Override
public void onPaused(UploadTask.TaskSnapshot taskSnapshot) {
Log.d(TAG, "Upload is paused " + taskSnapshot);
WritableMap event = getUploadTaskAsMap(taskSnapshot);
handleStorageEvent(STORAGE_STATE_CHANGED, path, event);
}
});
} catch (Exception ex) {
final int errorCode = 2;
callback.invoke(makeErrorPayload(errorCode, ex));
@ -300,17 +300,17 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
//Firebase.Storage methods
@ReactMethod
public void setMaxDownloadRetryTime(final double milliseconds) {
FirebaseStorage.getInstance().setMaxDownloadRetryTimeMillis((long)milliseconds);
FirebaseStorage.getInstance().setMaxDownloadRetryTimeMillis((long) milliseconds);
}
@ReactMethod
public void setMaxOperationRetryTime(final double milliseconds) {
FirebaseStorage.getInstance().setMaxOperationRetryTimeMillis((long)milliseconds);
FirebaseStorage.getInstance().setMaxOperationRetryTimeMillis((long) milliseconds);
}
@ReactMethod
public void setMaxUploadRetryTime(final double milliseconds) {
FirebaseStorage.getInstance().setMaxUploadRetryTimeMillis((long)milliseconds);
FirebaseStorage.getInstance().setMaxUploadRetryTimeMillis((long) milliseconds);
}
private StorageReference getReference(String path) {
@ -438,7 +438,7 @@ public class RNFirebaseStorage extends ReactContextBaseJavaModule {
body.putString("path", path);
body.putString("message", error.getMessage());
WritableMap evt = Arguments.createMap();
WritableMap evt = Arguments.createMap();
evt.putString("eventName", STORAGE_ERROR);
evt.putMap("body", body);