Cleanup playlist dialog code
This commit is contained in:
parent
bb3731f7ea
commit
b88a6f004b
@ -1,61 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
Copyright (C) 2012 Christopher Eby <kreed@kreed.org>
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
-->
|
|
||||||
<LinearLayout
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:divider="?android:attr/dividerHorizontal"
|
|
||||||
android:showDividers="middle"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/playlist_name"
|
|
||||||
android:inputType="text"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:layout_marginBottom="8dip"
|
|
||||||
android:layout_marginLeft="8dip"
|
|
||||||
android:layout_marginRight="8dip" />
|
|
||||||
<LinearLayout
|
|
||||||
style="?android:attr/buttonBarStyle"
|
|
||||||
android:layout_width="fill_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
<Button
|
|
||||||
style="?android:attr/buttonBarButtonStyle"
|
|
||||||
android:id="@+id/cancel"
|
|
||||||
android:layout_width="0px"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@android:string/cancel"
|
|
||||||
android:singleLine="true" />
|
|
||||||
<Button
|
|
||||||
style="?android:attr/buttonBarButtonStyle"
|
|
||||||
android:id="@+id/create"
|
|
||||||
android:layout_width="0px"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:text="@string/create"
|
|
||||||
android:singleLine="true" />
|
|
||||||
</LinearLayout>
|
|
||||||
</LinearLayout>
|
|
@ -675,10 +675,16 @@ public class LibraryActivity
|
|||||||
pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
|
pickSongs(intent, ACTION_ENQUEUE_AS_NEXT);
|
||||||
break;
|
break;
|
||||||
case CTX_MENU_RENAME_PLAYLIST: {
|
case CTX_MENU_RENAME_PLAYLIST: {
|
||||||
PlaylistTask playlistTask = new PlaylistTask(intent.getLongExtra("id", -1), intent.getStringExtra("title"));
|
final String playlistName = intent.getStringExtra("title");
|
||||||
NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename, playlistTask);
|
final long playlistId = intent.getLongExtra("id", -1);
|
||||||
dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog));
|
PlaylistInputDialog dialog = new PlaylistInputDialog(new PlaylistInputDialog.Callback() {
|
||||||
dialog.show();
|
@Override
|
||||||
|
public void onSuccess(String input) {
|
||||||
|
PlaylistTask playlistTask = new PlaylistTask(playlistId, input);
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, playlistTask));
|
||||||
|
}
|
||||||
|
}, playlistName, R.string.rename);
|
||||||
|
dialog.show(getFragmentManager(), "RenamePlaylistInputDialog");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case CTX_MENU_DELETE:
|
case CTX_MENU_DELETE:
|
||||||
|
@ -1,173 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org>
|
|
||||||
* Copyright (C) 2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package ch.blinkenlights.android.vanilla;
|
|
||||||
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.Button;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Simple dialog to prompt to user to enter a playlist name. Has an EditText to
|
|
||||||
* enter the name and two buttons, create and cancel. Create changes to
|
|
||||||
* overwrite if a name that already exists is selected.
|
|
||||||
*/
|
|
||||||
public class NewPlaylistDialog extends Dialog implements TextWatcher, View.OnClickListener {
|
|
||||||
/**
|
|
||||||
* The create/overwrite button.
|
|
||||||
*/
|
|
||||||
private Button mPositiveButton;
|
|
||||||
/**
|
|
||||||
* The text entry view.
|
|
||||||
*/
|
|
||||||
private EditText mText;
|
|
||||||
/**
|
|
||||||
* Whether the dialog has been accepted. The dialog is accepted if create
|
|
||||||
* was clicked.
|
|
||||||
*/
|
|
||||||
private boolean mAccepted;
|
|
||||||
/**
|
|
||||||
* The text to display initially. When the EditText contains this text, the
|
|
||||||
* positive button will be disabled.
|
|
||||||
*/
|
|
||||||
private final String mInitialText;
|
|
||||||
/**
|
|
||||||
* The resource containing the string describing the default positive
|
|
||||||
* action (e.g. "Create" or "Rename").
|
|
||||||
*/
|
|
||||||
private final int mActionRes;
|
|
||||||
/**
|
|
||||||
* A playlist task that is simply stored in the dialog.
|
|
||||||
*/
|
|
||||||
private final PlaylistTask mPlaylistTask;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a NewPlaylistDialog.
|
|
||||||
*
|
|
||||||
* @param context A Context to use.
|
|
||||||
* @param initialText The text to show initially. The positive button is
|
|
||||||
* disabled when the EditText contains this text.
|
|
||||||
* @param actionText A string resource describing the default positive
|
|
||||||
* action (e.g. "Create").
|
|
||||||
*/
|
|
||||||
public NewPlaylistDialog(Context context, String initialText, int actionText, PlaylistTask playlistTask)
|
|
||||||
{
|
|
||||||
super(context);
|
|
||||||
mInitialText = initialText;
|
|
||||||
mActionRes = actionText;
|
|
||||||
mPlaylistTask = playlistTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle state)
|
|
||||||
{
|
|
||||||
super.onCreate(state);
|
|
||||||
|
|
||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
|
|
||||||
|
|
||||||
setContentView(R.layout.new_playlist_dialog);
|
|
||||||
|
|
||||||
setTitle(R.string.choose_playlist_name);
|
|
||||||
|
|
||||||
mPositiveButton = (Button)findViewById(R.id.create);
|
|
||||||
mPositiveButton.setOnClickListener(this);
|
|
||||||
mPositiveButton.setText(mActionRes);
|
|
||||||
View negativeButton = findViewById(R.id.cancel);
|
|
||||||
negativeButton.setOnClickListener(this);
|
|
||||||
|
|
||||||
mText = (EditText)findViewById(R.id.playlist_name);
|
|
||||||
mText.addTextChangedListener(this);
|
|
||||||
mText.setText(mInitialText);
|
|
||||||
mText.requestFocus();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the playlist name currently entered in the dialog.
|
|
||||||
*/
|
|
||||||
public String getText()
|
|
||||||
{
|
|
||||||
return mText.getText().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the stored playlist task.
|
|
||||||
*/
|
|
||||||
public PlaylistTask getPlaylistTask()
|
|
||||||
{
|
|
||||||
return mPlaylistTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void afterTextChanged(Editable s)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
|
||||||
{
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTextChanged(CharSequence text, int start, int before, int count)
|
|
||||||
{
|
|
||||||
String string = text.toString();
|
|
||||||
if (string.equals(mInitialText)) {
|
|
||||||
mPositiveButton.setEnabled(false);
|
|
||||||
} else {
|
|
||||||
mPositiveButton.setEnabled(true);
|
|
||||||
// Update the action button based on whether there is an
|
|
||||||
// existing playlist with the given name.
|
|
||||||
ContentResolver resolver = getContext().getContentResolver();
|
|
||||||
int res = Playlist.getPlaylist(resolver, string) == -1 ? mActionRes : R.string.overwrite;
|
|
||||||
mPositiveButton.setText(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether the dialog has been accepted. The dialog is accepted
|
|
||||||
* when the create/overwrite button is clicked.
|
|
||||||
*/
|
|
||||||
public boolean isAccepted()
|
|
||||||
{
|
|
||||||
return mAccepted;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onClick(View view)
|
|
||||||
{
|
|
||||||
switch (view.getId()) {
|
|
||||||
case R.id.create:
|
|
||||||
mAccepted = true;
|
|
||||||
// fall through
|
|
||||||
case R.id.cancel:
|
|
||||||
dismiss();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -371,11 +371,10 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
static final int MENU_SONG_FAVORITE = 12;
|
static final int MENU_SONG_FAVORITE = 12;
|
||||||
static final int MENU_SHOW_QUEUE = 13;
|
static final int MENU_SHOW_QUEUE = 13;
|
||||||
static final int MENU_HIDE_QUEUE = 14;
|
static final int MENU_HIDE_QUEUE = 14;
|
||||||
static final int MENU_SAVE_QUEUE_AS_PLAYLIST = 15;
|
static final int MENU_DELETE = 15;
|
||||||
static final int MENU_DELETE = 16;
|
static final int MENU_EMPTY_QUEUE = 16;
|
||||||
static final int MENU_EMPTY_QUEUE = 17;
|
static final int MENU_ADD_TO_PLAYLIST = 17;
|
||||||
static final int MENU_ADD_TO_PLAYLIST = 18;
|
static final int MENU_SHARE = 18;
|
||||||
static final int MENU_SHARE = 19;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu)
|
public boolean onCreateOptionsMenu(Menu menu)
|
||||||
@ -397,11 +396,6 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
case MENU_EMPTY_QUEUE:
|
case MENU_EMPTY_QUEUE:
|
||||||
PlaybackService.get(this).emptyQueue();
|
PlaybackService.get(this).emptyQueue();
|
||||||
break;
|
break;
|
||||||
case MENU_SAVE_QUEUE_AS_PLAYLIST:
|
|
||||||
NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, null);
|
|
||||||
dialog.setOnDismissListener(new SaveAsPlaylistDismiss());
|
|
||||||
dialog.show();
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -410,10 +404,9 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call addToPlaylist with the results from a NewPlaylistDialog stored in
|
* Same as MSG_ADD_TO_PLAYLIST but creates the new playlist on-the-fly (or overwrites an existing list)
|
||||||
* obj.
|
|
||||||
*/
|
*/
|
||||||
protected static final int MSG_NEW_PLAYLIST = 0;
|
protected static final int MSG_CREATE_PLAYLIST = 0;
|
||||||
/**
|
/**
|
||||||
* Call renamePlaylist with the results from a NewPlaylistDialog stored in
|
* Call renamePlaylist with the results from a NewPlaylistDialog stored in
|
||||||
* obj.
|
* obj.
|
||||||
@ -434,7 +427,7 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
/**
|
/**
|
||||||
* Saves the current queue as a playlist
|
* Saves the current queue as a playlist
|
||||||
*/
|
*/
|
||||||
protected static final int MSG_SAVE_QUEUE_AS_PLAYLIST = 5;
|
protected static final int MSG_ADD_QUEUE_TO_PLAYLIST = 5;
|
||||||
/**
|
/**
|
||||||
* Notification that we changed some playlist members
|
* Notification that we changed some playlist members
|
||||||
*/
|
*/
|
||||||
@ -444,16 +437,12 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
public boolean handleMessage(Message message)
|
public boolean handleMessage(Message message)
|
||||||
{
|
{
|
||||||
switch (message.what) {
|
switch (message.what) {
|
||||||
case MSG_NEW_PLAYLIST: {
|
case MSG_CREATE_PLAYLIST: {
|
||||||
NewPlaylistDialog dialog = (NewPlaylistDialog)message.obj;
|
PlaylistTask playlistTask = (PlaylistTask)message.obj;
|
||||||
if (dialog.isAccepted()) {
|
int nextAction = message.arg1;
|
||||||
String name = dialog.getText();
|
long playlistId = Playlist.createPlaylist(getContentResolver(), playlistTask.name);
|
||||||
long playlistId = Playlist.createPlaylist(getContentResolver(), name);
|
playlistTask.playlistId = playlistId;
|
||||||
PlaylistTask playlistTask = dialog.getPlaylistTask();
|
mHandler.sendMessage(mHandler.obtainMessage(nextAction, playlistTask));
|
||||||
playlistTask.name = name;
|
|
||||||
playlistTask.playlistId = playlistId;
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_ADD_TO_PLAYLIST: {
|
case MSG_ADD_TO_PLAYLIST: {
|
||||||
@ -461,12 +450,9 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
addToPlaylist(playlistTask);
|
addToPlaylist(playlistTask);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_SAVE_QUEUE_AS_PLAYLIST: {
|
case MSG_ADD_QUEUE_TO_PLAYLIST: {
|
||||||
String playlistName = (String)message.obj;
|
PlaylistTask playlistTask = (PlaylistTask)message.obj;
|
||||||
long playlistId = Playlist.createPlaylist(getContentResolver(), playlistName);
|
|
||||||
PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName);
|
|
||||||
playlistTask.audioIds = new ArrayList<Long>();
|
playlistTask.audioIds = new ArrayList<Long>();
|
||||||
|
|
||||||
Song song;
|
Song song;
|
||||||
PlaybackService service = PlaybackService.get(this);
|
PlaybackService service = PlaybackService.get(this);
|
||||||
for (int i=0; ; i++) {
|
for (int i=0; ; i++) {
|
||||||
@ -475,7 +461,6 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
break;
|
break;
|
||||||
playlistTask.audioIds.add(song.id);
|
playlistTask.audioIds.add(song.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
addToPlaylist(playlistTask);
|
addToPlaylist(playlistTask);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -485,11 +470,8 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_RENAME_PLAYLIST: {
|
case MSG_RENAME_PLAYLIST: {
|
||||||
NewPlaylistDialog dialog = (NewPlaylistDialog)message.obj;
|
PlaylistTask playlistTask = (PlaylistTask)message.obj;
|
||||||
if (dialog.isAccepted()) {
|
Playlist.renamePlaylist(getContentResolver(), playlistTask.playlistId, playlistTask.name);
|
||||||
long playlistId = dialog.getPlaylistTask().playlistId;
|
|
||||||
Playlist.renamePlaylist(getContentResolver(), playlistId, dialog.getText());
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MSG_DELETE: {
|
case MSG_DELETE: {
|
||||||
@ -678,19 +660,4 @@ public abstract class PlaybackActivity extends Activity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fired if user dismisses the create-playlist dialog
|
|
||||||
*
|
|
||||||
* @param dialogInterface the dismissed interface dialog
|
|
||||||
*/
|
|
||||||
class SaveAsPlaylistDismiss implements DialogInterface.OnDismissListener {
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialogInterface) {
|
|
||||||
NewPlaylistDialog dialog = (NewPlaylistDialog)dialogInterface;
|
|
||||||
if (dialog.isAccepted()) {
|
|
||||||
String playlistName = dialog.getText();
|
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_SAVE_QUEUE_AS_PLAYLIST, playlistName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -31,22 +31,18 @@ import android.content.Intent;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
|
||||||
public class PlaylistDialog extends DialogFragment
|
public class PlaylistDialog extends DialogFragment
|
||||||
implements DialogInterface.OnClickListener
|
implements DialogInterface.OnClickListener
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class implementing our callback interface
|
* A class implementing our callback interface
|
||||||
*/
|
*/
|
||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
/**
|
/**
|
||||||
* The intent to act on
|
* The data passed to the callback
|
||||||
*/
|
*/
|
||||||
private Intent mIntent;
|
private PlaylistDialog.Data mData;
|
||||||
/**
|
|
||||||
* The media adapter to pass on which will be used to query all songs
|
|
||||||
*/
|
|
||||||
private MediaAdapter mAllSrc;
|
|
||||||
/**
|
/**
|
||||||
* Array of all found playlist names
|
* Array of all found playlist names
|
||||||
*/
|
*/
|
||||||
@ -56,23 +52,33 @@ public class PlaylistDialog extends DialogFragment
|
|||||||
*/
|
*/
|
||||||
private long[] mItemValue;
|
private long[] mItemValue;
|
||||||
/**
|
/**
|
||||||
* Magic value, indicating that a new
|
* Index of 'create playlist' button
|
||||||
* playlist shall be created
|
|
||||||
*/
|
*/
|
||||||
private final int VALUE_CREATE_PLAYLIST = -1;
|
private final int BUTTON_CREATE_PLAYLIST = 0;
|
||||||
/**
|
/**
|
||||||
* Our callback interface
|
* Our callback interface
|
||||||
*/
|
*/
|
||||||
public interface Callback {
|
public interface Callback {
|
||||||
void appendToPlaylistFromIntent(Intent intent, MediaAdapter allSource);
|
void updatePlaylistFromPlaylistDialog(PlaylistDialog.Data data);
|
||||||
void createNewPlaylistFromIntent(Intent intent, MediaAdapter allSource);
|
}
|
||||||
|
/**
|
||||||
|
* Our data structure
|
||||||
|
*/
|
||||||
|
public class Data {
|
||||||
|
public String name;
|
||||||
|
public long id;
|
||||||
|
public Intent sourceIntent;
|
||||||
|
public MediaAdapter allSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new playlist dialog to assemble a playlist using an intent
|
||||||
|
*/
|
||||||
PlaylistDialog(Callback callback, Intent intent, MediaAdapter allSource) {
|
PlaylistDialog(Callback callback, Intent intent, MediaAdapter allSource) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
mIntent = intent;
|
mData = new PlaylistDialog.Data();
|
||||||
mAllSrc = allSource;
|
mData.sourceIntent = intent;
|
||||||
|
mData.allSource = allSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -87,7 +93,7 @@ public class PlaylistDialog extends DialogFragment
|
|||||||
|
|
||||||
// Index 0 is always 'New Playlist...'
|
// Index 0 is always 'New Playlist...'
|
||||||
mItemName[0] = getResources().getString(R.string.new_playlist);
|
mItemName[0] = getResources().getString(R.string.new_playlist);
|
||||||
mItemValue[0] = VALUE_CREATE_PLAYLIST;
|
mItemValue[0] = -1;
|
||||||
|
|
||||||
for (int i = 0 ; i < count; i++) {
|
for (int i = 0 ; i < count; i++) {
|
||||||
cursor.moveToPosition(i);
|
cursor.moveToPosition(i);
|
||||||
@ -104,13 +110,23 @@ public class PlaylistDialog extends DialogFragment
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
if (mItemValue[which] == VALUE_CREATE_PLAYLIST) {
|
switch (which) {
|
||||||
mCallback.createNewPlaylistFromIntent(mIntent, mAllSrc);
|
case BUTTON_CREATE_PLAYLIST:
|
||||||
} else {
|
PlaylistInputDialog newDialog = new PlaylistInputDialog(new PlaylistInputDialog.Callback() {
|
||||||
Intent copy = new Intent(mIntent);
|
@Override
|
||||||
copy.putExtra("playlist", mItemValue[which]);
|
public void onSuccess(String input) {
|
||||||
copy.putExtra("playlistName", mItemName[which]);
|
mData.id = -1;
|
||||||
mCallback.appendToPlaylistFromIntent(copy, mAllSrc);
|
mData.name = input;
|
||||||
|
mCallback.updatePlaylistFromPlaylistDialog(mData);
|
||||||
|
}
|
||||||
|
}, "", R.string.create);
|
||||||
|
newDialog.show(getFragmentManager(), "PlaylistInputDialog");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
mData.id = mItemValue[which];
|
||||||
|
mData.name = mItemName[which];
|
||||||
|
mCallback.updatePlaylistFromPlaylistDialog(mData);
|
||||||
}
|
}
|
||||||
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
148
src/ch/blinkenlights/android/vanilla/PlaylistInputDialog.java
Normal file
148
src/ch/blinkenlights/android/vanilla/PlaylistInputDialog.java
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package ch.blinkenlights.android.vanilla;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.DialogFragment;
|
||||||
|
import android.content.ContentResolver;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.InputType;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.widget.EditText;
|
||||||
|
|
||||||
|
public class PlaylistInputDialog extends DialogFragment
|
||||||
|
implements DialogInterface.OnClickListener, TextWatcher
|
||||||
|
{
|
||||||
|
|
||||||
|
public interface Callback {
|
||||||
|
void onSuccess(String input);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A editText instance
|
||||||
|
*/
|
||||||
|
private EditText mEditText;
|
||||||
|
/**
|
||||||
|
* Our callback implementing the PlaylistInputDialog.Callback
|
||||||
|
* interface
|
||||||
|
*/
|
||||||
|
private Callback mCallback;
|
||||||
|
/**
|
||||||
|
* The label of the positive button
|
||||||
|
*/
|
||||||
|
private int mActionRes;
|
||||||
|
/**
|
||||||
|
* The initial text to display
|
||||||
|
*/
|
||||||
|
private String mInitialText;
|
||||||
|
/**
|
||||||
|
* The instance of the alert dialog
|
||||||
|
*/
|
||||||
|
private AlertDialog mDialog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
* @param callback the callback to call back
|
||||||
|
* @param initialText the initial value mEditText
|
||||||
|
* @param actionRes the label of the positive button
|
||||||
|
*/
|
||||||
|
PlaylistInputDialog(Callback callback, String initialText, int actionRes) {
|
||||||
|
mCallback = callback;
|
||||||
|
mInitialText = initialText;
|
||||||
|
mActionRes = actionRes;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||||
|
mEditText = new EditText(getActivity());
|
||||||
|
mEditText.setInputType(InputType.TYPE_CLASS_TEXT);
|
||||||
|
mEditText.addTextChangedListener(this);
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||||
|
builder.setTitle(R.string.choose_playlist_name)
|
||||||
|
.setView(mEditText)
|
||||||
|
.setPositiveButton(mActionRes, this)
|
||||||
|
.setNegativeButton(android.R.string.cancel, this);
|
||||||
|
mDialog = builder.create();
|
||||||
|
return mDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the view becomes visible, so we can
|
||||||
|
* set the button positive-button and request focus
|
||||||
|
*/
|
||||||
|
public void onStart() {
|
||||||
|
super.onStart();
|
||||||
|
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
||||||
|
mEditText.setText(mInitialText);
|
||||||
|
mEditText.requestFocus();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called after mEditText changed
|
||||||
|
*/
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called before mEditText changed
|
||||||
|
*/
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
// noop
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when mEditText changed
|
||||||
|
*/
|
||||||
|
public void onTextChanged(CharSequence text, int start, int before, int count) {
|
||||||
|
String string = text.toString();
|
||||||
|
if (string.equals(mInitialText)) {
|
||||||
|
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
|
||||||
|
} else {
|
||||||
|
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
|
||||||
|
ContentResolver resolver = getContext().getContentResolver();
|
||||||
|
int res = Playlist.getPlaylist(resolver, string) == -1 ? mActionRes : R.string.overwrite;
|
||||||
|
mDialog.getButton(DialogInterface.BUTTON_POSITIVE).setText(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
switch (which) {
|
||||||
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
|
// noop
|
||||||
|
break;
|
||||||
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
|
mCallback.onSuccess(mEditText.getText().toString());
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
@ -126,11 +126,13 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
|||||||
menu.add(0, MENU_HIDE_QUEUE, 20, R.string.hide_queue);
|
menu.add(0, MENU_HIDE_QUEUE, 20, R.string.hide_queue);
|
||||||
menu.add(0, MENU_CLEAR_QUEUE, 20, R.string.dequeue_rest);
|
menu.add(0, MENU_CLEAR_QUEUE, 20, R.string.dequeue_rest);
|
||||||
menu.add(0, MENU_EMPTY_QUEUE, 20, R.string.empty_the_queue);
|
menu.add(0, MENU_EMPTY_QUEUE, 20, R.string.empty_the_queue);
|
||||||
menu.add(0, MENU_SAVE_QUEUE_AS_PLAYLIST, 20, R.string.save_as_playlist);
|
menu.add(0, MENU_SAVE_QUEUE, 20, R.string.save_as_playlist);
|
||||||
onSlideFullyExpanded(false);
|
onSlideFullyExpanded(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final int MENU_SAVE_QUEUE = 300;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
@ -140,13 +142,18 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
|||||||
case MENU_HIDE_QUEUE:
|
case MENU_HIDE_QUEUE:
|
||||||
mSlidingView.hideSlide();
|
mSlidingView.hideSlide();
|
||||||
break;
|
break;
|
||||||
|
case MENU_SAVE_QUEUE:
|
||||||
|
PlaylistDialog dialog = new PlaylistDialog(this, null, null);
|
||||||
|
dialog.show(getFragmentManager(), "PlaylistDialog");
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final int CTX_MENU_ADD_TO_PLAYLIST = 300;
|
|
||||||
|
static final int CTX_MENU_ADD_TO_PLAYLIST = 300;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
@ -166,32 +173,28 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called by PlaylistDialog.Callback to prompt for the new
|
|
||||||
* playlist name
|
|
||||||
*
|
|
||||||
* @param intent The intent holding the selected data
|
|
||||||
*/
|
|
||||||
public void createNewPlaylistFromIntent(Intent intent, MediaAdapter allSource) {
|
|
||||||
PlaylistTask playlistTask = new PlaylistTask(-1, null);
|
|
||||||
playlistTask.query = buildQueryFromIntent(intent, true, allSource);
|
|
||||||
NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, playlistTask);
|
|
||||||
dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog));
|
|
||||||
dialog.show();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called by PlaylistDialog.Callback to append data to
|
* Called by PlaylistDialog.Callback to append data to
|
||||||
* a playlist
|
* a playlist
|
||||||
*
|
*
|
||||||
* @param intent The intent holding the selected data
|
* @param intent The intent holding the selected data
|
||||||
*/
|
*/
|
||||||
public void appendToPlaylistFromIntent(Intent intent, MediaAdapter allSource) {
|
public void updatePlaylistFromPlaylistDialog(PlaylistDialog.Data data) {
|
||||||
long playlistId = intent.getLongExtra("playlist", -1);
|
PlaylistTask playlistTask = new PlaylistTask(data.id, data.name);
|
||||||
String playlistName = intent.getStringExtra("playlistName");
|
int action = -1;
|
||||||
PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName);
|
|
||||||
playlistTask.query = buildQueryFromIntent(intent, true, allSource);
|
if (data.sourceIntent == null) {
|
||||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask));
|
action = MSG_ADD_QUEUE_TO_PLAYLIST;
|
||||||
|
} else {
|
||||||
|
// we got a source intent: build the query here
|
||||||
|
playlistTask.query = buildQueryFromIntent(data.sourceIntent, true, data.allSource);
|
||||||
|
action = MSG_ADD_TO_PLAYLIST;
|
||||||
|
}
|
||||||
|
if (playlistTask.playlistId < 0) {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(MSG_CREATE_PLAYLIST, action, 0, playlistTask));
|
||||||
|
} else {
|
||||||
|
mHandler.sendMessage(mHandler.obtainMessage(action, playlistTask));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -327,7 +330,7 @@ public class SlidingPlaybackActivity extends PlaybackActivity
|
|||||||
if (mMenu == null)
|
if (mMenu == null)
|
||||||
return; // not initialized yet
|
return; // not initialized yet
|
||||||
|
|
||||||
final int[] slide_visible = {MENU_HIDE_QUEUE, MENU_CLEAR_QUEUE, MENU_EMPTY_QUEUE, MENU_SAVE_QUEUE_AS_PLAYLIST};
|
final int[] slide_visible = {MENU_HIDE_QUEUE, MENU_CLEAR_QUEUE, MENU_EMPTY_QUEUE, MENU_SAVE_QUEUE};
|
||||||
final int[] slide_hidden = {MENU_SHOW_QUEUE, MENU_SORT, MENU_DELETE, MENU_ENQUEUE_ALBUM, MENU_ENQUEUE_ARTIST, MENU_ENQUEUE_GENRE, MENU_ADD_TO_PLAYLIST, MENU_SHARE};
|
final int[] slide_hidden = {MENU_SHOW_QUEUE, MENU_SORT, MENU_DELETE, MENU_ENQUEUE_ALBUM, MENU_ENQUEUE_ARTIST, MENU_ENQUEUE_GENRE, MENU_ADD_TO_PLAYLIST, MENU_SHARE};
|
||||||
|
|
||||||
for (int id : slide_visible) {
|
for (int id : slide_visible) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user