From a94943bfc06b071370909d31597c6bc19e751765 Mon Sep 17 00:00:00 2001 From: Salakar Date: Tue, 28 Nov 2017 09:09:58 +0000 Subject: [PATCH] fix imports --- .../firebase/database/RNFirebaseDatabase.java | 25 ++++++++++++++----- lib/utils/SyncTree.js | 2 +- tests/src/firebase.js | 2 +- tests/src/tests/core/coreTests.js | 2 +- tests/src/tests/storage/storageTests.js | 2 +- 5 files changed, 23 insertions(+), 10 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabase.java b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabase.java index ef130caa..e9900a40 100644 --- a/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabase.java +++ b/android/src/main/java/io/invertase/firebase/database/RNFirebaseDatabase.java @@ -13,6 +13,7 @@ import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.google.firebase.FirebaseApp; +import com.google.firebase.database.DatabaseException; import com.google.firebase.database.Logger; import com.google.firebase.database.MutableData; import com.google.firebase.database.OnDisconnect; @@ -35,6 +36,7 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule { private static final String TAG = "RNFirebaseDatabase"; private boolean enableLogging = false; private HashMap references = new HashMap<>(); + private HashMap loggingLevelSet = new HashMap<>(); private SparseArray transactionHandlers = new SparseArray<>(); RNFirebaseDatabase(ReactApplicationContext reactContext) { @@ -89,6 +91,8 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule { enableLogging = enabled; List firebaseAppList = FirebaseApp.getApps(getReactApplicationContext()); for (FirebaseApp app : firebaseAppList) { + loggingLevelSet.put(app.getName(), enabled); + if (enableLogging) { FirebaseDatabase.getInstance(app).setLogLevel(Logger.Level.DEBUG); } else { @@ -488,12 +492,21 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule { FirebaseApp firebaseApp = FirebaseApp.getInstance(appName); FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance(firebaseApp); -// todo errors 'calls must be made before any other usage of database instance -// if (enableLogging) { -// firebaseDatabase.setLogLevel(Logger.Level.DEBUG); -// } else { -// firebaseDatabase.setLogLevel(Logger.Level.WARN); -// } + if (enableLogging && !loggingLevelSet.get(firebaseDatabase.getApp().getName())) { + try { + loggingLevelSet.put(firebaseDatabase.getApp().getName(), enableLogging); + firebaseDatabase.setLogLevel(Logger.Level.DEBUG); + } catch (DatabaseException dex) { + // do nothing - to catch 'calls to setLogLevel must be made for use of database' errors + } + } else if (!enableLogging && loggingLevelSet.get(firebaseDatabase.getApp().getName())) { + try { + loggingLevelSet.put(firebaseDatabase.getApp().getName(), enableLogging); + firebaseDatabase.setLogLevel(Logger.Level.WARN); + } catch (DatabaseException dex) { + // do nothing - to catch 'calls to setLogLevel must be made for use of database' errors + } + } return firebaseDatabase; } diff --git a/lib/utils/SyncTree.js b/lib/utils/SyncTree.js index d8349ef4..bf726889 100644 --- a/lib/utils/SyncTree.js +++ b/lib/utils/SyncTree.js @@ -3,7 +3,7 @@ */ import { NativeEventEmitter } from 'react-native'; -import INTERNALS from './../internals'; +import INTERNALS from './internals'; import DatabaseSnapshot from './../modules/database/snapshot'; import DatabaseReference from './../modules/database/reference'; import { isString, nativeToJSError } from './../utils'; diff --git a/tests/src/firebase.js b/tests/src/firebase.js index 22709803..033b438b 100644 --- a/tests/src/firebase.js +++ b/tests/src/firebase.js @@ -1,7 +1,7 @@ import { Platform } from 'react-native'; import firebase from 'firebase'; -import RNfirebase from './../firebase/firebase'; +import RNfirebase from './../firebase'; import DatabaseContents from './tests/support/DatabaseContents'; diff --git a/tests/src/tests/core/coreTests.js b/tests/src/tests/core/coreTests.js index cd25a62d..d96e5d78 100644 --- a/tests/src/tests/core/coreTests.js +++ b/tests/src/tests/core/coreTests.js @@ -1,7 +1,7 @@ import { Platform } from 'react-native'; import should from 'should'; -import RNFirebase from './../../../firebase/firebase'; +import RNFirebase from './../../../firebase'; const androidTestConfig = { // firebase android sdk completely ignores client id diff --git a/tests/src/tests/storage/storageTests.js b/tests/src/tests/storage/storageTests.js index 90d9d61a..2aa78578 100644 --- a/tests/src/tests/storage/storageTests.js +++ b/tests/src/tests/storage/storageTests.js @@ -1,4 +1,4 @@ -import RNfirebase from './../../../firebase/firebase'; +import RNfirebase from './../../../firebase'; function storageTests({ describe, it, firebase, tryCatch }) { describe('ref(:path)', () => {