Sort routes by name.
This commit is contained in:
parent
1b9e2f0e49
commit
126e79a2b5
2 changed files with 14 additions and 0 deletions
|
@ -163,6 +163,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
||||||
mRouteAdapter = new RouteAdapter(getActivity());
|
mRouteAdapter = new RouteAdapter(getActivity());
|
||||||
mRouteAdapter.add(MediaRouter.getInstance(getActivity()).getRoutes());
|
mRouteAdapter.add(MediaRouter.getInstance(getActivity()).getRoutes());
|
||||||
mRouteAdapter.remove(MediaRouter.getInstance(getActivity()).getDefaultRoute());
|
mRouteAdapter.remove(MediaRouter.getInstance(getActivity()).getDefaultRoute());
|
||||||
|
mRouteAdapter.sort(RouteAdapter.COMPARATOR);
|
||||||
mPlaylistAdapter = new FileArrayAdapter(getActivity());
|
mPlaylistAdapter = new FileArrayAdapter(getActivity());
|
||||||
|
|
||||||
mListView = (ListView) getView().findViewById(R.id.listview);
|
mListView = (ListView) getView().findViewById(R.id.listview);
|
||||||
|
@ -246,6 +247,7 @@ public class RouteFragment extends MediaRouteDiscoveryFragment implements
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mRouteAdapter.add(route);
|
mRouteAdapter.add(route);
|
||||||
|
mRouteAdapter.sort(RouteAdapter.COMPARATOR);
|
||||||
|
|
||||||
RouteInfo current = mMediaRouterPlayService.getCurrentRoute();
|
RouteInfo current = mMediaRouterPlayService.getCurrentRoute();
|
||||||
if (current != null && route.getId().equals(current.getId())) {
|
if (current != null && route.getId().equals(current.getId())) {
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package com.github.nutomic.controldlna.utility;
|
package com.github.nutomic.controldlna.utility;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.database.DataSetObserver;
|
||||||
import android.support.v7.media.MediaRouter.RouteInfo;
|
import android.support.v7.media.MediaRouter.RouteInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -14,6 +16,16 @@ import com.github.nutomic.controldlna.R;
|
||||||
|
|
||||||
public class RouteAdapter extends ArrayAdapter<RouteInfo> {
|
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) {
|
public RouteAdapter(Context context) {
|
||||||
super(context, R.layout.list_item);
|
super(context, R.layout.list_item);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue