@Override protected void asyncUpdate() { MPDApplication app = (MPDApplication) getActivity().getApplication(); if (this.getActivity().getIntent().getStringExtra("directory") != null) { currentDirectory = app.oMPDAsyncHelper .oMPD .getRootDirectory() .makeDirectory((String) this.getActivity().getIntent().getStringExtra("directory")); setActivityTitle( (String) getActivity().getIntent().getStringExtra("directory"), R.drawable.ic_tab_playlists_selected); } else { currentDirectory = app.oMPDAsyncHelper.oMPD.getRootDirectory(); } try { currentDirectory.refreshData(); } catch (MPDServerException e) { e.printStackTrace(); } Collection<Directory> directories = currentDirectory.getDirectories(); for (Directory child : directories) { items.add(child.getName()); } Collection<Music> musics = currentDirectory.getFiles(); for (Music music : musics) { items.add(music.getTitle()); } }
/* * React to playlist change on server and refresh ourself * @see org.a0z.mpd.event.AbstractStatusChangeListener#playlistChanged(org.a0z.mpd.MPDStatus, int) */ @Override public void playlistChanged(MPDStatus mpdStatus, int oldPlaylistVersion) { try { refresh(oldPlaylistVersion); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override public void asyncUpdate() { try { if (getActivity() == null) return; items = app.oMPDAsyncHelper.oMPD.getSongs(artist, album); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, String playlist) { try { app.oMPDAsyncHelper.oMPD.addToPlaylist(playlist, (Music) item); Tools.notifyUser(String.format(getResources().getString(irAdded), item), getActivity()); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, String playlist) { try { app.oMPDAsyncHelper.oMPD.addToPlaylist( playlist, app.oMPDAsyncHelper.oMPD.find("genre", item.getName())); Tools.notifyUser(irAdded, item); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, boolean replace, boolean play) { try { app.oMPDAsyncHelper .oMPD .getPlaylist() .addAll(app.oMPDAsyncHelper.oMPD.find("genre", item.getName())); Tools.notifyUser(irAdded, item); } catch (MPDServerException e) { e.printStackTrace(); } }
@Override protected void add(Item item, boolean replace, boolean play) { Music music = (Music) item; try { app.oMPDAsyncHelper.oMPD.add(music, replace, play); Tools.notifyUser( String.format( getResources().getString(R.string.songAdded, music.getTitle()), music.getName()), getActivity()); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Override public boolean onContextItemSelected(MenuItem item) { MPDApplication app = (MPDApplication) getApplication(); AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); int songId = (Integer) songlist.get(info.position).get("songid"); switch (item.getItemId()) { case R.id.PLCX_SkipToHere: // skip to selected Song try { app.oMPDAsyncHelper.oMPD.skipToId(songId); } catch (MPDServerException e) { } return true; case R.id.PLCX_playNext: try { // Move song to next in playlist MPDStatus status = app.oMPDAsyncHelper.oMPD.getStatus(); if (info.id < status.getSongPos()) { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getSongPos()); } else { app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getSongPos() + 1); } Tools.notifyUser("Song moved to next in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_moveFirst: try { // Move song to first in playlist app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, 0); Tools.notifyUser("Song moved to first in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_moveLast: try { // Move song to last in playlist MPDStatus status = app.oMPDAsyncHelper.oMPD.getStatus(); app.oMPDAsyncHelper.oMPD.getPlaylist().move(songId, status.getPlaylistLength() - 1); Tools.notifyUser("Song moved to last in list", this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLCX_removeFromPlaylist: try { app.oMPDAsyncHelper.oMPD.getPlaylist().removeById(songId); Tools.notifyUser(getResources().getString(R.string.deletedSongFromPlaylist), this); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; default: return super.onContextItemSelected(item); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { MPDApplication app = (MPDApplication) getApplication(); // Menu actions... switch (item.getItemId()) { case R.id.PLM_MainMenu: Intent i = new Intent(this, MainMenuActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; case R.id.PLM_LibTab: i = new Intent(this, LibraryTabActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); startActivity(i); return true; case R.id.PLM_Clear: try { app.oMPDAsyncHelper.oMPD.getPlaylist().clear(); songlist.clear(); Tools.notifyUser(getResources().getString(R.string.playlistCleared), this); ((SimpleAdapter) getListAdapter()).notifyDataSetChanged(); } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } return true; case R.id.PLM_EditPL: i = new Intent(this, PlaylistRemoveActivity.class); startActivity(i); return true; case R.id.PLM_Manage: i = new Intent(this, PlaylistManagerActivity.class); startActivity(i); return true; case R.id.PLM_Save: i = new Intent(this, PlaylistSaveActivity.class); startActivity(i); return true; case android.R.id.home: finish(); return true; default: return false; } }
@Override public void onListItemClick(ListView l, View v, int position, long id) { // click on a file if (position > currentDirectory.getDirectories().size() - 1 || currentDirectory.getDirectories().size() == 0) { Music music = (Music) currentDirectory.getFiles() .toArray()[position - currentDirectory.getDirectories().size()]; try { MPDApplication app = (MPDApplication) getActivity().getApplication(); int songId = -1; app.oMPDAsyncHelper.oMPD.getPlaylist().add(music); if (songId > -1) { app.oMPDAsyncHelper.oMPD.skipToId(songId); } } catch (MPDServerException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { // click on a directory // open the same sub activity, it would be better to reuse the // same instance Intent intent = new Intent(getActivity(), FSActivity.class); String dir; dir = ((Directory) currentDirectory.getDirectories().toArray()[position]).getFullpath(); if (dir != null) { intent.putExtra("directory", dir); startActivityForResult(intent, -1); } } }
@Override protected void Add(String item) { try { MPDApplication app = (MPDApplication) getActivity().getApplication(); Directory ToAdd = currentDirectory.getDirectory(item); if (ToAdd != null) { // Valid directory app.oMPDAsyncHelper.oMPD.getPlaylist().add(ToAdd); Tools.notifyUser( String.format(getResources().getString(R.string.addedDirectoryToPlaylist), item), FSFragment.this.getActivity()); } else { Music music = currentDirectory.getFileByTitle(item); if (music != null) { app.oMPDAsyncHelper.oMPD.getPlaylist().add(music); Tools.notifyUser( getResources().getString(R.string.songAdded, item), FSFragment.this.getActivity()); } } } catch (MPDServerException e) { e.printStackTrace(); } }