Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit e3f60f8

Browse files
Bump Firebase Android SDK to the latest available versions #1213
1 parent 2d176e8 commit e3f60f8

File tree

1 file changed

+64
-51
lines changed

1 file changed

+64
-51
lines changed

src/firebase.android.ts

Lines changed: 64 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -551,56 +551,70 @@ firebase.getRemoteConfig = arg => {
551551
const remoteConfigSettings = new com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings.Builder()
552552
.setDeveloperModeEnabled(arg.developerMode || false)
553553
.build();
554-
firebaseRemoteConfig.setConfigSettings(remoteConfigSettings);
555-
556-
// TODO async, do we need to wait?
557-
const defaults = firebase.getRemoteConfigDefaults(arg.properties);
558-
firebaseRemoteConfig.setDefaultsAsync(firebase.toHashMap(defaults));
559554

560-
const returnMethod = throttled => {
561-
// TODO async, so do we need to wait?
562-
firebaseRemoteConfig.activate();
563-
564-
const lastFetchTime = firebaseRemoteConfig.getInfo().getFetchTimeMillis();
565-
const lastFetch = new Date(lastFetchTime);
555+
firebaseRemoteConfig.setConfigSettings(remoteConfigSettings);
566556

567-
const result = {
568-
lastFetch: lastFetch,
569-
throttled: throttled,
570-
properties: {}
571-
};
557+
const addOnCompleteListener = new gmsTasks.OnCompleteListener({
558+
onComplete: task => {
559+
if (!task.isSuccessful()) {
560+
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
561+
} else {
562+
const returnMethod = throttled => {
563+
const addOnCompleteActivateListener = new gmsTasks.OnCompleteListener({
564+
onComplete: task => {
565+
if (!task.isSuccessful()) {
566+
reject((task.getException() && task.getException().getReason ? task.getException().getReason() : task.getException()));
567+
} else {
568+
const lastFetchTime = firebaseRemoteConfig.getInfo().getFetchTimeMillis();
569+
const lastFetch = new Date(lastFetchTime);
570+
571+
const result = {
572+
lastFetch: lastFetch,
573+
throttled: throttled,
574+
properties: {}
575+
};
576+
577+
for (const p in arg.properties) {
578+
const prop = arg.properties[p];
579+
const key = prop.key;
580+
const value = firebaseRemoteConfig.getString(key);
581+
// we could have the user pass in the type but this seems easier to use
582+
result.properties[key] = firebase.strongTypeify(value);
583+
}
584+
resolve(result);
585+
}
586+
}
587+
});
588+
firebaseRemoteConfig.activate().addOnCompleteListener(addOnCompleteActivateListener);
589+
};
572590

573-
for (const p in arg.properties) {
574-
const prop = arg.properties[p];
575-
const key = prop.key;
576-
const value = firebaseRemoteConfig.getString(key);
577-
// we could have the user pass in the type but this seems easier to use
578-
result.properties[key] = firebase.strongTypeify(value);
579-
}
591+
const onSuccessListener = new gmsTasks.OnSuccessListener({
592+
onSuccess: () => returnMethod(false)
593+
});
580594

581-
resolve(result);
582-
};
595+
const onFailureListener = new gmsTasks.OnFailureListener({
596+
onFailure: exception => {
597+
if (exception.getMessage() === "com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException") {
598+
returnMethod(true);
599+
} else {
600+
reject("Retrieving remote config data failed. " + exception);
601+
}
602+
}
603+
});
583604

584-
const onSuccessListener = new gmsTasks.OnSuccessListener({
585-
onSuccess: () => returnMethod(false)
586-
});
605+
// default 12 hours, just like the SDK does
606+
const expirationDuration = arg.cacheExpirationSeconds || 43200;
587607

588-
const onFailureListener = new gmsTasks.OnFailureListener({
589-
onFailure: exception => {
590-
if (exception.getMessage() === "com.google.firebase.remoteconfig.FirebaseRemoteConfigFetchThrottledException") {
591-
returnMethod(true);
592-
} else {
593-
reject("Retrieving remote config data failed. " + exception);
608+
firebaseRemoteConfig.fetch(expirationDuration)
609+
.addOnSuccessListener(onSuccessListener)
610+
.addOnFailureListener(onFailureListener);
594611
}
595612
}
596613
});
597614

598-
// default 12 hours, just like the SDK does
599-
const expirationDuration = arg.cacheExpirationSeconds || 43200;
600-
601-
firebaseRemoteConfig.fetch(expirationDuration)
602-
.addOnSuccessListener(onSuccessListener)
603-
.addOnFailureListener(onFailureListener);
615+
const defaults = firebase.getRemoteConfigDefaults(arg.properties);
616+
firebaseRemoteConfig.setDefaultsAsync(firebase.toHashMap(defaults))
617+
.addOnCompleteListener(addOnCompleteListener);
604618
};
605619

606620
try {
@@ -2304,15 +2318,15 @@ firebase.firestore.onDocumentSnapshot = (docRef: com.google.firebase.firestore.D
23042318
}
23052319

23062320
const listener = docRef.addSnapshotListener(options, new com.google.firebase.firestore.EventListener({
2307-
onEvent: ((snapshot: com.google.firebase.firestore.DocumentSnapshot, exception: com.google.firebase.firestore.FirebaseFirestoreException) => {
2308-
if (exception !== null) {
2309-
const error = "onDocumentSnapshot error code: " + exception.getCode();
2310-
onErrorCallback && onErrorCallback(new Error(error));
2311-
return;
2312-
}
2313-
onNextCallback && onNextCallback(new DocumentSnapshot(snapshot));
2314-
})
2315-
})
2321+
onEvent: ((snapshot: com.google.firebase.firestore.DocumentSnapshot, exception: com.google.firebase.firestore.FirebaseFirestoreException) => {
2322+
if (exception !== null) {
2323+
const error = "onDocumentSnapshot error code: " + exception.getCode();
2324+
onErrorCallback && onErrorCallback(new Error(error));
2325+
return;
2326+
}
2327+
onNextCallback && onNextCallback(new DocumentSnapshot(snapshot));
2328+
})
2329+
})
23162330
);
23172331

23182332
return () => listener.remove();
@@ -2345,8 +2359,7 @@ firebase.firestore.onCollectionSnapshot = (colRef: com.google.firebase.firestore
23452359
}
23462360
onNextCallback && onNextCallback(new QuerySnapshot(snapshot));
23472361
})
2348-
})
2349-
);
2362+
}));
23502363
return () => listener.remove();
23512364
};
23522365

0 commit comments

Comments
 (0)