sync with master

This commit is contained in:
Salakar
2018-03-28 16:28:19 +01:00
25 changed files with 392 additions and 240 deletions

View File

@@ -2,16 +2,13 @@ buildscript {
ext.firebaseVersion = '12.0.0'
repositories {
jcenter()
mavenLocal()
maven {
url "https://maven.google.com"
}
google()
maven {
url 'https://maven.fabric.io/public'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'io.fabric.tools:gradle:1.25.1'
}
}
@@ -20,10 +17,10 @@ apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion "27.0.2"
buildToolsVersion "27.0.3"
defaultConfig {
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 26
versionCode 1
versionName "1.0"
multiDexEnabled true
@@ -48,7 +45,6 @@ allprojects {
}
}
rootProject.gradle.buildFinished { buildResult ->
if (buildResult.getFailure() != null) {
try {
@@ -79,31 +75,29 @@ rootProject.gradle.buildFinished { buildResult ->
logger.log(LogLevel.ERROR, "| |")
logger.log(LogLevel.ERROR, " ----------------------------------------------------------- ")
}
} catch (Exception exception) {
}
} catch (Exception exception) {}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
//noinspection GradleDynamicVersion
compile "com.facebook.react:react-native:+" // From node_modules
compile "com.android.support:support-v4:27.1.0"
compile 'me.leolin:ShortcutBadger:1.1.21@aar'
compile "com.google.android.gms:play-services-base:$firebaseVersion"
compile "com.google.firebase:firebase-core:$firebaseVersion"
compile "com.google.firebase:firebase-config:$firebaseVersion"
compile "com.google.firebase:firebase-auth:$firebaseVersion"
compile "com.google.firebase:firebase-database:$firebaseVersion"
compile "com.google.firebase:firebase-storage:$firebaseVersion"
compile "com.google.firebase:firebase-messaging:$firebaseVersion"
compile "com.google.firebase:firebase-crash:$firebaseVersion"
compile "com.google.firebase:firebase-perf:$firebaseVersion"
compile "com.google.firebase:firebase-ads:$firebaseVersion"
compile "com.google.firebase:firebase-firestore:$firebaseVersion"
compile "com.google.firebase:firebase-invites:$firebaseVersion"
compile('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
// compile fileTree(include: ['*.jar'], dir: 'libs')
api "com.facebook.react:react-native:+" // From node_modules
api "com.android.support:support-v4:27.0.2"
compileOnly 'me.leolin:ShortcutBadger:1.1.21@aar'
compileOnly "com.google.android.gms:play-services-base:$firebaseVersion"
compileOnly "com.google.firebase:firebase-core:$firebaseVersion"
compileOnly "com.google.firebase:firebase-config:$firebaseVersion"
compileOnly "com.google.firebase:firebase-auth:$firebaseVersion"
compileOnly "com.google.firebase:firebase-database:$firebaseVersion"
compileOnly "com.google.firebase:firebase-storage:$firebaseVersion"
compileOnly "com.google.firebase:firebase-messaging:$firebaseVersion"
compileOnly "com.google.firebase:firebase-crash:$firebaseVersion"
compileOnly "com.google.firebase:firebase-perf:$firebaseVersion"
compileOnly "com.google.firebase:firebase-ads:$firebaseVersion"
compileOnly "com.google.firebase:firebase-firestore:$firebaseVersion"
compileOnly "com.google.firebase:firebase-invites:$firebaseVersion"
compileOnly('com.crashlytics.sdk.android:crashlytics:2.9.1@aar') {
transitive = true
}
}

View File

@@ -596,8 +596,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
if (props.hasKey("photoURL")) {
String photoURLStr = props.getString("photoURL");
Uri uri = Uri.parse(photoURLStr);
profileBuilder.setPhotoUri(uri);
profileBuilder.setPhotoUri(photoURLStr == null ? null : Uri.parse(photoURLStr));
}
UserProfileChangeRequest profileUpdates = profileBuilder.build();
@@ -1067,7 +1066,7 @@ class RNFirebaseAuth extends ReactContextBaseJavaModule {
public void reauthenticateAndRetrieveDataWithCredential(String appName, String provider, String authToken, String authSecret, final Promise promise) {
reauthenticate(appName, provider, authToken, authSecret, promise, true);
}
public void reauthenticate(String appName, String provider, String authToken, String authSecret, final Promise promise, final boolean withData) {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
final FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(firebaseApp);

View File

@@ -18,6 +18,7 @@ import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.FirebaseApp;
import com.google.firebase.firestore.FirebaseFirestoreSettings;
import com.google.firebase.firestore.Transaction;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.FieldValue;
@@ -47,14 +48,42 @@ public class RNFirebaseFirestore extends ReactContextBaseJavaModule {
* REACT NATIVE METHODS
*/
/**
* @param enabled
*/
@ReactMethod
public void disableNetwork(String appName, final Promise promise) {
getFirestoreForApp(appName).disableNetwork().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "disableNetwork:onComplete:success");
promise.resolve(null);
} else {
Log.e(TAG, "disableNetwork:onComplete:failure", task.getException());
RNFirebaseFirestore.promiseRejectException(promise, (FirebaseFirestoreException)task.getException());
}
}
});
}
@ReactMethod
public void enableLogging(Boolean enabled) {
FirebaseFirestore.setLoggingEnabled(enabled);
}
@ReactMethod
public void enableNetwork(String appName, final Promise promise) {
getFirestoreForApp(appName).enableNetwork().addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Log.d(TAG, "enableNetwork:onComplete:success");
promise.resolve(null);
} else {
Log.e(TAG, "enableNetwork:onComplete:failure", task.getException());
RNFirebaseFirestore.promiseRejectException(promise, (FirebaseFirestoreException)task.getException());
}
}
});
}
@ReactMethod
public void collectionGet(String appName, String path, ReadableArray filters,

View File

@@ -110,19 +110,37 @@ public class BundleJSONConverter {
SETTERS.put(JSONArray.class, new Setter() {
public void setOnBundle(Bundle bundle, String key, Object value) throws JSONException {
JSONArray jsonArray = (JSONArray) value;
// Empty list, can't even figure out the type, assume an ArrayList<String>
if (jsonArray.length() == 0) {
bundle.putStringArrayList(key, new ArrayList<String>());
return;
}
// Only strings are supported for now
if (jsonArray.get(0) instanceof String) {
ArrayList<String> stringArrayList = new ArrayList<String>();
// Assume an empty list is an ArrayList<String>
if (jsonArray.length() == 0 || jsonArray.get(0) instanceof String) {
ArrayList<String> stringArrayList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
stringArrayList.add((String) jsonArray.get(i));
}
bundle.putStringArrayList(key, stringArrayList);
} else if (jsonArray.get(0) instanceof Integer) {
ArrayList<Integer> integerArrayList = new ArrayList<>();
for (int i = 0; i < jsonArray.length(); i++) {
integerArrayList.add((Integer) jsonArray.get(i));
}
bundle.putIntegerArrayList(key, integerArrayList);
} else if (jsonArray.get(0) instanceof Boolean) {
boolean[] booleanArray = new boolean[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
booleanArray[i] = (Boolean)jsonArray.get(i);
}
bundle.putBooleanArray(key, booleanArray);
} else if (jsonArray.get(0) instanceof Double) {
double[] doubleArray = new double[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
doubleArray[i] = (Double)jsonArray.get(i);
}
bundle.putDoubleArray(key, doubleArray);
} else if (jsonArray.get(0) instanceof Long) {
long[] longArray = new long[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) {
longArray[i] = (Long) jsonArray.get(i);
}
bundle.putLongArray(key, longArray);
} else if (jsonArray.get(0) instanceof JSONObject) {
ArrayList<Bundle> bundleArrayList = new ArrayList<>();
for (int i =0; i < jsonArray.length(); i++) {
@@ -162,7 +180,11 @@ public class BundleJSONConverter {
JSONArray jsonArray = new JSONArray();
List<Object> listValue = (List<Object>) value;
for (Object objValue : listValue) {
if (objValue instanceof String) {
if (objValue instanceof String
|| objValue instanceof Integer
|| objValue instanceof Double
|| objValue instanceof Long
|| objValue instanceof Boolean) {
jsonArray.put(objValue);
} else if (objValue instanceof Bundle) {
jsonArray.put(convertToJSON((Bundle) objValue));

View File

@@ -96,13 +96,15 @@ public class RNFirebaseMessaging extends ReactContextBaseJavaModule {
}
@ReactMethod
public void subscribeToTopic(String topic) {
public void subscribeToTopic(String topic, Promise promise) {
FirebaseMessaging.getInstance().subscribeToTopic(topic);
promise.resolve(null);
}
@ReactMethod
public void unsubscribeFromTopic(String topic) {
public void unsubscribeFromTopic(String topic, Promise promise) {
FirebaseMessaging.getInstance().unsubscribeFromTopic(topic);
promise.resolve(null);
}
private class MessageReceiver extends BroadcastReceiver {

View File

@@ -35,11 +35,15 @@ public class RNFirebaseMessagingService extends FirebaseMessagingService {
// Broadcast it so it is only available to the RN Application
LocalBroadcastManager.getInstance(this).sendBroadcast(messagingEvent);
} else {
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(this.getApplicationContext(), RNFirebaseBackgroundMessagingService.class);
headlessIntent.putExtra("message", message);
this.getApplicationContext().startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
try {
// If the app is in the background we send it to the Headless JS Service
Intent headlessIntent = new Intent(this.getApplicationContext(), RNFirebaseBackgroundMessagingService.class);
headlessIntent.putExtra("message", message);
this.getApplicationContext().startService(headlessIntent);
HeadlessJsTaskService.acquireWakeLockNow(this.getApplicationContext());
} catch (IllegalStateException ex) {
Log.e(TAG, "Background messages will only work if the message priority is set to 'high'", ex);
}
}
}
}

View File

@@ -64,7 +64,7 @@ public class RNFirebaseNotificationManager {
this.preferences = context.getSharedPreferences(PREFERENCES_KEY, Context.MODE_PRIVATE);
}
public void cancelAllNotifications() {
public void cancelAllNotifications(Promise promise) {
try {
Map<String, ?> notifications = preferences.getAll();
@@ -72,16 +72,25 @@ public class RNFirebaseNotificationManager {
cancelAlarm(notificationId);
}
preferences.edit().clear().apply();
promise.resolve(null);
} catch (SecurityException e) {
// TODO: Identify what these situations are
// In some devices/situations cancelAllLocalNotifications can throw a SecurityException.
Log.e(TAG, e.getMessage());
promise.reject("notification/cancel_notifications_error", "Could not cancel notifications", e);
}
}
public void cancelNotification(String notificationId) {
cancelAlarm(notificationId);
preferences.edit().remove(notificationId).apply();
public void cancelNotification(String notificationId, Promise promise) {
try {
cancelAlarm(notificationId);
preferences.edit().remove(notificationId).apply();
} catch (SecurityException e) {
// TODO: Identify what these situations are
// In some devices/situations cancelAllLocalNotifications can throw a SecurityException.
Log.e(TAG, e.getMessage());
promise.reject("notification/cancel_notification_error", "Could not cancel notifications", e);
}
}
public void createChannel(ReadableMap channelMap) {
@@ -162,12 +171,14 @@ public class RNFirebaseNotificationManager {
return array;
}
public void removeAllDeliveredNotifications() {
public void removeAllDeliveredNotifications(Promise promise) {
notificationManager.cancelAll();
promise.resolve(null);
}
public void removeDeliveredNotification(String notificationId) {
public void removeDeliveredNotification(String notificationId, Promise promise) {
notificationManager.cancel(notificationId.hashCode());
promise.resolve(null);
}
@@ -236,6 +247,41 @@ public class RNFirebaseNotificationManager {
Double badgeIconType = android.getDouble("badgeIconType");
nb = nb.setBadgeIconType(badgeIconType.intValue());
}
if (android.containsKey("bigPicture")) {
Bundle bigPicture = android.getBundle("bigPicture");
NotificationCompat.BigPictureStyle bp = new NotificationCompat.BigPictureStyle();
Bitmap picture = getBitmap(bigPicture.getString("picture"));
if (picture != null) {
bp = bp.bigPicture(picture);
}
if (bigPicture.containsKey("largeIcon")) {
Bitmap largeIcon = getBitmap(bigPicture.getString("largeIcon"));
if (largeIcon != null) {
bp = bp.bigLargeIcon(largeIcon);
}
}
if (bigPicture.containsKey("contentTitle")) {
bp = bp.setBigContentTitle(bigPicture.getString("contentTitle"));
}
if (bigPicture.containsKey("summaryText")) {
bp = bp.setSummaryText(bigPicture.getString("summaryText"));
}
nb = nb.setStyle(bp);
}
if (android.containsKey("bigText")) {
Bundle bigText = android.getBundle("bigText");
NotificationCompat.BigTextStyle bt = new NotificationCompat.BigTextStyle();
bt.bigText(bigText.getString("text"));
if (bigText.containsKey("contentTitle")) {
bt = bt.setBigContentTitle(bigText.getString("contentTitle"));
}
if (bigText.containsKey("summaryText")) {
bt = bt.setSummaryText(bigText.getString("summaryText"));
}
nb = nb.setStyle(bt);
}
if (android.containsKey("category")) {
nb = nb.setCategory(android.getString("category"));
}
@@ -352,12 +398,14 @@ public class RNFirebaseNotificationManager {
nb = nb.setUsesChronometer(android.getBoolean("usesChronometer"));
}
if (android.containsKey("vibrate")) {
double[] vibrate = android.getDoubleArray("vibrate");
long[] vibrateArray = new long[vibrate.length];
for (int i = 0; i < vibrate.length; i++) {
vibrateArray[i] = ((Double)vibrate[i]).longValue();
ArrayList<Integer> vibrate = android.getIntegerArrayList("vibrate");
if(vibrate != null) {
long[] vibrateArray = new long[vibrate.size()];
for (int i = 0; i < vibrate.size(); i++) {
vibrateArray[i] = vibrate.get(i).longValue();
}
nb = nb.setVibrate(vibrateArray);
}
nb = nb.setVibrate(vibrateArray);
}
if (android.containsKey("visibility")) {
Double visibility = android.getDouble("visibility");
@@ -407,9 +455,8 @@ public class RNFirebaseNotificationManager {
Utils.sendEvent(reactContext, "notifications_notification_displayed", Arguments.fromBundle(notification));
}
} catch (Exception e) {
if (promise == null) {
Log.e(TAG, "Failed to send notification", e);
} else {
Log.e(TAG, "Failed to send notification", e);
if (promise != null) {
promise.reject("notification/display_notification_error", "Could not send notification", e);
}
}

View File

@@ -62,13 +62,13 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
}
@ReactMethod
public void cancelAllNotifications() {
notificationManager.cancelAllNotifications();
public void cancelAllNotifications(Promise promise) {
notificationManager.cancelAllNotifications(promise);
}
@ReactMethod
public void cancelNotification(String notificationId) {
notificationManager.cancelNotification(notificationId);
public void cancelNotification(String notificationId, Promise promise) {
notificationManager.cancelNotification(notificationId, promise);
}
@ReactMethod
@@ -103,17 +103,17 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
}
@ReactMethod
public void removeAllDeliveredNotifications() {
notificationManager.removeAllDeliveredNotifications();
public void removeAllDeliveredNotifications(Promise promise) {
notificationManager.removeAllDeliveredNotifications(promise);
}
@ReactMethod
public void removeDeliveredNotification(String notificationId) {
notificationManager.removeDeliveredNotification(notificationId);
public void removeDeliveredNotification(String notificationId, Promise promise) {
notificationManager.removeDeliveredNotification(notificationId, promise);
}
@ReactMethod
public void setBadge(int badge) {
public void setBadge(int badge, Promise promise) {
// Store the badge count for later retrieval
sharedPreferences.edit().putInt(BADGE_KEY, badge).apply();
if (badge == 0) {
@@ -123,6 +123,7 @@ public class RNFirebaseNotifications extends ReactContextBaseJavaModule implemen
Log.d(TAG, "Apply badge count: " + badge);
ShortcutBadger.applyCount(this.getReactApplicationContext(), badge);
}
promise.resolve(null);
}
@ReactMethod