implement save-as-playlist in showqueue activity

This commit is contained in:
Adrian Ulrich 2014-10-23 20:10:38 +02:00
parent c3bcc48d3c
commit 046870bf3b

View File

@ -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 * 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 * it under the terms of the GNU General Public License as published by
@ -18,8 +18,9 @@
package ch.blinkenlights.android.vanilla; package ch.blinkenlights.android.vanilla;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.Menu; import android.view.Menu;
@ -30,7 +31,9 @@ import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ListView; import android.widget.ListView;
import com.mobeta.android.dslv.DragSortListView; import com.mobeta.android.dslv.DragSortListView;
public class ShowQueueActivity extends PlaybackActivity { public class ShowQueueActivity extends PlaybackActivity
implements DialogInterface.OnDismissListener
{
private DragSortListView mListView; private DragSortListView mListView;
private ShowQueueAdapter listAdapter; private ShowQueueAdapter listAdapter;
private PlaybackService mService; private PlaybackService mService;
@ -71,7 +74,7 @@ public class ShowQueueActivity extends PlaybackActivity {
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { 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_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; return true;
} }
@ -82,12 +85,19 @@ public class ShowQueueActivity extends PlaybackActivity {
*/ */
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) { switch (item.getItemId()) {
finish(); case android.R.id.home:
return true; finish();
} else { break;
return super.onOptionsItemSelected(item); 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 * Called when the song timeline has changed
*/ */