diff --git a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java b/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java index 0853c7f..aa024c4 100644 --- a/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/DeviceArrayAdapter.java @@ -41,7 +41,7 @@ public class DeviceArrayAdapter extends ArrayAdapter> * @param deviceType One of RENDERER or SERVER. */ public DeviceArrayAdapter(Activity activity, String deviceType) { - super(activity, android.R.layout.simple_list_item_1); + super(activity, android.R.layout.simple_list_item_2); mActivity = activity; mDeviceType = deviceType; } diff --git a/src/com/github/nutomic/controldlna/FileArrayAdapter.java b/src/com/github/nutomic/controldlna/FileArrayAdapter.java index bbadfc4..b368036 100644 --- a/src/com/github/nutomic/controldlna/FileArrayAdapter.java +++ b/src/com/github/nutomic/controldlna/FileArrayAdapter.java @@ -1,8 +1,12 @@ package com.github.nutomic.controldlna; import java.util.Collection; +import java.util.Comparator; import org.teleal.cling.support.model.DIDLObject; +import org.teleal.cling.support.model.container.Container; +import org.teleal.cling.support.model.item.Item; +import org.teleal.cling.support.model.item.MusicTrack; import android.content.Context; import android.view.LayoutInflater; @@ -15,6 +19,23 @@ public class FileArrayAdapter extends ArrayAdapter { public FileArrayAdapter(Context context) { super(context, android.R.layout.simple_list_item_1); + sort(new Comparator() { + + @Override + public int compare(DIDLObject lhs, DIDLObject rhs) { + if (lhs instanceof MusicTrack && rhs instanceof MusicTrack) + return ((MusicTrack) rhs).getOriginalTrackNumber() - + ((MusicTrack) lhs).getOriginalTrackNumber(); + else if (lhs instanceof Item && rhs instanceof Container) + return 1; + else if (rhs instanceof Item && lhs instanceof Container) + return -1; + else if (lhs instanceof Container && rhs instanceof Container) + return lhs.getTitle().compareTo(rhs.getTitle()); + else + return 0; + } + }); } @Override @@ -22,10 +43,20 @@ public class FileArrayAdapter extends ArrayAdapter { if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(android.R.layout.simple_list_item_1, parent, false); + convertView = inflater.inflate(android.R.layout.simple_list_item_2, parent, false); } - TextView tv = (TextView) convertView.findViewById(android.R.id.text1); - tv.setText(getItem(position).getTitle()); + DIDLObject item = getItem(position); + TextView title = (TextView) convertView.findViewById(android.R.id.text1); + TextView artist = (TextView) convertView.findViewById(android.R.id.text2); + MusicTrack track; + if (item instanceof MusicTrack) { + track = (MusicTrack) item; + title.setText(Integer.toString(track.getOriginalTrackNumber()) + + ". " + item.getTitle()); + artist.setText(track.getArtists()[0].getName()); + } + else + title.setText(item.getTitle()); return convertView; }