implement save-as-playlist in showqueue activity
This commit is contained in:
parent
c3bcc48d3c
commit
046870bf3b
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2013 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
* Copyright (C) 2013-2014 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -18,8 +18,9 @@
|
||||
package ch.blinkenlights.android.vanilla;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
@ -30,7 +31,9 @@ import android.widget.AdapterView.OnItemLongClickListener;
|
||||
import android.widget.ListView;
|
||||
import com.mobeta.android.dslv.DragSortListView;
|
||||
|
||||
public class ShowQueueActivity extends PlaybackActivity {
|
||||
public class ShowQueueActivity extends PlaybackActivity
|
||||
implements DialogInterface.OnDismissListener
|
||||
{
|
||||
private DragSortListView mListView;
|
||||
private ShowQueueAdapter listAdapter;
|
||||
private PlaybackService mService;
|
||||
@ -71,7 +74,7 @@ public class ShowQueueActivity extends PlaybackActivity {
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
menu.add(0, MENU_CLEAR_QUEUE, 0, R.string.clear_queue).setIcon(R.drawable.ic_menu_close_clear_cancel);
|
||||
menu.add(0, MENU_SAVEAS_PLAYLIST, 0, R.string.save_as_playlist).setIcon(R.drawable.ic_menu_preferences);
|
||||
menu.add(0, MENU_SAVE_AS_PLAYLIST, 0, R.string.save_as_playlist).setIcon(R.drawable.ic_menu_preferences);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -82,12 +85,19 @@ public class ShowQueueActivity extends PlaybackActivity {
|
||||
*/
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
} else {
|
||||
return super.onOptionsItemSelected(item);
|
||||
switch (item.getItemId()) {
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
case MENU_SAVE_AS_PLAYLIST:
|
||||
NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, null);
|
||||
dialog.setOnDismissListener(this);
|
||||
dialog.show();
|
||||
break;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -127,6 +137,31 @@ public class ShowQueueActivity extends PlaybackActivity {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fired if user dismisses the create-playlist dialog
|
||||
*
|
||||
* @param dialogInterface the dismissed interface dialog
|
||||
*/
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
NewPlaylistDialog dialog = (NewPlaylistDialog)dialogInterface;
|
||||
if (dialog.isAccepted()) {
|
||||
String playlistName = dialog.getText();
|
||||
long playlistId = Playlist.createPlaylist(getContentResolver(), playlistName);
|
||||
PlaylistTask playlistTask = new PlaylistTask(playlistId, playlistName);
|
||||
playlistTask.audioIds = new ArrayList<Long>();
|
||||
|
||||
Song song;
|
||||
for (int i=0; ; i++) {
|
||||
song = mService.getSongByQueuePosition(i);
|
||||
if (song == null)
|
||||
break;
|
||||
playlistTask.audioIds.add(song.id);
|
||||
}
|
||||
mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, playlistTask));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the song timeline has changed
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user