Commit a6149222 authored by Edward Wang's avatar Edward Wang Committed by Jean-Baptiste Kempf

Enable sort menu functions for audio list

Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 9ca92b77
......@@ -35,8 +35,16 @@ public class AudioBrowserActivity extends Activity {
private AudioPlaylistAdapter mAlbumsAdapter;
private AudioPlaylistAdapter mGenresAdapter;
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;
private static AudioBrowserActivity mInstance;
@Override
protected void onCreate(Bundle savedInstanceState) {
mInstance = this;
super.onCreate(savedInstanceState);
setContentView(R.layout.audio_browser);
......@@ -69,6 +77,10 @@ public class AudioBrowserActivity extends Activity {
updateLists();
}
public static AudioBrowserActivity getInstance() {
return mInstance;
}
OnItemClickListener songListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> av, View v, int p, long id) {
......@@ -145,6 +157,15 @@ public class AudioBrowserActivity extends Activity {
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 Comparator<Media> byAlbum = new Comparator<Media>() {
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getAlbum(), m2.getAlbum());
......@@ -153,6 +174,7 @@ public class AudioBrowserActivity extends Activity {
return res;
};
};
private Comparator<Media> byArtist = new Comparator<Media>() {
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getArtist(), m2.getArtist());
......@@ -161,6 +183,7 @@ public class AudioBrowserActivity extends Activity {
return res;
};
};
private Comparator<Media> byGenre = new Comparator<Media>() {
public int compare(Media m1, Media m2) {
int res = String.CASE_INSENSITIVE_ORDER.compare(m1.getGenre(), m2.getGenre());
......@@ -177,7 +200,18 @@ public class AudioBrowserActivity extends Activity {
mAlbumsAdapter.clear();
mGenresAdapter.clear();
Collections.sort(audioList, byPath);
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));
......@@ -204,4 +238,14 @@ public class AudioBrowserActivity extends Activity {
mAlbumsAdapter.notifyDataSetChanged();
mGenresAdapter.notifyDataSetChanged();
}
public void sortBy(int sortby) {
if(mSortBy == sortby) {
mSortReverse = !mSortReverse;
} else {
mSortBy = sortby;
mSortReverse = false;
}
updateLists();
}
}
......@@ -37,7 +37,8 @@ public class MainActivity extends TabActivity {
public static final String START_FROM_NOTIFICATION = "from_notification";
private static final String PREF_SHOW_INFO = "show_info";
private VideoListActivity mVideoListActivity;
private VideoListActivity mVideoListActivity = null;
private AudioBrowserActivity mAudioBrowserActivity = null;
private static MainActivity mInstance;
private ProgressBar mProgressBar;
......@@ -74,8 +75,9 @@ public class MainActivity extends TabActivity {
mTabHost.addTab(mTabHost.newTabSpec("AUDIO TAB").setIndicator("AUDIO TAB")
.setContent(new Intent(this, AudioActivityGroup.class)));
// Get video list instance to sort the list.
// Get video & audio list instances to sort the list.
mVideoListActivity = VideoListActivity.getInstance();
mAudioBrowserActivity = AudioBrowserActivity.getInstance();
// add mini audio player
mAudioPlayer = (AudioMiniPlayer) findViewById(R.id.audio_mini_player);
......@@ -143,6 +145,9 @@ public class MainActivity extends TabActivity {
if (mCurrentState == VIDEO_TAB) {
mVideoListActivity.sortBy(
VideoListAdapter.SORT_BY_TITLE);
} else if(mCurrentState == AUDIO_TAB) {
mAudioBrowserActivity.sortBy(
AudioBrowserActivity.SORT_BY_TITLE);
}
break;
// Sort by length
......@@ -150,6 +155,9 @@ public class MainActivity extends TabActivity {
if (mCurrentState == VIDEO_TAB) {
mVideoListActivity.sortBy(
VideoListAdapter.SORT_BY_LENGTH);
} else if(mCurrentState == AUDIO_TAB) {
mAudioBrowserActivity.sortBy(
AudioBrowserActivity.SORT_BY_LENGTH);
}
break;
// About
......@@ -237,6 +245,8 @@ public class MainActivity extends TabActivity {
mChangeTab.setImageResource(R.drawable.header_icon_video);
mTabHost.setCurrentTab(AUDIO_TAB);
mCurrentState = AUDIO_TAB;
if(mAudioBrowserActivity == null)
mAudioBrowserActivity = AudioBrowserActivity.getInstance();
}
/**
......
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