-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(performance): add missing methods (#505)
Refactor helper methods into separate class.
- Loading branch information
Showing
4 changed files
with
57 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...ava/io/capawesome/capacitorjs/plugins/firebase/performance/FirebasePerformanceHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.capawesome.capacitorjs.plugins.firebase.performance; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
|
||
import java.util.HashMap; | ||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class FirebasePerformanceHelper { | ||
|
||
@NonNull | ||
public static Map<String, String> jsObjectToAttributesMap(JSONObject object) throws JSONException { | ||
Map<String, String> map = new HashMap<>(); | ||
Iterator<String> keys = object.keys(); | ||
while (keys.hasNext()) { | ||
String key = keys.next(); | ||
map.put(key, object.get(key).toString()); | ||
} | ||
return map; | ||
} | ||
|
||
@NonNull | ||
public static Map<String, Long> jsObjectToMetricsMap(JSONObject object) throws JSONException { | ||
Map<String, Long> map = new HashMap<>(); | ||
Iterator<String> keys = object.keys(); | ||
while (keys.hasNext()) { | ||
String key = keys.next(); | ||
if (object.get(key) instanceof Long) { | ||
map.put(key, (Long) object.get(key)); | ||
} else if (object.get(key) instanceof Double) { | ||
map.put(key, (long) Math.floor((double) object.get(key))); | ||
} else { | ||
throw new JSONException(FirebasePerformancePlugin.ERROR_INVALID_METRIC_VALUE); | ||
} | ||
} | ||
return map; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,6 +86,5 @@ import FirebasePerformance | |
self.stopTrace(traceName) | ||
} | ||
} | ||
return | ||
} | ||
} |