diff options
author | Scott Jackson <daneren2005@gmail.com> | 2012-07-07 08:29:52 -0700 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2012-07-07 08:29:52 -0700 |
commit | 6ebae86dfbb7fa79d81e6b2485f395eeab7267ef (patch) | |
tree | bc26b39df3c6a666bcac960042f2ac8cb06ad202 /subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java | |
parent | 8a7bb33f73d4fab1e380adf972efc2f3a7ee8b3e (diff) | |
download | dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.tar.gz dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.tar.bz2 dsub-6ebae86dfbb7fa79d81e6b2485f395eeab7267ef.zip |
Changed project package to github.daneren2005.subphonic
Diffstat (limited to 'subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java')
-rw-r--r-- | subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java | 141 |
1 files changed, 141 insertions, 0 deletions
diff --git a/subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java b/subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java new file mode 100644 index 00000000..9882fad0 --- /dev/null +++ b/subsonic-android/src/github/daneren2005/subphonic/activity/SelectPlaylistActivity.java @@ -0,0 +1,141 @@ +/* + This file is part of Subsonic. + + Subsonic is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + Subsonic is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with Subsonic. If not, see <http://www.gnu.org/licenses/>. + + Copyright 2009 (C) Sindre Mehus + */ + +package github.daneren2005.subphonic.activity; + +import android.content.Intent; +import android.os.Bundle; +import android.view.ContextMenu; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ImageButton; +import android.widget.ListView; +import github.daneren2005.subphonic.R; +import github.daneren2005.subphonic.domain.Playlist; +import github.daneren2005.subphonic.service.MusicServiceFactory; +import github.daneren2005.subphonic.service.MusicService; +import github.daneren2005.subphonic.util.BackgroundTask; +import github.daneren2005.subphonic.util.Constants; +import github.daneren2005.subphonic.util.PlaylistAdapter; +import github.daneren2005.subphonic.util.TabActivityBackgroundTask; +import github.daneren2005.subphonic.util.Util; + +import java.util.List; + +public class SelectPlaylistActivity extends SubsonicTabActivity implements AdapterView.OnItemClickListener { + + private static final int MENU_ITEM_PLAY_ALL = 1; + + private ListView list; + private View emptyTextView; + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.select_playlist); + + list = (ListView) findViewById(R.id.select_playlist_list); + emptyTextView = findViewById(R.id.select_playlist_empty); + list.setOnItemClickListener(this); + registerForContextMenu(list); + + // Title: Playlists + setTitle(R.string.playlist_label); + + // Button 1: gone + ImageButton searchButton = (ImageButton)findViewById(R.id.action_button_1); + searchButton.setVisibility(View.GONE); + + // Button 2: refresh + ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_2); + refreshButton.setImageResource(R.drawable.action_refresh); + refreshButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + refresh(); + } + }); + + load(); + } + + private void refresh() { + finish(); + Intent intent = new Intent(this, SelectPlaylistActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_REFRESH, true); + Util.startActivityWithoutTransition(this, intent); + } + + private void load() { + BackgroundTask<List<Playlist>> task = new TabActivityBackgroundTask<List<Playlist>>(this) { + @Override + protected List<Playlist> doInBackground() throws Throwable { + MusicService musicService = MusicServiceFactory.getMusicService(SelectPlaylistActivity.this); + boolean refresh = getIntent().getBooleanExtra(Constants.INTENT_EXTRA_NAME_REFRESH, false); + return musicService.getPlaylists(refresh, SelectPlaylistActivity.this, this); + } + + @Override + protected void done(List<Playlist> result) { + list.setAdapter(new PlaylistAdapter(SelectPlaylistActivity.this, PlaylistAdapter.PlaylistComparator.sort(result))); + emptyTextView.setVisibility(result.isEmpty() ? View.VISIBLE : View.GONE); + } + }; + task.execute(); + } + + @Override + public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { + super.onCreateContextMenu(menu, view, menuInfo); + menu.add(Menu.NONE, MENU_ITEM_PLAY_ALL, MENU_ITEM_PLAY_ALL, R.string.common_play_now); + } + + @Override + public boolean onContextItemSelected(MenuItem menuItem) { + AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuItem.getMenuInfo(); + Playlist playlist = (Playlist) list.getItemAtPosition(info.position); + + switch (menuItem.getItemId()) { + case MENU_ITEM_PLAY_ALL: + Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_AUTOPLAY, true); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + break; + default: + return super.onContextItemSelected(menuItem); + } + return true; + } + + @Override + public void onItemClick(AdapterView<?> parent, View view, int position, long id) { + + Playlist playlist = (Playlist) parent.getItemAtPosition(position); + + Intent intent = new Intent(SelectPlaylistActivity.this, SelectAlbumActivity.class); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_ID, playlist.getId()); + intent.putExtra(Constants.INTENT_EXTRA_NAME_PLAYLIST_NAME, playlist.getName()); + Util.startActivityWithoutTransition(SelectPlaylistActivity.this, intent); + } + +}
\ No newline at end of file |