Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ne1c committed Dec 17, 2015
1 parent 030a5b8 commit 092f012
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ public void loadRooms() {

@SuppressWarnings("unchecked")
Subscription sub = mDataManger.getRooms().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(roomModels -> {
mAllRooms = (ArrayList<RoomModel>) roomModels.clone();

ArrayList<RoomModel> visibleList = new ArrayList<>();

for (RoomModel room : roomModels) {
if (!room.hide) {
visibleList.add(room);
Expand All @@ -63,6 +63,7 @@ public void loadRooms() {

return visibleList;
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mView::showRooms, throwable -> {
mView.showError(throwable.getMessage());
});
Expand All @@ -87,7 +88,6 @@ public ArrayList<RoomModel> getOnlyVisibleRooms(ArrayList<RoomModel> rooms) {

public void loadCachedRooms() {
mDataManger.getDbRooms().subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.map(roomModels -> {
ArrayList<RoomModel> visibleList = new ArrayList<>();
for (RoomModel room : roomModels) {
Expand All @@ -98,6 +98,9 @@ public void loadCachedRooms() {

return visibleList;
})
.subscribe(mView::showRooms);
.observeOn(AndroidSchedulers.mainThread())
.subscribe(mView::showRooms, throwable -> {
mView.showError(throwable.getMessage());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public Observable<ArrayList<RoomModel>> getRooms() {
Observable<ArrayList<RoomModel>> dbRooms = mClientDatabase.getRooms();

return Observable.combineLatest(serverRooms, dbRooms, (server, db) -> {
ArrayList<RoomModel> result = new ArrayList<>();

// Data exist in db ang get from server
if (db.size() > 0 && server.size() > 0) {
for (RoomModel r1 : db) {
Expand All @@ -55,19 +53,19 @@ public Observable<ArrayList<RoomModel>> getRooms() {
Collections.sort(server, new RoomModel.SortedByPosition());
mClientDatabase.insertRooms(server);

result = server;
return server;
} else if (db.size() > 0 && server.size() == 0) { // If data exist only in db
Collections.sort(db, new RoomModel.SortedByPosition());

result = db;
return db;
} else if (db.size() == 0 && server.size() > 0) { // If data not exist in db, only server
sortByName(server);
mClientDatabase.insertRooms(server);

result = db;
return server;
}

return result;
return new ArrayList<>();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,

mPresenter.bindView(this);
mPresenter.loadCachedRooms();
mPresenter.loadRooms();

return v;
}
Expand All @@ -85,7 +86,6 @@ public boolean isEdit() {
public void onResume() {
super.onResume();

mPresenter.loadRooms();
}

public void setEdit(boolean edit) {
Expand Down

0 comments on commit 092f012

Please sign in to comment.