@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()); } }
@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); } } }