コード例 #1
0
  /** Update this {@link TomahawkFragment}'s {@link TomahawkListAdapter} content */
  @Override
  protected void updateAdapter() {
    if (!mIsResumed) {
      return;
    }

    List<TomahawkListItem> albumsAndTopHits = new ArrayList<TomahawkListItem>();
    TomahawkMainActivity activity = (TomahawkMainActivity) getActivity();
    Context context = getActivity();
    LayoutInflater layoutInflater = getActivity().getLayoutInflater();
    View rootView = getView();
    if (mArtist != null) {
      activity.setTitle(mArtist.getName());
      if (mIsLocal) {
        albumsAndTopHits.addAll(mArtist.getLocalAlbums());
      } else {
        albumsAndTopHits.addAll(mArtist.getTopHits());
        albumsAndTopHits.addAll(mArtist.getAlbums());
        mShownQueries = mArtist.getTopHits();
        int precedingItemCount = 0;
        if (getListAdapter() != null
            && ((TomahawkListAdapter) getListAdapter()).isShowingContentHeader()) {
          precedingItemCount++;
        }
        mQueryPositions.clear();
        for (int i = 0; i < mShownQueries.size(); i++) {
          mQueryPositions.put(i, i + precedingItemCount);
        }
      }
      if (getListAdapter() == null) {
        TomahawkListAdapter tomahawkListAdapter =
            new TomahawkListAdapter(context, layoutInflater, albumsAndTopHits);
        tomahawkListAdapter.setShowCategoryHeaders(
            true, TomahawkListAdapter.SHOW_QUERIES_AS_TOPHITS);
        tomahawkListAdapter.showContentHeader(rootView, mArtist, mIsLocal);
        tomahawkListAdapter.setShowResolvedBy(true);
        setListAdapter(tomahawkListAdapter);
      } else {
        ((TomahawkListAdapter) getListAdapter()).setListItems(albumsAndTopHits);
        ((TomahawkListAdapter) getListAdapter()).showContentHeader(rootView, mArtist, mIsLocal);
      }
      getListView().setOnItemClickListener(this);
    } else if (mShowMode == SHOW_MODE_STARREDALBUMS) {
      ArrayList<Album> albums = DatabaseHelper.getInstance().getStarredAlbums();
      albumsAndTopHits.addAll(albums);
      if (getListAdapter() == null) {
        TomahawkListAdapter tomahawkListAdapter =
            new TomahawkListAdapter(context, layoutInflater, albumsAndTopHits);
        setListAdapter(tomahawkListAdapter);
      } else {
        ((TomahawkListAdapter) getListAdapter()).setListItems(albumsAndTopHits);
      }
      getListView().setOnItemClickListener(this);
    } else {
      if (mIsLocal) {
        albumsAndTopHits.addAll(Album.getLocalAlbums());
      } else {
        albumsAndTopHits.addAll(Album.getAlbums());
      }
      if (getGridAdapter() == null) {
        TomahawkGridAdapter tomahawkGridAdapter =
            new TomahawkGridAdapter(activity, layoutInflater, albumsAndTopHits);
        setGridAdapter(tomahawkGridAdapter);
      } else {
        getGridAdapter().setListArray(albumsAndTopHits);
      }
      getGridView().setOnItemClickListener(this);
      adaptColumnCount();
    }

    updateShowPlaystate();
  }