Commit 0910ea6e authored by Sébastien Toque's avatar Sébastien Toque

audio browser: show songs of an artist/album/genre in a dedicated activity

parent dbd5dd0d
......@@ -61,6 +61,9 @@
<activity
android:name=".AudioBrowserActivity"
android:theme="@android:style/Theme.NoTitleBar"/>
<activity
android:name="AudioListActivity"
android:theme="@android:style/Theme.NoTitleBar"/>
<activity
android:name=".AudioActivityGroup"
android:theme="@android:style/Theme.NoTitleBar"/>
......
......@@ -71,7 +71,8 @@
<ListView
android:id="@+id/albums_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
android:layout_height="fill_parent"
android:fastScrollEnabled="true" />
<ListView
android:id="@+id/genres_list"
android:layout_width="fill_parent"
......
......@@ -5,31 +5,16 @@
android:gravity="center_vertical"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal"
android:layout_marginTop="5dip">
<TextView
android:id="@+id/title"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:text="@string/title"
android:textColor="#ffffff"
android:textSize="20dip" />
<ImageView
android:id="@+id/ml_item_more"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:src="@drawable/ic_next"
android:paddingRight="12dip"
android:paddingLeft="5dip" />
</LinearLayout>
android:layout_marginLeft="5dip"
android:layout_marginRight="5dip"
android:layout_marginTop="5dip"
android:text="@string/title"
android:textColor="#ffffff"
android:textSize="20dip" />
<TextView
android:id="@+id/text"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg_with_shadow"
android:gravity="center_horizontal"
android:text="@string/songs"
android:textColor="#ffffff"
android:textSize="16dip" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#f0f0f0" />
<ListView
android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fastScrollEnabled="true" />
<TextView
android:id="@id/android:empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nomedia"
android:textSize="20dip" />
</LinearLayout>
\ No newline at end of file
......@@ -78,9 +78,9 @@ public class AudioBrowserActivity extends Activity {
mMediaLibrary.addUpdateHandler(mHandler);
mSongsAdapter = new AudioSongsListAdapter(this, R.layout.audio_browser_item);
mArtistsAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_playlist);
mAlbumsAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_playlist);
mGenresAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_playlist);
mArtistsAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_item);
mAlbumsAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_item);
mGenresAdapter = new AudioPlaylistAdapter(this, R.layout.audio_browser_item);
ListView songsList = (ListView) findViewById(R.id.songs_list);
ListView artistList = (ListView) findViewById(R.id.artists_list);
ListView albumList = (ListView) findViewById(R.id.albums_list);
......@@ -114,12 +114,13 @@ public class AudioBrowserActivity extends Activity {
@Override
public void onItemClick(AdapterView<?> av, View v, int p, long id) {
AudioPlaylistAdapter adapter = (AudioPlaylistAdapter) av.getAdapter();
List<String> playlist = adapter.getPlaylist(p);
if (playlist.isEmpty())
return;
mAudioController.load(playlist, 0);
Intent intent = new Intent(AudioBrowserActivity.this, AudioPlayerActivity.class);
startActivity(intent);
String name = adapter.getItem(p);
Intent intent = new Intent(AudioBrowserActivity.this, AudioListActivity.class);
AudioListActivity.set(intent, name, mFlingViewGroup.getPosition());
AudioActivityGroup group = (AudioActivityGroup) AudioBrowserActivity.this.getParent();
group.startChildAcitvity("AudioListActivity", intent);
}
};
......
package org.videolan.vlc.android;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
public class AudioListActivity extends ListActivity {
public final static String TAG = "VLC/AudioBrowserActivity";
private AudioServiceController mAudioController;
private MediaLibrary mMediaLibrary;
private TextView mTitle;
private AudioSongsListAdapter mSongsAdapter;
public final static int SORT_BY_TITLE = 0;
public final static int SORT_BY_LENGTH = 1;
private boolean mSortReverse = false;
private int mSortBy = SORT_BY_TITLE;
public final static String EXTRA_NAME = "name";
public final static String EXTRA_MODE = "mode";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_list);
mAudioController = AudioServiceController.getInstance();
mMediaLibrary = MediaLibrary.getInstance(this);
mMediaLibrary.addUpdateHandler(mHandler);
mTitle = (TextView) findViewById(R.id.title);
mSongsAdapter = new AudioSongsListAdapter(this, R.layout.audio_browser_item);
setListAdapter(mSongsAdapter);
updateList();
}
public static void set(Intent intent, String name, int mode) {
intent.putExtra(EXTRA_NAME, name);
intent.putExtra(EXTRA_MODE, mode);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
mAudioController.load(mSongsAdapter.getPaths(), position);
Intent intent = new Intent(AudioListActivity.this, AudioPlayerActivity.class);
startActivity(intent);
super.onListItemClick(l, v, position, id);
}
@Override
protected void onDestroy() {
mMediaLibrary.removeUpdateHandler(mHandler);
mSongsAdapter.clear();
super.onDestroy();
}
/**
* Handle changes on the list
*/
protected Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MediaLibrary.MEDIA_ITEMS_UPDATED:
updateList();
break;
}
}
};
private Comparator<Media> byPath = new Comparator<Media>() {
public int compare(Media m1, Media m2) {
return String.CASE_INSENSITIVE_ORDER.compare(m1.getFile().getPath(), m2.getFile().getPath());
};
};
private Comparator<Media> byLength = new Comparator<Media>() {
public int compare(Media m1, Media m2) {
if (m1.getLength() > m2.getLength())
return -1;
if (m1.getLength() < m2.getLength())
return 1;
else
return 0;
};
};
private void updateList() {
String name = getIntent().getStringExtra(EXTRA_NAME);
int mode = getIntent().getIntExtra(EXTRA_MODE, 0);
if (name == null || mode == 0)
return;
mTitle.setText(name);
List<Media> audioList = MediaLibrary.getInstance(this).getAudioItems(name, mode);
mSongsAdapter.clear();
switch (mSortBy) {
case SORT_BY_LENGTH:
Collections.sort(audioList, byLength);
break;
case SORT_BY_TITLE:
default:
Collections.sort(audioList, byPath);
break;
}
if (mSortReverse) {
Collections.reverse(audioList);
}
for (int i = 0; i < audioList.size(); i++) {
mSongsAdapter.add(audioList.get(i));
}
mSongsAdapter.notifyDataSetChanged();
}
}
......@@ -27,22 +27,18 @@ import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class AudioPlaylistAdapter extends ArrayAdapter<String> {
private ArrayList<String> mTitles;
private ArrayList<Boolean> mExpanded;
private HashMap<String, ArrayList<Media>> mPlaylists;
public AudioPlaylistAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
mTitles = new ArrayList<String>();
mExpanded = new ArrayList<Boolean>();
mPlaylists = new HashMap<String, ArrayList<Media>>();
}
......@@ -52,7 +48,6 @@ public class AudioPlaylistAdapter extends ArrayAdapter<String> {
list = new ArrayList<Media>();
mPlaylists.put(title, list);
mTitles.add(title);
mExpanded.add(false);
super.add(title);
} else {
list = mPlaylists.get(title);
......@@ -66,7 +61,6 @@ public class AudioPlaylistAdapter extends ArrayAdapter<String> {
mPlaylists.get(item).clear();
mPlaylists.remove(item);
}
mExpanded.clear();
mTitles.clear();
super.clear();
}
......@@ -81,7 +75,6 @@ public class AudioPlaylistAdapter extends ArrayAdapter<String> {
holder = new ViewHolder();
holder.title = (TextView) v.findViewById(R.id.title);
holder.text = (TextView) v.findViewById(R.id.text);
holder.more = (ImageView) v.findViewById(R.id.ml_item_more);
v.setTag(holder);
} else
holder = (ViewHolder) v.getTag();
......@@ -89,41 +82,15 @@ public class AudioPlaylistAdapter extends ArrayAdapter<String> {
String name = mTitles.get(position);
ArrayList<Media> list = mPlaylists.get(name);
holder.title.setText(name);
if (mExpanded.get(position)) {
StringBuilder sb = new StringBuilder();
for (Media media : list) {
sb.append(" - ");
sb.append(media.getTitle());
sb.append("\n");
}
holder.text.setText(sb.toString());
}
else {
holder.text.setText(R.string.songs);
holder.text.setText(list.size() + " " + holder.text.getText());
}
holder.text.setText(R.string.songs);
holder.text.setText(list.size() + " " + holder.text.getText());
holder.more.setTag(position);
holder.more.setOnClickListener(moreClickListener);
return v;
}
private OnClickListener moreClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
int position = (Integer) v.getTag();
boolean expanded = mExpanded.get(position);
for (int i = 0; i < mExpanded.size(); ++i)
mExpanded.set(i, false);
mExpanded.set(position, !expanded);
notifyDataSetChanged();
}
};
static class ViewHolder {
TextView title;
TextView text;
ImageView more;
}
public List<String> getPlaylist(int position) {
......
......@@ -38,6 +38,9 @@ public class MediaLibrary {
public final static String TAG = "VLC/MediaLibrary";
protected static final int MEDIA_ITEMS_UPDATED = 100;
public final static int MODE_ARTIST = 1;
public final static int MODE_ALBUM = 2;
public final static int MODE_GENRE = 3;
private static MediaLibrary mInstance;
private DatabaseManager mDBManager;
......@@ -87,14 +90,42 @@ public class MediaLibrary {
}
public ArrayList<Media> getAudioItems() {
ArrayList<Media> videoItems = new ArrayList<Media>();
ArrayList<Media> audioItems = new ArrayList<Media>();
for (int i = 0; i < mItemList.size(); i++) {
Media item = mItemList.get(i);
if (item.getType() == Media.TYPE_AUDIO) {
videoItems.add(item);
audioItems.add(item);
}
}
return videoItems;
return audioItems;
}
public ArrayList<Media> getAudioItems(String name, int mode) {
ArrayList<Media> audioItems = new ArrayList<Media>();
for (int i = 0; i < mItemList.size(); i++) {
Media item = mItemList.get(i);
if (item.getType() == Media.TYPE_AUDIO) {
boolean valid = false;
switch (mode) {
case MODE_ARTIST:
valid = name.equals(item.getArtist());
break;
case MODE_ALBUM:
valid = name.equals(item.getAlbum());
break;
case MODE_GENRE:
valid = name.equals(item.getGenre());
break;
default:
break;
}
if (valid)
audioItems.add(item);
}
}
return audioItems;
}
public ArrayList<Media> getMediaItems() {
......
......@@ -103,6 +103,10 @@ public class FlingViewGroup extends ViewGroup {
}
}
public int getPosition() {
return mCurrentView;
}
public void setPosition(int position) {
mCurrentView = position;
}
......
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