Skip to content

Commit

Permalink
fix: Update check-in system to work properly (#1673)
Browse files Browse the repository at this point in the history
* fix: Update check-in system to work properly

* fix: Update check-in system to work properly

* fix: Update check-in system to work properly
  • Loading branch information
ShridharGoel authored and iamareebjamal committed May 28, 2019
1 parent 9dfaf74 commit e0d2a92
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ private void sortAttendees(int sortBy) {
} else {
fastItemAdapter.withComparator((Attendee a1, Attendee a2) -> a1.getFirstname().compareTo(a2.getFirstname()), true);
}
fastItemAdapter.setNewList(getPresenter().getAttendees());
binding.setVariable(BR.attendees, getPresenter().getAttendees());
fastItemAdapter.setNewList(attendeeList);
binding.setVariable(BR.attendees, attendeeList);
binding.executePendingBindings();
}

Expand All @@ -182,7 +182,6 @@ public void onStart() {
setupRefreshListener();
setupRecyclerView();
getPresenter().attach(eventId, this);
binding.setAttendees(getPresenter().getAttendees());
getPresenter().start();
}

Expand Down Expand Up @@ -294,10 +293,16 @@ private void setupRefreshListener() {
refreshLayout.setRefreshing(false);
attendeeList.clear();
getPresenter().loadAttendeesPageWise(FIRST_PAGE, true);
fastItemAdapter.setNewList(attendeeList);
});
}

@Override
public void onResume() {
super.onResume();
attendeeList.clear();
getPresenter().loadAttendeesPageWise(FIRST_PAGE, false);
}

// View Implementation

@Override
Expand All @@ -324,9 +329,9 @@ public void showScanButton(boolean show) {

@Override
public void showResults(List<Attendee> attendees) {
attendeeList.addAll(getPresenter().getAttendees());
attendeeList.addAll(attendees);
fastItemAdapter.setNewList(attendeeList);
binding.setVariable(BR.attendees, attendees);
binding.setVariable(BR.attendees, attendeeList);
binding.executePendingBindings();
}

Expand All @@ -349,5 +354,10 @@ public void showError(String error) {
ViewUtils.showSnackbar(binding.getRoot(), error);
}

@Override
public List<Attendee> getAttendeeList() {
return attendeeList;
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public void start() {

@Override
public void detach() {
attendeeListener.stopListening();
super.detach();
attendeeListener.stopListening();
}

public List<Attendee> getAttendees() {
Expand Down Expand Up @@ -90,23 +90,23 @@ public void loadAttendeesPageWise(long pageNumber, boolean forceReload) {
}

private Observable<Attendee> getAttendeeSource(boolean forceReload) {
if (!forceReload && !attendeeList.isEmpty() && isRotated())
return Observable.fromIterable(attendeeList);
if (!forceReload && !getView().getAttendeeList().isEmpty() && isRotated())
return Observable.fromIterable(getView().getAttendeeList());
else
return attendeeRepository.getAttendees(getId(), forceReload);
}

private Observable<Attendee> getAttendeeSourcePageWise(long pageNumber, boolean forceReload) {
if (!forceReload && !attendeeList.isEmpty() && isRotated())
return Observable.fromIterable(attendeeList);
if (!forceReload && !getView().getAttendeeList().isEmpty() && isRotated())
return Observable.fromIterable(getView().getAttendeeList());
else
return attendeeRepository.getAttendeesPageWise(getId(), pageNumber, forceReload);
}

private void updateLocal(Attendee attendee) {
Utils.indexOf(attendeeList, attendee, (first, second) -> first.getId() == second.getId())
Utils.indexOf(getView().getAttendeeList(), attendee, (first, second) -> first.getId() == second.getId())
.subscribeOn(Schedulers.computation())
.subscribe(index -> attendeeList.set(index, attendee), Logger::logError);
.subscribe(index -> getView().getAttendeeList().set(index, attendee), Logger::logError);
}

private void listenToModelChanges() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.eventyay.organizer.common.mvp.view.Refreshable;
import com.eventyay.organizer.data.attendee.Attendee;

import java.util.List;

public interface AttendeesView extends Progressive, Refreshable, Erroneous, Emptiable<Attendee> {

void showScanButton(boolean show);
Expand All @@ -14,4 +16,6 @@ public interface AttendeesView extends Progressive, Refreshable, Erroneous, Empt

void showToggleDialog(long attendeeId);

List<Attendee> getAttendeeList();

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public Observable<Attendee> getAttendeesPageWise(long eventId, long pageNumber,
Observable<Attendee> networkObservable = Observable.defer(() ->
attendeeApi.getAttendeesPageWise(eventId, pageNumber)
.doOnNext(attendees -> repository
.syncSave(Attendee.class, attendees, Attendee::getId, Attendee_Table.id)
.saveList(Attendee.class, attendees)
.subscribe())
.flatMapIterable(attendees -> attendees));

Expand Down

0 comments on commit e0d2a92

Please sign in to comment.