Example #1
0
  @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());
    }
  }
Example #2
0
  @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);
      }
    }
  }
Example #3
0
 @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();
   }
 }