Commit 19ccff83 authored by Sébastien Toque's avatar Sébastien Toque
Browse files

Highlight current audio media

parent 1bf432ee
......@@ -506,6 +506,12 @@ public class AudioService extends Service {
return medias;
}
public String getItem() {
return mCurrentMedia != null
? mCurrentMedia.getPath()
: null;
}
@Override
public void next() throws RemoteException {
AudioService.this.next();
......
......@@ -90,6 +90,15 @@ public class AudioServiceController implements IAudioPlayerControl {
return new ArrayList<String>();
}
public String getItem() {
try {
return mAudioServiceBinder.getItem();
} catch (RemoteException e) {
Log.e(TAG, "remote procedure call failed: getItem()");
}
return null;
}
/**
* Bind to audio service if it is running
*/
......
......@@ -190,10 +190,13 @@ public class AudioListActivity extends ListActivity {
int mode = getIntent().getIntExtra(EXTRA_MODE, 0);
List<Media> audioList;
List<String> itemList;
String currentItem = null;
int currentIndex = -1;
if (name == null || mode == 0) {
mTitle.setText(R.string.songs);
itemList = AudioServiceController.getInstance().getItems();
currentItem = AudioServiceController.getInstance().getItem();
audioList = MediaLibrary.getInstance(this).getMediaItems(itemList);
}
else {
......@@ -214,9 +217,15 @@ public class AudioListActivity extends ListActivity {
if (mSortReverse) {
Collections.reverse(audioList);
}
for (int i = 0; i < audioList.size(); i++) {
mSongsAdapter.add(audioList.get(i));
Media media = audioList.get(i);
if (currentItem != null && currentItem.equals(media.getPath()))
currentIndex = i;
mSongsAdapter.add(media);
}
mSongsAdapter.setCurrentIndex(currentIndex);
getListView().setSelection(currentIndex);
mSongsAdapter.notifyDataSetChanged();
}
......
......@@ -27,6 +27,7 @@ import org.videolan.vlc.Media;
import org.videolan.vlc.R;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
......@@ -36,10 +37,12 @@ import android.widget.TextView;
public class AudioSongsListAdapter extends ArrayAdapter<Media> {
private ArrayList<Media> mMediaList;
private int mCurrentIndex;
public AudioSongsListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
mMediaList = new ArrayList<Media>();
mCurrentIndex = -1;
}
@Override
......@@ -54,6 +57,10 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
super.clear();
}
public void setCurrentIndex(int currentIndex) {
mCurrentIndex = currentIndex;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
......@@ -70,6 +77,7 @@ public class AudioSongsListAdapter extends ArrayAdapter<Media> {
Media media = getItem(position);
holder.title.setText(media.getTitle());
holder.title.setTextColor(mCurrentIndex == position ? Color.RED : Color.WHITE);
holder.artist.setText(media.getArtist() + " - " + media.getAlbum());
return v;
}
......
......@@ -33,6 +33,7 @@ interface IAudioService {
void load(in List<String> mediaPathList, int position);
void append(in List<String> mediaPathList);
List<String> getItems();
String getItem();
boolean isPlaying();
boolean isShuffling();
int getRepeatType();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment