CR Changes

This commit is contained in:
Akshet Pandey 2018-03-21 13:08:46 -07:00
parent cc8799b465
commit a9470e78c5
2 changed files with 21 additions and 14 deletions

View File

@ -54,7 +54,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
*/ */
@ReactMethod @ReactMethod
public void goOnline(String appName, String dbURL) { public void goOnline(String appName, String dbURL) {
getDatabaseForApp(appName, dbURL).goOnline(); getDatabaseForAppAndSetLogging(appName, dbURL).goOnline();
} }
/** /**
@ -62,7 +62,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
*/ */
@ReactMethod @ReactMethod
public void goOffline(String appName, String dbURL) { public void goOffline(String appName, String dbURL) {
getDatabaseForApp(appName, dbURL).goOffline(); getDatabaseForAppAndSetLogging(appName, dbURL).goOffline();
} }
/** /**
@ -71,7 +71,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
*/ */
@ReactMethod @ReactMethod
public void setPersistence(String appName, String dbURL, Boolean state) { public void setPersistence(String appName, String dbURL, Boolean state) {
getDatabaseForApp(appName, dbURL).setPersistenceEnabled(state); getDatabaseForAppAndSetLogging(appName, dbURL).setPersistenceEnabled(state);
} }
/** /**
@ -80,7 +80,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
*/ */
@ReactMethod @ReactMethod
public void setPersistenceCacheSizeBytes(String appName, String dbURL, int size) { public void setPersistenceCacheSizeBytes(String appName, String dbURL, int size) {
getDatabaseForApp(appName, dbURL).setPersistenceCacheSizeBytes((long) size); getDatabaseForAppAndSetLogging(appName, dbURL).setPersistenceCacheSizeBytes((long) size);
} }
@ -494,9 +494,10 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
* Get a database instance for a specific firebase app instance * Get a database instance for a specific firebase app instance
* *
* @param appName * @param appName
* @param dbURL
* @return * @return
*/ */
private FirebaseDatabase getDatabaseForApp(String appName, String dbURL) { public static FirebaseDatabase getDatabaseForApp(String appName, String dbURL) {
FirebaseDatabase firebaseDatabase; FirebaseDatabase firebaseDatabase;
if(dbURL != null && dbURL.length() > 0) { if(dbURL != null && dbURL.length() > 0) {
firebaseDatabase = FirebaseDatabase.getInstance(dbURL); firebaseDatabase = FirebaseDatabase.getInstance(dbURL);
@ -504,6 +505,19 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
firebaseDatabase = FirebaseDatabase.getInstance(firebaseApp); firebaseDatabase = FirebaseDatabase.getInstance(firebaseApp);
} }
return firebaseDatabase;
}
/**
* Get a database instance for a specific firebase app instance and enable/disable logging
*
* @param appName
* @param dbURL
* @return
*/
private FirebaseDatabase getDatabaseForAppAndSetLogging(String appName, String dbURL) {
FirebaseDatabase firebaseDatabase = RNFirebaseDatabase.getDatabaseForApp(appName, dbURL);
Boolean logLevel = loggingLevelSet.get(firebaseDatabase.getApp().getName()); Boolean logLevel = loggingLevelSet.get(firebaseDatabase.getApp().getName());
if (enableLogging && (logLevel == null || !logLevel)) { if (enableLogging && (logLevel == null || !logLevel)) {
@ -541,7 +555,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
* @return * @return
*/ */
private DatabaseReference getReferenceForAppPath(String appName, String dbURL, String path) { private DatabaseReference getReferenceForAppPath(String appName, String dbURL, String path) {
return getDatabaseForApp(appName, dbURL).getReference(path); return getDatabaseForAppAndSetLogging(appName, dbURL).getReference(path);
} }
/** /**

View File

@ -348,14 +348,7 @@ class RNFirebaseDatabaseReference {
* @return * @return
*/ */
private void buildDatabaseQueryAtPathAndModifiers(String path, ReadableArray modifiers) { private void buildDatabaseQueryAtPathAndModifiers(String path, ReadableArray modifiers) {
FirebaseDatabase firebaseDatabase; FirebaseDatabase firebaseDatabase = RNFirebaseDatabase.getDatabaseForApp(appName, dbURL);
if(dbURL != null && dbURL.length() > 0) {
firebaseDatabase = FirebaseDatabase.getInstance(dbURL);
} else {
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
firebaseDatabase= FirebaseDatabase.getInstance(firebaseApp);
}
query = firebaseDatabase.getReference(path); query = firebaseDatabase.getReference(path);
List<Object> modifiersList = Utils.recursivelyDeconstructReadableArray(modifiers); List<Object> modifiersList = Utils.recursivelyDeconstructReadableArray(modifiers);