More actions in playlist activity; default action pref
This commit is contained in:
parent
0f54cb6242
commit
9b5f60343b
@ -61,6 +61,7 @@ THE SOFTWARE.
|
||||
<string name="sort_by">Sort By</string>
|
||||
<string name="search">Search</string>
|
||||
<string name="done">Done</string>
|
||||
<string name="remove">Remove</string>
|
||||
|
||||
<plurals name="playing">
|
||||
<item quantity="one">1 song playing.</item>
|
||||
@ -155,6 +156,7 @@ THE SOFTWARE.
|
||||
<string name="controls_in_selector_title">Controls in Library</string>
|
||||
<string name="controls_in_selector_summary">Show the currently playing song and media controls in the library view</string>
|
||||
<string name="default_action_title">Default Action</string>
|
||||
<string name="default_playlist_action_title">Default Playlist Action</string>
|
||||
|
||||
<string name="pref_misc">Miscellaneous Features</string>
|
||||
<string name="disable_lockscreen_title">Disable Lockscreen</string>
|
||||
|
@ -121,6 +121,12 @@ THE SOFTWARE.
|
||||
android:entries="@array/default_action_entries"
|
||||
android:entryValues="@array/entry_values"
|
||||
android:defaultValue="0" />
|
||||
<org.kreed.vanilla.ListPreferenceSummary
|
||||
android:key="default_playlist_action"
|
||||
android:title="@string/default_playlist_action_title"
|
||||
android:entries="@array/default_action_entries"
|
||||
android:entryValues="@array/entry_values"
|
||||
android:defaultValue="3" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_misc">
|
||||
<CheckBoxPreference
|
||||
|
@ -30,8 +30,8 @@ import android.content.SharedPreferences;
|
||||
import android.content.res.Resources;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.PaintDrawable;
|
||||
import android.net.Uri;
|
||||
@ -76,11 +76,11 @@ public class LibraryActivity
|
||||
, DialogInterface.OnClickListener
|
||||
, DialogInterface.OnDismissListener
|
||||
{
|
||||
private static final int ACTION_PLAY = 0;
|
||||
private static final int ACTION_ENQUEUE = 1;
|
||||
private static final int ACTION_LAST_USED = 2;
|
||||
private static final int ACTION_PLAY_ALL = 3;
|
||||
private static final int ACTION_ENQUEUE_ALL = 4;
|
||||
public static final int ACTION_PLAY = 0;
|
||||
public static final int ACTION_ENQUEUE = 1;
|
||||
public static final int ACTION_LAST_USED = 2;
|
||||
public static final int ACTION_PLAY_ALL = 3;
|
||||
public static final int ACTION_ENQUEUE_ALL = 4;
|
||||
private static final int[] modeForAction =
|
||||
{ SongTimeline.MODE_PLAY, SongTimeline.MODE_ENQUEUE, -1,
|
||||
SongTimeline.MODE_PLAY_ID_FIRST, SongTimeline.MODE_ENQUEUE_ID_FIRST };
|
||||
|
@ -32,8 +32,8 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.res.TypedArray;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.TypedArray;
|
||||
import android.database.ContentObserver;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
@ -1187,6 +1187,7 @@ public final class PlaybackService extends Service
|
||||
case SongTimeline.MODE_PLAY_NEXT:
|
||||
case SongTimeline.MODE_ENQUEUE:
|
||||
case SongTimeline.MODE_ENQUEUE_ID_FIRST:
|
||||
case SongTimeline.MODE_ENQUEUE_POS_FIRST:
|
||||
text = R.plurals.enqueued;
|
||||
break;
|
||||
default:
|
||||
|
@ -26,11 +26,14 @@ import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.AdapterView;
|
||||
@ -44,14 +47,44 @@ public class PlaylistActivity extends Activity
|
||||
, AbsListView.OnItemClickListener
|
||||
, DialogInterface.OnClickListener
|
||||
{
|
||||
/**
|
||||
* The SongTimeline play mode corresponding to each
|
||||
* LibraryActivity.ACTION_*
|
||||
*/
|
||||
private static final int[] MODE_FOR_ACTION =
|
||||
{ SongTimeline.MODE_PLAY, SongTimeline.MODE_ENQUEUE, -1,
|
||||
SongTimeline.MODE_PLAY_POS_FIRST, SongTimeline.MODE_ENQUEUE_POS_FIRST };
|
||||
|
||||
/**
|
||||
* An event loop running on a worker thread.
|
||||
*/
|
||||
private Looper mLooper;
|
||||
private DragListView mListView;
|
||||
private PlaylistAdapter mAdapter;
|
||||
|
||||
/**
|
||||
* The id of the playlist this activity is currently viewing.
|
||||
*/
|
||||
private long mPlaylistId;
|
||||
/**
|
||||
* The name of the playlist this activity is currently viewing.
|
||||
*/
|
||||
private String mPlaylistName;
|
||||
/**
|
||||
* If true, then playlists songs can be dragged to reorder.
|
||||
*/
|
||||
private boolean mEditing;
|
||||
|
||||
/**
|
||||
* The item click action specified in the preferences.
|
||||
*/
|
||||
private int mDefaultAction;
|
||||
/**
|
||||
* The last action used from the context menu, used to implement
|
||||
* LAST_USED_ACTION action.
|
||||
*/
|
||||
private int mLastAction = LibraryActivity.ACTION_PLAY;
|
||||
|
||||
private Button mEditButton;
|
||||
private Button mDeleteButton;
|
||||
|
||||
@ -72,6 +105,7 @@ public class PlaylistActivity extends Activity
|
||||
view.setDivider(null);
|
||||
view.setFastScrollEnabled(true);
|
||||
view.setOnItemClickListener(this);
|
||||
view.setOnCreateContextMenuListener(this);
|
||||
mListView = view;
|
||||
|
||||
View header = LayoutInflater.from(this).inflate(R.layout.playlist_buttons, null);
|
||||
@ -88,6 +122,14 @@ public class PlaylistActivity extends Activity
|
||||
onNewIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart()
|
||||
{
|
||||
super.onStart();
|
||||
SharedPreferences settings = PlaybackService.getSettings(this);
|
||||
mDefaultAction = Integer.parseInt(settings.getString("default_playlist_action", "0"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
@ -141,6 +183,74 @@ public class PlaylistActivity extends Activity
|
||||
}
|
||||
}
|
||||
|
||||
private static final int MENU_PLAY = LibraryActivity.ACTION_PLAY;
|
||||
private static final int MENU_PLAY_ALL = LibraryActivity.ACTION_PLAY_ALL;
|
||||
private static final int MENU_ENQUEUE = LibraryActivity.ACTION_ENQUEUE;
|
||||
private static final int MENU_ENQUEUE_ALL = LibraryActivity.ACTION_ENQUEUE_ALL;
|
||||
private static final int MENU_REMOVE = -1;
|
||||
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View listView, ContextMenu.ContextMenuInfo absInfo)
|
||||
{
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)absInfo;
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra("id", info.id);
|
||||
intent.putExtra("position", info.position);
|
||||
intent.putExtra("audioId", (Long)((MediaView)info.targetView).getTag());
|
||||
|
||||
menu.add(0, MENU_PLAY, 0, R.string.play).setIntent(intent);
|
||||
menu.add(0, MENU_PLAY_ALL, 0, R.string.play_all).setIntent(intent);
|
||||
menu.add(0, MENU_ENQUEUE, 0, R.string.enqueue).setIntent(intent);
|
||||
menu.add(0, MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(intent);
|
||||
menu.add(0, MENU_REMOVE, 0, R.string.remove).setIntent(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item)
|
||||
{
|
||||
int itemId = item.getItemId();
|
||||
Intent intent = item.getIntent();
|
||||
|
||||
if (itemId == MENU_REMOVE) {
|
||||
mAdapter.remove(intent.getLongExtra("id", -1));
|
||||
} else {
|
||||
performAction(itemId, intent.getIntExtra("position", -1), intent.getLongExtra("audioId", -1));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform the specified action on the adapter row with the given id and
|
||||
* position.
|
||||
*
|
||||
* @param action One of LibraryActivity.ACTION_*.
|
||||
* @param position The position in the adapter.
|
||||
* @param audioId The id of the selected song, for PLAY/ENQUEUE.
|
||||
*/
|
||||
private void performAction(int action, int position, long audioId)
|
||||
{
|
||||
if (action == LibraryActivity.ACTION_LAST_USED)
|
||||
action = mLastAction;
|
||||
|
||||
switch (action) {
|
||||
case LibraryActivity.ACTION_PLAY:
|
||||
case LibraryActivity.ACTION_ENQUEUE: {
|
||||
QueryTask query = MediaUtils.buildMediaQuery(MediaUtils.TYPE_SONG, audioId, Song.FILLED_PROJECTION, null);
|
||||
PlaybackService.get(this).addSongs(MODE_FOR_ACTION[action], query, 0);
|
||||
break;
|
||||
}
|
||||
case LibraryActivity.ACTION_PLAY_ALL:
|
||||
case LibraryActivity.ACTION_ENQUEUE_ALL: {
|
||||
QueryTask query = MediaUtils.buildPlaylistQuery(mPlaylistId, Song.FILLED_PLAYLIST_PROJECTION, null);
|
||||
PlaybackService.get(this).addSongs(MODE_FOR_ACTION[action], query, position - mListView.getHeaderViewsCount());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
mLastAction = action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
|
||||
{
|
||||
@ -149,8 +259,7 @@ public class PlaylistActivity extends Activity
|
||||
if (mediaView.isRightBitmapPressed()) {
|
||||
mAdapter.remove(id);
|
||||
} else if (!mEditing) {
|
||||
QueryTask query = MediaUtils.buildPlaylistQuery(mPlaylistId, Song.FILLED_PLAYLIST_PROJECTION, null);
|
||||
PlaybackService.get(this).addSongs(SongTimeline.MODE_PLAY_POS_FIRST, query, position - mListView.getHeaderViewsCount());
|
||||
performAction(mDefaultAction, position, (Long)mediaView.getTag());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ public class PlaylistAdapter extends CursorAdapter implements Handler.Callback {
|
||||
{
|
||||
MediaView mediaView = (MediaView)view;
|
||||
mediaView.updateMedia(cursor, true);
|
||||
mediaView.setTag(cursor.getLong(3));
|
||||
mediaView.setShowBitmaps(mEditable);
|
||||
}
|
||||
|
||||
|
@ -140,6 +140,16 @@ public final class SongTimeline {
|
||||
* @see SongTimeline#addSongs(int, android.database.Cursor, int, long)
|
||||
*/
|
||||
public static final int MODE_ENQUEUE_ID_FIRST = 5;
|
||||
/**
|
||||
* Like enqueue mode, but make the song at the given position play first by
|
||||
* removing the songs before the given position in the query and appending
|
||||
* them to the end of the queue.
|
||||
*
|
||||
* Pass the position in the integer argument.
|
||||
*
|
||||
* @see SongTimeline#addSongs(int, android.database.Cursor, int, long)
|
||||
*/
|
||||
public static final int MODE_ENQUEUE_POS_FIRST = 6;
|
||||
|
||||
/**
|
||||
* Disable shuffle.
|
||||
@ -558,6 +568,7 @@ public final class SongTimeline {
|
||||
|
||||
switch (mode) {
|
||||
case MODE_ENQUEUE:
|
||||
case MODE_ENQUEUE_POS_FIRST:
|
||||
case MODE_ENQUEUE_ID_FIRST: {
|
||||
int j = timeline.size();
|
||||
while (--j > mCurrentPos) {
|
||||
@ -589,7 +600,7 @@ public final class SongTimeline {
|
||||
timeline.add(song);
|
||||
|
||||
if (jumpSong == null) {
|
||||
if (mode == MODE_PLAY_POS_FIRST && j == i) {
|
||||
if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == i) {
|
||||
jumpSong = song;
|
||||
} else if (mode == MODE_PLAY_ID_FIRST || mode == MODE_ENQUEUE_ID_FIRST) {
|
||||
long id;
|
||||
|
Loading…
x
Reference in New Issue
Block a user