From 573bc7e78fde413ba5dad4c9277f6af05e21135b Mon Sep 17 00:00:00 2001 From: lado Date: Tue, 12 Feb 2013 22:27:52 +0100 Subject: Feature #1074 --- .../de/bjusystems/vdrmanager/gui/EventAdapter.java | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'vdrmanager/src') diff --git a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java index 8b77fa6..052192f 100644 --- a/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java +++ b/vdrmanager/src/de/bjusystems/vdrmanager/gui/EventAdapter.java @@ -1,6 +1,8 @@ package de.bjusystems.vdrmanager.gui; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import android.content.Context; @@ -61,6 +63,51 @@ abstract class EventAdapter extends ArrayAdapter implements items.add(object); super.add(object); } + + + void sort(int sortBy){ + + ArrayList events = new ArrayList(items); + + if(sortBy == BaseEventListActivity.MENU_GROUP_ALPHABET){ + + Collections.sort(events, new Comparator() { + @Override + public int compare(EventListItem lhs, EventListItem rhs) { + if(lhs == null || lhs.getTitle() == null){ + return 1; + } + if(rhs == null || rhs.getTitle() == null){ + return 0; + } + return lhs.getTitle().compareTo(rhs.getTitle()); + } + }); + + } else if(sortBy == BaseEventListActivity.MENU_GROUP_TIME) { + + Collections.sort(events, new Comparator() { + @Override + public int compare(EventListItem lhs, EventListItem rhs) { + if(lhs == null || lhs.getStart() == null){ + return 1; + } + if(rhs == null || rhs.getStart() == null){ + return 0; + } + return lhs.getStart().compareTo(rhs.getStart()); + } + }); + + } + + clear(); + for(EventListItem eli : events){ + add(eli); + } + + notifyDataSetChanged(); + } @Override public int getItemViewType(int position) { -- cgit v1.2.3