2 * Copyright (C) 2012 Andrew Neal
3 * Copyright (C) 2014 The CyanogenMod Project
4 * Licensed under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with the
6 * License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
8 * or agreed to in writing, software distributed under the License is
9 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
10 * KIND, either express or implied. See the License for the specific language
11 * governing permissions and limitations under the License.
14 package com.cyanogenmod.eleven.adapters;
16 import android.app.Activity;
17 import android.view.LayoutInflater;
18 import android.view.View;
19 import android.view.ViewGroup;
20 import android.widget.ArrayAdapter;
22 import com.cyanogenmod.eleven.Config;
23 import com.cyanogenmod.eleven.model.Song;
25 import java.util.Collection;
28 * This {@link ArrayAdapter} is used to display the songs for a particular playlist
29 * {@link com.cyanogenmod.eleven.ui.fragments.PlaylistDetailFragment}
31 * @author Andrew Neal (andrewdneal@gmail.com)
33 public class ProfileSongAdapter extends SongAdapter {
35 * Instead of having random +1 and -1 sprinkled around, this variable will show what is really
36 * related to the header
38 public static final int NUM_HEADERS = 1;
41 * Fake header layout Id
43 private final int mHeaderId;
46 * Constructor of <code>ProfileSongAdapter</code>
48 * @param activity The {@link Activity} to use
49 * @param layoutId The resource Id of the view to inflate.
51 public ProfileSongAdapter(final long playlistId, final Activity activity, final int layoutId,
53 super(activity, layoutId, playlistId, Config.IdType.Playlist);
62 public View getView(final int position, View convertView, final ViewGroup parent) {
64 // Return a faux header at position 0
66 if (convertView == null) {
67 convertView = LayoutInflater.from(getContext()).inflate(mHeaderId, parent, false);
73 return super.getView(position, convertView, parent);
79 protected boolean showNowPlayingIndicator(final Song song, final int position) {
80 return super.showNowPlayingIndicator(song, position)
81 && mCurrentlyPlayingTrack.mSourcePosition == position - NUM_HEADERS;
85 public boolean isEnabled(int position) {
90 return super.isEnabled(position);
97 public int getViewTypeCount() {
98 return super.getViewTypeCount() + NUM_HEADERS;
105 public int getItemViewType(final int position) {
107 // since our view type count adds 1 to the super class, we can return viewtypecount - 1
108 return getViewTypeCount() - 1;
110 return super.getItemViewType(position);
114 public void addAll(Collection<? extends Song> collection) {
115 // insert a header if one is needed
117 super.addAll(collection);
121 public void addAll(Song... items) {
122 // insert a header if one is needed
128 * Make sure we insert our header when we add items
130 private void insertHeader() {
131 if (getCount() == 0) {
132 // add a dummy entry to the underlying adapter. This is needed otherwise the
133 // underlying adapter could crash because getCount() doesn't match up
134 add(new Song(-1, null, null, null, -1, -1, -1));