Display artist, track number, sort by track number.
This commit is contained in:
parent
2d38870dfe
commit
167e0c7479
2 changed files with 35 additions and 4 deletions
|
@ -41,7 +41,7 @@ public class DeviceArrayAdapter extends ArrayAdapter<Device<?, ?, ?>>
|
||||||
* @param deviceType One of RENDERER or SERVER.
|
* @param deviceType One of RENDERER or SERVER.
|
||||||
*/
|
*/
|
||||||
public DeviceArrayAdapter(Activity activity, String deviceType) {
|
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;
|
mActivity = activity;
|
||||||
mDeviceType = deviceType;
|
mDeviceType = deviceType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
package com.github.nutomic.controldlna;
|
package com.github.nutomic.controldlna;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
import org.teleal.cling.support.model.DIDLObject;
|
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.content.Context;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -15,6 +19,23 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
||||||
|
|
||||||
public FileArrayAdapter(Context context) {
|
public FileArrayAdapter(Context context) {
|
||||||
super(context, android.R.layout.simple_list_item_1);
|
super(context, android.R.layout.simple_list_item_1);
|
||||||
|
sort(new Comparator<DIDLObject>() {
|
||||||
|
|
||||||
|
@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
|
@Override
|
||||||
|
@ -22,10 +43,20 @@ public class FileArrayAdapter extends ArrayAdapter<DIDLObject> {
|
||||||
if (convertView == null) {
|
if (convertView == null) {
|
||||||
LayoutInflater inflater = (LayoutInflater) getContext()
|
LayoutInflater inflater = (LayoutInflater) getContext()
|
||||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
.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);
|
DIDLObject item = getItem(position);
|
||||||
tv.setText(getItem(position).getTitle());
|
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;
|
return convertView;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue