[android][database] Combine snapshotToMap methods

This commit is contained in:
Chris Bianca 2017-08-22 17:31:20 +01:00
parent 7ea92751a9
commit e52e012e5e
1 changed files with 3 additions and 23 deletions

View File

@ -84,26 +84,7 @@ public class Utils {
*/
public static WritableMap snapshotToMap(DataSnapshot dataSnapshot, @Nullable String previousChildName) {
WritableMap result = Arguments.createMap();
WritableMap snapshot = Arguments.createMap();
snapshot.putString("key", dataSnapshot.getKey());
snapshot.putBoolean("exists", dataSnapshot.exists());
snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren());
snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount());
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
if (!dataSnapshot.hasChildren()) {
mapPutValue("value", dataSnapshot.getValue(), snapshot);
} else {
Object value = Utils.castValue(dataSnapshot);
if (value instanceof WritableNativeArray) {
snapshot.putArray("value", (WritableArray) value);
} else {
snapshot.putMap("value", (WritableMap) value);
}
}
WritableMap snapshot = Utils.snapshotToMap(dataSnapshot);
result.putMap("snapshot", snapshot);
result.putString("previousChildName", previousChildName);
@ -161,6 +142,8 @@ public class Utils {
snapshot.putBoolean("exists", dataSnapshot.exists());
snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren());
snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount());
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
if (!dataSnapshot.hasChildren()) {
mapPutValue("value", dataSnapshot.getValue(), snapshot);
@ -173,9 +156,6 @@ public class Utils {
}
}
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
return snapshot;
}