2015-07-26 18:15:07 +02:00
|
|
|
package org.moire.ultrasonic.view;
|
2013-06-04 09:37:53 +02:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
|
2015-07-26 18:15:07 +02:00
|
|
|
import org.moire.ultrasonic.domain.MusicDirectory;
|
|
|
|
import org.moire.ultrasonic.service.DownloadFile;
|
2013-06-04 09:37:53 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class SongListAdapter extends ArrayAdapter<DownloadFile>
|
|
|
|
{
|
|
|
|
Context context;
|
|
|
|
|
|
|
|
public SongListAdapter(Context context, final List<DownloadFile> entries)
|
|
|
|
{
|
|
|
|
super(context, android.R.layout.simple_list_item_1, entries);
|
|
|
|
this.context = context;
|
|
|
|
}
|
2013-06-04 09:37:53 +02:00
|
|
|
|
2013-12-04 07:36:02 +01:00
|
|
|
@Override
|
|
|
|
public View getView(final int position, final View convertView, final ViewGroup parent)
|
|
|
|
{
|
2013-12-07 07:13:36 +01:00
|
|
|
DownloadFile downloadFile = getItem(position);
|
2021-10-13 20:59:28 +02:00
|
|
|
MusicDirectory.Entry entry = downloadFile.getSong();
|
2013-12-07 07:13:36 +01:00
|
|
|
|
|
|
|
SongView view;
|
|
|
|
|
2021-05-19 18:37:54 +02:00
|
|
|
if (convertView instanceof SongView)
|
2013-12-07 07:13:36 +01:00
|
|
|
{
|
|
|
|
SongView currentView = (SongView) convertView;
|
|
|
|
if (currentView.getEntry().equals(entry))
|
|
|
|
{
|
|
|
|
currentView.update();
|
|
|
|
return currentView;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-23 09:50:49 +01:00
|
|
|
EntryAdapter.SongViewHolder viewHolder = (EntryAdapter.SongViewHolder) convertView.getTag();
|
|
|
|
view = currentView;
|
|
|
|
view.setViewHolder(viewHolder);
|
2013-12-07 07:13:36 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
view = new SongView(this.context);
|
2014-01-23 09:50:49 +01:00
|
|
|
view.setLayout(entry);
|
2013-12-07 07:13:36 +01:00
|
|
|
}
|
|
|
|
|
2013-12-21 17:58:21 +01:00
|
|
|
view.setSong(entry, false, true);
|
2013-12-04 07:36:02 +01:00
|
|
|
return view;
|
|
|
|
}
|
2013-12-07 07:13:36 +01:00
|
|
|
}
|