Skip to content

Commit

Permalink
feat: sort attendee list on the basis of ticket type (#781)
Browse files Browse the repository at this point in the history
  • Loading branch information
AkshayCHD committed Mar 18, 2018
1 parent 3d1321b commit 977ceb0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* Use the {@link AttendeesFragment#newInstance} factory method to
* create an instance of this fragment.
*/
@SuppressWarnings("PMD.TooManyMethods")
public class AttendeesFragment extends BaseFragment<IAttendeesPresenter> implements IAttendeesView {

private Context context;
Expand All @@ -63,6 +64,10 @@ public class AttendeesFragment extends BaseFragment<IAttendeesPresenter> impleme
@Inject
Lazy<IAttendeesPresenter> presenterProvider;

private static final int SORTBYTICKET = 0;
private static final int SORTBYNAME = 1;


private ItemAdapter<Attendee> fastItemAdapter;
private FragmentAttendeesBinding binding;
private SwipeRefreshLayout refreshLayout;
Expand Down Expand Up @@ -123,11 +128,28 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.filterBySync:
fastItemAdapter.filter(FILTER_SYNC);
return true;
case R.id.sortByTicket:
sortAttendees(SORTBYTICKET);
return true;
case R.id.sortByName:
sortAttendees(SORTBYNAME);
return true;
default:
return super.onOptionsItemSelected(item);
}
}

void sortAttendees(int sortBy) {
if (sortBy == SORTBYTICKET) {
fastItemAdapter.withComparator((Attendee a1, Attendee a2) -> a1.getTicket().getType().compareTo(a2.getTicket().getType()));
} else {
fastItemAdapter.withComparator((Attendee a1, Attendee a2) -> a1.getFirstname().compareTo(a2.getFirstname()), true);
}
fastItemAdapter.setNewList(getPresenter().getAttendees());
binding.setVariable(BR.attendees, getPresenter().getAttendees());
binding.executePendingBindings();
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/menu/menu_attendees.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@
android:title="@string/filter_by_sync" />
</menu>
</item>
<item android:id="@+id/sortAttendee"
android:title="@string/sort_attendee"
app:showAsAction="ifRoom">
<menu>
<item android:id="@+id/sortByName"
android:title="@string/sort_by_name" />
<item android:id="@+id/sortByTicket"
android:title="@string/sort_by_ticket_type" />
</menu>
</item>


</menu>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@
<string name="filter">filter</string>
<string name="filter_by_sync">Pending Sync</string>
<string name="filter_by_none">None</string>
<string name="sort_attendee">Sort By</string>
<string name="sort_by_name">Name</string>
<string name="sort_by_ticket_type">Ticket</string>
<string name="publish_success">Your Event is published successfully.</string>
<string name="draft_success">Your Event is unpublished successfully.</string>
<string name="request_token">Request Token</string>
Expand Down

0 comments on commit 977ceb0

Please sign in to comment.