Commit f9e48f49 authored by Filipe de Lima Brito's avatar Filipe de Lima Brito

Update MethodCallHelper.java

parent a41ab15e
......@@ -481,24 +481,34 @@ public class MethodCallHelper {
.put(new JSONObject().put("rooms", true).put("users", true))
).onSuccessTask(CONVERT_TO_JSON_OBJECT)
.onSuccessTask(task -> {
String jsonString = "";
final JSONObject result = task.getResult();
if (result.has("rooms") && result.has("users")) {
JSONArray jsonRoomArray = (JSONArray) result.get("rooms");
JSONArray jsonUserArray = (JSONArray) result.get("users");
String roomJsonString = jsonRoomArray.toString().replace("[","").replace("]","");
String userJsonString = jsonUserArray.toString().replace("[","").replace("]","");
String jsonString = "[" + roomJsonString + "," + userJsonString + "]";
Log.i("JSON", jsonString);
realmHelper.executeTransaction(new Transaction() {
@Override
public Object execute(Realm realm) throws JSONException {
realm.delete(RealmSpotlight.class);
realm.createOrUpdateAllFromJson(RealmSpotlight.class, jsonString);
return null;
}
if (result.has("rooms")) {
JSONArray roomJsonArray = (JSONArray) result.get("rooms");
jsonString = roomJsonArray.toString();
}
if (result.has("users")) {
JSONArray userJsonArray = (JSONArray) result.get("users");
int usersTotal = userJsonArray.length();
for (int i = 0; i < usersTotal; ++i) {
RealmSpotlight.Companion.customizeUserJsonObject(userJsonArray.getJSONObject(i));
}
if (jsonString.equals("")) {
jsonString = userJsonArray.toString();
} else {
jsonString = jsonString.replace("]", "") + "," + userJsonArray.toString().replace("[", "");
}
}
if (!jsonString.equals("")) {
String jsonStringResults = jsonString;
realmHelper.executeTransaction(realm -> {
realm.delete(RealmSpotlight.class);
realm.createOrUpdateAllFromJson(RealmSpotlight.class, jsonStringResults);
return null;
});
}
return null;
......@@ -533,4 +543,4 @@ public class MethodCallHelper {
protected interface ParamBuilder {
JSONArray buildParam() throws JSONException;
}
}
\ No newline at end of file
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment