[android][database] Fix issue #100
This commit is contained in:
parent
c7eb09ddd5
commit
c4f8688348
|
@ -216,12 +216,12 @@ public class Utils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static boolean isArray(DataSnapshot snapshot) {
|
private static boolean isArray(DataSnapshot snapshot) {
|
||||||
long expectedKey = 0;
|
long expectedKey = -1;
|
||||||
for (DataSnapshot child : snapshot.getChildren()) {
|
for (DataSnapshot child : snapshot.getChildren()) {
|
||||||
try {
|
try {
|
||||||
long key = Long.parseLong(child.getKey());
|
long key = Long.parseLong(child.getKey());
|
||||||
if (key == expectedKey) {
|
if (key > expectedKey) {
|
||||||
expectedKey++;
|
expectedKey = key;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -238,11 +238,11 @@ public class Utils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static boolean isArray(MutableData mutableData) {
|
private static boolean isArray(MutableData mutableData) {
|
||||||
long expectedKey = 0;
|
long expectedKey = -1;
|
||||||
for (MutableData child : mutableData.getChildren()) {
|
for (MutableData child : mutableData.getChildren()) {
|
||||||
try {
|
try {
|
||||||
long key = Long.parseLong(child.getKey());
|
long key = Long.parseLong(child.getKey());
|
||||||
if (key == expectedKey) {
|
if (key > expectedKey) {
|
||||||
expectedKey++;
|
expectedKey++;
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -261,8 +261,16 @@ public class Utils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static <Any> WritableArray buildArray(DataSnapshot snapshot) {
|
private static <Any> WritableArray buildArray(DataSnapshot snapshot) {
|
||||||
|
long expectedKey = 0;
|
||||||
WritableArray array = Arguments.createArray();
|
WritableArray array = Arguments.createArray();
|
||||||
for (DataSnapshot child : snapshot.getChildren()) {
|
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);
|
Any castedChild = castValue(child);
|
||||||
switch (castedChild.getClass().getName()) {
|
switch (castedChild.getClass().getName()) {
|
||||||
case "java.lang.Boolean":
|
case "java.lang.Boolean":
|
||||||
|
@ -288,6 +296,7 @@ public class Utils {
|
||||||
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
|
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
expectedKey++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
@ -299,8 +308,16 @@ public class Utils {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private static <Any> WritableArray buildArray(MutableData mutableData) {
|
private static <Any> WritableArray buildArray(MutableData mutableData) {
|
||||||
|
long expectedKey = 0;
|
||||||
WritableArray array = Arguments.createArray();
|
WritableArray array = Arguments.createArray();
|
||||||
for (MutableData child : mutableData.getChildren()) {
|
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);
|
Any castedChild = castValue(child);
|
||||||
switch (castedChild.getClass().getName()) {
|
switch (castedChild.getClass().getName()) {
|
||||||
case "java.lang.Boolean":
|
case "java.lang.Boolean":
|
||||||
|
@ -326,6 +343,7 @@ public class Utils {
|
||||||
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
|
Log.w(TAG, "Invalid type: " + castedChild.getClass().getName());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
expectedKey++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||||
|
|
||||||
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean getUseDeveloperSupport() {
|
public boolean getUseDeveloperSupport() {
|
||||||
return BuildConfig.DEBUG;
|
return BuildConfig.DEBUG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ function childTests({ fdescribe, it, context, firebase }) {
|
||||||
// Assertion
|
// Assertion
|
||||||
console.warn(JSON.stringify(snapshot.val()));
|
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]]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue