Ejemplo n.º 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());
    }
  }
Ejemplo n.º 2
0
 private String getArtistForTrackList() {
   Music song;
   String lastArtist = null;
   boolean differentArtists = false;
   for (Item item : items) {
     song = (Music) item;
     if (lastArtist == null) {
       lastArtist = song.getAlbumArtist();
       continue;
     }
     if (!lastArtist.equalsIgnoreCase(song.getAlbumArtist())) {
       differentArtists = true;
       break;
     }
   }
   if (differentArtists || lastArtist == null || lastArtist.equals("")) {
     differentArtists = false;
     for (Item item : items) {
       song = (Music) item;
       if (lastArtist == null) {
         lastArtist = song.getArtist();
         continue;
       }
       if (!lastArtist.equalsIgnoreCase(song.getArtist())) {
         differentArtists = true;
         break;
       }
     }
     if (differentArtists || lastArtist == null || lastArtist.equals("")) {
       return getString(R.string.variousArtists);
     }
     return lastArtist;
   }
   return lastArtist;
 }
Ejemplo n.º 3
0
 private String getTotalTimeForTrackList() {
   Music song;
   long totalTime = 0;
   for (Item item : items) {
     song = (Music) item;
     if (song.getTime() > 0) totalTime += song.getTime();
   }
   return Music.timeToString(totalTime);
 }
Ejemplo n.º 4
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {

    MPDApplication app = (MPDApplication) getApplication(); // Play selected Song

    Music m = musics.get(position);
    try {
      app.oMPDAsyncHelper.oMPD.skipToId(m.getSongId());
    } catch (MPDServerException e) {
    }
  }
Ejemplo n.º 5
0
 @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();
   }
 }
Ejemplo n.º 6
0
  protected void update() {
    MPDApplication app = (MPDApplication) getApplicationContext();
    try {
      MPDPlaylist playlist = app.oMPDAsyncHelper.oMPD.getPlaylist();
      songlist = new ArrayList<HashMap<String, Object>>();
      musics = playlist.getMusicList();
      int playingID = app.oMPDAsyncHelper.oMPD.getStatus().getSongId();
      // The position in the songlist of the currently played song
      int listPlayingID = -1;
      for (Music m : musics) {
        if (m == null) {
          continue;
        }
        HashMap<String, Object> item = new HashMap<String, Object>();
        item.put("songid", m.getSongId());
        item.put("artist", m.getArtist());
        item.put("title", m.getTitle());
        if (m.getSongId() == playingID) {
          item.put("play", android.R.drawable.ic_media_play);
          // Lie a little. Scroll to the previous song than the one playing. That way it shows that
          // there are other songs before
          // it
          listPlayingID = songlist.size() - 1;
        } else {
          item.put("play", 0);
        }
        songlist.add(item);
      }
      SimpleAdapter songs =
          new SimpleAdapter(
              this,
              songlist,
              R.layout.playlist_list_item,
              new String[] {"play", "title", "artist"},
              new int[] {R.id.picture, android.R.id.text1, android.R.id.text2});

      setListAdapter(songs);

      // Only scroll if there is a valid song to scroll to. 0 is a valid song but does not require
      // scroll anyway.
      // Also, only scroll if it's the first update. You don't want your playlist to scroll itself
      // while you are looking at other
      // stuff.
      if (firstUpdate && listPlayingID > 0) setSelection(listPlayingID);
      firstUpdate = false;

    } catch (MPDServerException e) {
    }
  }
Ejemplo n.º 7
0
  protected void update() {
    // TODO: Preserve position!!!
    MPDApplication app = (MPDApplication) getApplicationContext();
    try {
      if (isPlayQueue) {
        MPDPlaylist playlist = app.oMPDAsyncHelper.oMPD.getPlaylist();
        musics = playlist.getMusicList();
      } else {
        musics = app.oMPDAsyncHelper.oMPD.getPlaylistSongs(playlistName);
      }

      songlist = new ArrayList<HashMap<String, Object>>();
      int playingID = app.oMPDAsyncHelper.oMPD.getStatus().getSongId();
      int pos = null == getListView() ? -1 : getListView().getFirstVisiblePosition();
      View view = null == getListView() ? null : getListView().getChildAt(0);
      int top = null == view ? -1 : view.getTop();

      for (Music m : musics) {
        HashMap<String, Object> item = new HashMap<String, Object>();
        item.put("songid", m.getSongId());
        item.put("artist", m.getArtist());
        item.put("title", m.getTitle());
        item.put("marked", false);
        if (isPlayQueue && m.getSongId() == playingID)
          item.put("play", android.R.drawable.ic_media_play);
        else item.put("play", 0);
        songlist.add(item);
      }
      SimpleAdapter songs =
          new SimpleAdapter(
              this,
              songlist,
              R.layout.playlist_editlist_item,
              new String[] {"play", "title", "artist", "marked"},
              new int[] {R.id.picture, android.R.id.text1, android.R.id.text2, R.id.removeCBox});

      setListAdapter(songs);
      if (-1 != pos && -1 != top) {
        getListView().setSelectionFromTop(pos, top);
      }
    } catch (MPDServerException e) {
    }
  }
Ejemplo n.º 8
0
 @Override
 protected ListAdapter getCustomListAdapter() {
   if (items != null) {
     Music song;
     boolean differentArtists = false;
     String lastArtist = null;
     for (Item item : items) {
       song = (Music) item;
       if (lastArtist == null) {
         lastArtist = song.getArtist();
         continue;
       }
       if (!lastArtist.equalsIgnoreCase(song.getArtist())) {
         differentArtists = true;
         break;
       }
     }
     return new ArrayIndexerAdapter(getActivity(), new SongDataBinder(differentArtists), items);
   }
   return super.getCustomListAdapter();
 }
Ejemplo n.º 9
0
 @Override
 public void updateFromItems() {
   super.updateFromItems();
   if (items != null) {
     Music song;
     String lastArtist = null;
     for (Item item : items) {
       song = (Music) item;
       if (lastArtist == null) {
         lastArtist = song.getArtist();
         continue;
       }
     }
     if (lastArtist == null) {
       for (Item item : items) {
         song = (Music) item;
         if (lastArtist == null) {
           lastArtist = song.getArtist();
           continue;
         }
       }
     }
     String artistName = getArtistForTrackList();
     headerArtist.setText(artistName);
     headerInfo.setText(getHeaderInfoString());
     if (coverHelper != null) {
       String filename = null;
       String path = null;
       if (items.size() > 0) {
         song = (Music) items.get(0);
         filename = song.getFilename();
         path = song.getPath();
         artistName = song.getArtist();
       }
       coverArtProgress.setVisibility(ProgressBar.VISIBLE);
       coverHelper.downloadCover(artistName, album.getName(), path, filename);
     } else {
       coverArtListener.onCoverNotFound();
     }
   }
 }
Ejemplo n.º 10
0
 public PlaylistSong(Music m) {
   super(
       m.getAlbum(),
       m.getArtist(),
       m.getAlbumArtist(),
       m.getFullpath(),
       m.getDisc(),
       m.getDate(),
       m.getTime(),
       m.getParentDirectory(),
       m.getTitle(),
       m.getTotalTracks(),
       m.getTrack(),
       m.getSongId(),
       m.getPos(),
       m.getName());
 }