[android][database] Fix issue #100

This commit is contained in:
Chris Bianca 2017-05-10 20:44:28 +01:00
parent c7eb09ddd5
commit c4f8688348
3 changed files with 25 additions and 7 deletions

View File

@ -216,12 +216,12 @@ public class Utils {
* @return
*/
private static boolean isArray(DataSnapshot snapshot) {
long expectedKey = 0;
long expectedKey = -1;
for (DataSnapshot child : snapshot.getChildren()) {
try {
long key = Long.parseLong(child.getKey());
if (key == expectedKey) {
expectedKey++;
if (key > expectedKey) {
expectedKey = key;
} else {
return false;
}
@ -238,11 +238,11 @@ public class Utils {
* @return
*/
private static boolean isArray(MutableData mutableData) {
long expectedKey = 0;
long expectedKey = -1;
for (MutableData child : mutableData.getChildren()) {
try {
long key = Long.parseLong(child.getKey());
if (key == expectedKey) {
if (key > expectedKey) {
expectedKey++;
} else {
return false;
@ -261,8 +261,16 @@ public class Utils {
* @return
*/
private static <Any> WritableArray buildArray(DataSnapshot snapshot) {
long expectedKey = 0;
WritableArray array = Arguments.createArray();
for (DataSnapshot child : snapshot.getChildren()) {
long key = Long.parseLong(child.getKey());
if (key > expectedKey) {
for (long i = expectedKey; i < key; i++) {
array.pushNull();
}
expectedKey = key;
}
Any castedChild = castValue(child);
switch (castedChild.getClass().getName()) {
case "java.lang.Boolean":
@ -288,6 +296,7 @@ public class Utils {
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
break;
}
expectedKey++;
}
return array;
}
@ -299,8 +308,16 @@ public class Utils {
* @return
*/
private static <Any> WritableArray buildArray(MutableData mutableData) {
long expectedKey = 0;
WritableArray array = Arguments.createArray();
for (MutableData child : mutableData.getChildren()) {
long key = Long.parseLong(child.getKey());
if (key > expectedKey) {
for (long i = expectedKey; i < key; i++) {
array.pushNull();
}
expectedKey = key;
}
Any castedChild = castValue(child);
switch (castedChild.getClass().getName()) {
case "java.lang.Boolean":
@ -326,6 +343,7 @@ public class Utils {
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
break;
}
expectedKey++;
}
return array;
}

View File

@ -17,7 +17,7 @@ public class MainApplication extends Application implements ReactApplication {
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
@Override
protected boolean getUseDeveloperSupport() {
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

View File

@ -14,7 +14,7 @@ function childTests({ fdescribe, it, context, firebase }) {
// Assertion
console.warn(JSON.stringify(snapshot.val()));
snapshot.val().should.eql(DatabaseContents.ISSUES[100]);
snapshot.val().should.eql([null, DatabaseContents.ISSUES[100][1], DatabaseContents.ISSUES[100][2], DatabaseContents.ISSUES[100][3]]);
});
});
});