Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Merge pull request #2 from wizpanda/firebase-changes
Browse files Browse the repository at this point in the history
Fixes for latest firebase changes
  • Loading branch information
sagrawal31 authored May 17, 2019
2 parents 247b6a2 + 289706f commit ad537b6
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 264 deletions.
17 changes: 0 additions & 17 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,6 @@ window.FirebasePlugin.getValue("key", function(value) {
}, function(error) {
console.error(error);
});
// or, specify a namespace for the config value
window.FirebasePlugin.getValue("key", "namespace", function(value) {
console.log(value);
}, function(error) {
console.error(error);
});
```

## getByteArray (Android only)
Expand All @@ -272,15 +266,6 @@ window.FirebasePlugin.getByteArray("key", function(bytes) {
}, function(error) {
console.error(error);
});
// or, specify a namespace for the byte array
window.FirebasePlugin.getByteArray("key", "namespace", function(bytes) {
// a Base64 encoded string that represents the value for "key"
console.log(bytes.base64);
// a numeric array containing the values of the byte array (i.e. [0xFF, 0x00])
console.log(bytes.array);
}, function(error) {
console.error(error);
});
```

## getInfo (Android only)
Expand Down Expand Up @@ -332,8 +317,6 @@ var defaults = {
}
// set defaults
window.FirebasePlugin.setDefaults(defaults);
// or, specify a namespace
window.FirebasePlugin.setDefaults(defaults, "namespace");
```

## startTrace
Expand Down
8 changes: 0 additions & 8 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,17 @@ xmlns:android="http://schemas.android.com/apk/res/android">
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
<service android:name="org.apache.cordova.firebase.FirebasePluginInstanceIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT"/>
</intent-filter>
</service>
<receiver android:name="org.apache.cordova.firebase.OnNotificationOpenReceiver"></receiver>
</config-file>
<resource-file src="src/android/google-services.json" target="."/>
<resource-file src="src/android/cordova-plugin-firebase-strings.xml" target="res/values/cordova-plugin-firebase-strings.xml" />
<source-file src="src/android/FirebasePlugin.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/OnNotificationOpenReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginInstanceIDService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessagingService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessageReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessageReceiverManager.java" target-dir="src/org/apache/cordova/firebase" />
Expand Down
38 changes: 10 additions & 28 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,18 +154,10 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
}
return true;
} else if (action.equals("getByteArray")) {
if (args.length() > 1) {
this.getByteArray(callbackContext, args.getString(0), args.getString(1));
} else {
this.getByteArray(callbackContext, args.getString(0), null);
}
this.getByteArray(callbackContext, args.getString(0));
return true;
} else if (action.equals("getValue")) {
if (args.length() > 1) {
this.getValue(callbackContext, args.getString(0), args.getString(1));
} else {
this.getValue(callbackContext, args.getString(0), null);
}
this.getValue(callbackContext, args.getString(0));
return true;
} else if (action.equals("getInfo")) {
this.getInfo(callbackContext);
Expand All @@ -174,11 +166,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
this.setConfigSettings(callbackContext, args.getJSONObject(0));
return true;
} else if (action.equals("setDefaults")) {
if (args.length() > 1) {
this.setDefaults(callbackContext, args.getJSONObject(0), args.getString(1));
} else {
this.setDefaults(callbackContext, args.getJSONObject(0), null);
}
this.setDefaults(callbackContext, args.getJSONObject(0));
return true;
} else if (action.equals("verifyPhoneNumber")) {
this.verifyPhoneNumber(callbackContext, args.getString(0), args.getInt(1));
Expand Down Expand Up @@ -602,12 +590,11 @@ public void onFailure(Exception e) {
});
}

private void getByteArray(final CallbackContext callbackContext, final String key, final String namespace) {
private void getByteArray(final CallbackContext callbackContext, final String key) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
byte[] bytes = namespace == null ? FirebaseRemoteConfig.getInstance().getByteArray(key)
: FirebaseRemoteConfig.getInstance().getByteArray(key, namespace);
byte[] bytes = FirebaseRemoteConfig.getInstance().getByteArray(key);
JSONObject object = new JSONObject();
object.put("base64", Base64.encodeToString(bytes, Base64.DEFAULT));
object.put("array", new JSONArray(bytes));
Expand All @@ -620,13 +607,11 @@ public void run() {
});
}

private void getValue(final CallbackContext callbackContext, final String key, final String namespace) {
private void getValue(final CallbackContext callbackContext, final String key) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
FirebaseRemoteConfigValue value = namespace == null
? FirebaseRemoteConfig.getInstance().getValue(key)
: FirebaseRemoteConfig.getInstance().getValue(key, namespace);
FirebaseRemoteConfigValue value = FirebaseRemoteConfig.getInstance().getValue(key);
callbackContext.success(value.asString());
} catch (Exception e) {
Crashlytics.logException(e);
Expand Down Expand Up @@ -676,14 +661,11 @@ public void run() {
});
}

private void setDefaults(final CallbackContext callbackContext, final JSONObject defaults, final String namespace) {
private void setDefaults(final CallbackContext callbackContext, final JSONObject defaults) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
if (namespace == null)
FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults));
else
FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults), namespace);
FirebaseRemoteConfig.getInstance().setDefaults(defaultsToMap(defaults));
callbackContext.success();
} catch (Exception e) {
Crashlytics.logException(e);
Expand Down Expand Up @@ -882,7 +864,7 @@ public void run() {
}

if (myTrace != null && myTrace instanceof Trace) {
myTrace.incrementCounter(counterNamed);
myTrace.incrementMetric(counterNamed, 1);
callbackContext.success();
} else {
callbackContext.error("Trace not found");
Expand Down
25 changes: 0 additions & 25 deletions src/android/FirebasePluginInstanceIDService.java

This file was deleted.

15 changes: 15 additions & 0 deletions src/android/FirebasePluginMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ private String getStringResource(String name) {
);
}


/**
* Called if InstanceID token is updated. This may occur if the security of
* the previous token had been compromised. Note that this is called when the InstanceID token
* is initially generated so this is where you would retrieve the token.
*/
@Override
public void onNewToken(String refreshedToken) {
super.onNewToken(refreshedToken);
Log.e("NEW_TOKEN",refreshedToken);
Log.d(TAG, "Refreshed token: " + refreshedToken);
FirebasePlugin.sendToken(refreshedToken);
}


/**
* Called when message is received.
*
Expand Down
Empty file removed src/android/build-extras.gradle
Empty file.
Loading

0 comments on commit ad537b6

Please sign in to comment.