Sort routes by name.

This commit is contained in:
Felix Ableitner 2014-05-10 14:58:12 +02:00
parent 1b9e2f0e49
commit 126e79a2b5
2 changed files with 14 additions and 0 deletions

View file

@ -163,6 +163,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
mRouteAdapter = new RouteAdapter(getActivity());
mRouteAdapter.add(MediaRouter.getInstance(getActivity()).getRoutes());
mRouteAdapter.remove(MediaRouter.getInstance(getActivity()).getDefaultRoute());
mRouteAdapter.sort(RouteAdapter.COMPARATOR);
mPlaylistAdapter = new FileArrayAdapter(getActivity());
mListView = (ListView) getView().findViewById(R.id.listview);
@ -246,6 +247,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
}
}
mRouteAdapter.add(route);
mRouteAdapter.sort(RouteAdapter.COMPARATOR);
RouteInfo current = mMediaRouterPlayService.getCurrentRoute();
if (current != null && route.getId().equals(current.getId())) {

View file

@ -1,8 +1,10 @@
package com.github.nutomic.controldlna.utility;
import java.util.Comparator;
import java.util.List;
import android.content.Context;
import android.database.DataSetObserver;
import android.support.v7.media.MediaRouter.RouteInfo;
import android.view.LayoutInflater;
import android.view.View;
@ -14,6 +16,16 @@ import com.github.nutomic.controldlna.R;
public class RouteAdapter extends ArrayAdapter<RouteInfo> {
/**
* Sorts routes by name. Call {@code sort(COMPARATOR)} whenever an item is inserted.
*/
public static final Comparator COMPARATOR = new Comparator<RouteInfo>() {
@Override
public int compare(RouteInfo lhs, RouteInfo rhs) {
return lhs.getName().compareTo(rhs.getName());
}
};
public RouteAdapter(Context context) {
super(context, R.layout.list_item);
}