Merge branch 'master' into medialibrary

This commit is contained in:
Adrian Ulrich 2016-11-22 10:05:46 +01:00
commit c631d17b52
2 changed files with 69 additions and 21 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013-2014 Adrian Ulrich <adrian@blinkenlights.ch> * Copyright (C) 2013-2016 Adrian Ulrich <adrian@blinkenlights.ch>
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@ import android.content.Context;
import android.app.Activity; import android.app.Activity;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.BaseAdapter;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.widget.TextView; import android.widget.TextView;
@ -31,30 +31,86 @@ import android.text.style.ForegroundColorSpan;
import android.text.Spannable; import android.text.Spannable;
import android.text.SpannableStringBuilder; import android.text.SpannableStringBuilder;
public class ShowQueueAdapter public class ShowQueueAdapter extends BaseAdapter {
extends ArrayAdapter<Song> /**
{ * The resource to pass to the inflater
*/
private int mResource; private int mResource;
/**
* The position we are going to mark as 'active'
*/
private int mHighlightRow; private int mHighlightRow;
/**
* The context to use
*/
private Context mContext; private Context mContext;
/**
* The playback service reference to query
*/
private PlaybackService mService;
public ShowQueueAdapter(Context context, int resource) { public ShowQueueAdapter(Context context, int resource) {
super(context, resource); super();
mResource = resource; mResource = resource;
mContext = context; mContext = context;
mHighlightRow = -1; mHighlightRow = -1;
} }
/** /**
* Tells the adapter to highlight a specific row id * Configures our data source
* Set this to -1 to disable the feature *
* @param service the playback service instance to use
* @param pos the row to highlight, setting this to -1 disables the feature
*/ */
public void highlightRow(int pos) { public void setData(PlaybackService service, int pos) {
mService = service;
mHighlightRow = pos; mHighlightRow = pos;
notifyDataSetChanged();
} }
/**
* Returns the number of songs in this adapter
*
* @return the number of songs in this adapter
*/
@Override
public int getCount() {
return (mService == null ? 0 : mService.getTimelineLength());
}
/**
* Returns the song at given position
*
* @param pos the position to query
* @return a Song object
*/
@Override
public Song getItem(int pos) {
return mService.getSongByQueuePosition(pos);
}
/**
* Returns the item id at `pos'
*
* @param pos the position to query
* @return the song.id at this position
*/
@Override
public long getItemId(int pos) {
return getItem(pos).id;
}
/**
* Returns always `true' as song.id's are stable
*/
@Override
public boolean hasStableIds() {
return true;
}
/**
* Returns the view
*/
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
DraggableRow row; DraggableRow row;

View File

@ -182,19 +182,11 @@ public class ShowQueueFragment extends Fragment
public void refreshSongQueueList(final boolean scroll) { public void refreshSongQueueList(final boolean scroll) {
getActivity().runOnUiThread(new Runnable(){ getActivity().runOnUiThread(new Runnable(){
public void run() { public void run() {
int i, stotal, spos; int pos = mService.getTimelinePosition();
stotal = mService.getTimelineLength(); /* Total number of songs in queue */ mListAdapter.setData(mService, pos);
spos = mService.getTimelinePosition(); /* Current position in queue */
mListAdapter.clear(); /* Flush all existing entries... */
mListAdapter.highlightRow(spos); /* and highlight current position */
for(i=0 ; i<stotal; i++) {
mListAdapter.add(mService.getSongByQueuePosition(i));
}
if(scroll) if(scroll)
scrollToCurrentSong(spos); scrollToCurrentSong(pos);
} }
}); });
} }