Commit 9e92d9a2 authored by Yusuke Iwaki's avatar Yusuke Iwaki

fix code style.

parent 8035b4a7
...@@ -75,7 +75,8 @@ public class MainActivity extends AbstractAuthedActivity { ...@@ -75,7 +75,8 @@ public class MainActivity extends AbstractAuthedActivity {
.subscribe(RxView.visibility(findViewById(R.id.user_action_container))); .subscribe(RxView.visibility(findViewById(R.id.user_action_container)));
} }
private RealmListObserver<RoomSubscription> roomsObserver = new RealmListObserver<RoomSubscription>() { private RealmListObserver<RoomSubscription> roomsObserver =
new RealmListObserver<RoomSubscription>() {
@Override protected RealmResults<RoomSubscription> queryItems(Realm realm) { @Override protected RealmResults<RoomSubscription> queryItems(Realm realm) {
return realm.where(RoomSubscription.class).findAll(); return realm.where(RoomSubscription.class).findAll();
} }
......
...@@ -44,7 +44,8 @@ public class RoomFragment extends AbstractChatRoomFragment { ...@@ -44,7 +44,8 @@ public class RoomFragment extends AbstractChatRoomFragment {
} }
private RealmObjectObserver<RoomSubscription> roomObserver = new RealmObjectObserver<RoomSubscription>() { private RealmObjectObserver<RoomSubscription> roomObserver =
new RealmObjectObserver<RoomSubscription>() {
@Override protected RealmQuery<RoomSubscription> query(Realm realm) { @Override protected RealmQuery<RoomSubscription> query(Realm realm) {
return realm.where(RoomSubscription.class).equalTo("rid", roomId); return realm.where(RoomSubscription.class).equalTo("rid", roomId);
} }
......
...@@ -154,41 +154,31 @@ public class MethodCallHelper { ...@@ -154,41 +154,31 @@ public class MethodCallHelper {
} }
private Task<Long> getRoomSubscriptionRecursive(long timestamp) { private Task<Long> getRoomSubscriptionRecursive(long timestamp) {
return call("subscriptions/get", param -> param.put("$date", timestamp), task -> { return getObjectRecursive("subscriptions", updatedRooms -> {
JSONObject result = task.getResult();
long nextTimestamp = 0;
try {
nextTimestamp = result.getJSONArray("remove")
.getJSONObject(0).getJSONObject("_deletedAt").getLong("$date");
} catch (JSONException exception) {
}
try {
JSONArray updatedRooms = result.getJSONArray("update");
for (int i = 0; i < updatedRooms.length(); i++) { for (int i = 0; i < updatedRooms.length(); i++) {
updatedRooms.getJSONObject(i).put("serverConfigId", serverConfigId); updatedRooms.getJSONObject(i).put("serverConfigId", serverConfigId);
} }
}, timestamp);
}
Task<Void> saveToDB = RealmHelperBolts.executeTransaction(realm -> { private Task<Long> getRoomRecursive(long timestamp) {
realm.createOrUpdateAllFromJson(RoomSubscription.class, result.getJSONArray("update")); return getObjectRecursive("rooms", updatedRooms -> {
return null; for (int i = 0; i < updatedRooms.length(); i++) {
}); JSONObject roomJson = updatedRooms.getJSONObject(i);
String rid = roomJson.getString("_id");
if (nextTimestamp > 0 && (timestamp == 0 || nextTimestamp < timestamp)) { roomJson.put("rid", rid)
final long _next = nextTimestamp; .put("serverConfigId", serverConfigId)
return saveToDB.onSuccessTask(_task -> getRoomSubscriptionRecursive(_next)); .remove("_id");
} else {
return saveToDB.onSuccessTask(_task -> Task.forResult(0L));
} }
} catch (JSONException exception) { }, timestamp);
return Task.forError(exception);
} }
});
private interface Customizer {
void customizeResult(JSONArray updatedRooms) throws JSONException;
} }
private Task<Long> getRoomRecursive(long timestamp) { private Task<Long> getObjectRecursive(String objName, Customizer customizer, long timestamp) {
return call("rooms/get", param -> param.put("$date", timestamp), task -> { return call(objName + "/get", param -> param.put("$date", timestamp), task -> {
JSONObject result = task.getResult(); JSONObject result = task.getResult();
long nextTimestamp = 0; long nextTimestamp = 0;
...@@ -196,17 +186,12 @@ public class MethodCallHelper { ...@@ -196,17 +186,12 @@ public class MethodCallHelper {
nextTimestamp = result.getJSONArray("remove") nextTimestamp = result.getJSONArray("remove")
.getJSONObject(0).getJSONObject("_deletedAt").getLong("$date"); .getJSONObject(0).getJSONObject("_deletedAt").getLong("$date");
} catch (JSONException exception) { } catch (JSONException exception) {
// keep nextTimestamp = 0
} }
try { try {
JSONArray updatedRooms = result.getJSONArray("update"); JSONArray updatedRooms = result.getJSONArray("update");
for (int i = 0; i < updatedRooms.length(); i++) { customizer.customizeResult(updatedRooms);
JSONObject roomJson = updatedRooms.getJSONObject(i);
String rid = roomJson.getString("_id");
roomJson.put("rid", rid)
.put("serverConfigId", serverConfigId)
.remove("_id");
}
Task<Void> saveToDB = RealmHelperBolts.executeTransaction(realm -> { Task<Void> saveToDB = RealmHelperBolts.executeTransaction(realm -> {
realm.createOrUpdateAllFromJson(RoomSubscription.class, result.getJSONArray("update")); realm.createOrUpdateAllFromJson(RoomSubscription.class, result.getJSONArray("update"));
...@@ -215,7 +200,7 @@ public class MethodCallHelper { ...@@ -215,7 +200,7 @@ public class MethodCallHelper {
if (nextTimestamp > 0 && (timestamp == 0 || nextTimestamp < timestamp)) { if (nextTimestamp > 0 && (timestamp == 0 || nextTimestamp < timestamp)) {
final long _next = nextTimestamp; final long _next = nextTimestamp;
return saveToDB.onSuccessTask(_task -> getRoomRecursive(_next)); return saveToDB.onSuccessTask(_task -> getObjectRecursive(objName, customizer, _next));
} else { } else {
return saveToDB.onSuccessTask(_task -> Task.forResult(0L)); return saveToDB.onSuccessTask(_task -> Task.forResult(0L));
} }
......
...@@ -43,7 +43,8 @@ public class RoomListManager { ...@@ -43,7 +43,8 @@ public class RoomListManager {
String type = roomSubscription.getT(); String type = roomSubscription.getT();
if (RoomSubscription.TYPE_CHANNEL.equals(type) || RoomSubscription.TYPE_PRIVATE.equals(type)) { if (RoomSubscription.TYPE_CHANNEL.equals(type)
|| RoomSubscription.TYPE_PRIVATE.equals(type)) {
insertOrUpdateItem(channelsContainer, roomSubscription); insertOrUpdateItem(channelsContainer, roomSubscription);
removeItemIfExists(dmContainer, name); removeItemIfExists(dmContainer, name);
} else if (RoomSubscription.TYPE_DIRECT_MESSAGE.equals(type)) { } else if (RoomSubscription.TYPE_DIRECT_MESSAGE.equals(type)) {
...@@ -85,7 +86,8 @@ public class RoomListManager { ...@@ -85,7 +86,8 @@ public class RoomListManager {
} }
} }
private void updateRoomItemView(RoomListItemView roomListItemView, RoomSubscription roomSubscription) { private void updateRoomItemView(RoomListItemView roomListItemView,
RoomSubscription roomSubscription) {
roomListItemView roomListItemView
.setRoomId(roomSubscription.getRid()) .setRoomId(roomSubscription.getRid())
.setRoomName(roomSubscription.getName()) .setRoomName(roomSubscription.getName())
......
...@@ -4,6 +4,7 @@ import io.realm.RealmObject; ...@@ -4,6 +4,7 @@ import io.realm.RealmObject;
import io.realm.annotations.PrimaryKey; import io.realm.annotations.PrimaryKey;
/** /**
* Login-User's email
*/ */
public class Email extends RealmObject { public class Email extends RealmObject {
@PrimaryKey private String address; @PrimaryKey private String address;
......
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