Beispiel #1
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) {
    }
  }
  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) {
    }
  }