|
|
|
|
@ -17,64 +17,80 @@ import com.example.musicplayer.util.CommonUtil;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 自建歌单和收藏歌单的二级适配类
|
|
|
|
|
* 自建歌单和收藏歌单的二级适配类。
|
|
|
|
|
* Created by 残渊 on 2018/9/23.
|
|
|
|
|
*/
|
|
|
|
|
public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
private static final String TAG = "ExpandableListViewAdapter";
|
|
|
|
|
|
|
|
|
|
private String[] mGroupStrings; //一级标题
|
|
|
|
|
private List<List<AlbumCollection>> mAlbumCollectionList; //二级收藏歌单列表
|
|
|
|
|
private Context mContext;
|
|
|
|
|
private OnChildItemClickListener mChildClickListener; //二级item的点击监听
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String[] mGroupStrings; // 一级标题数组
|
|
|
|
|
private List<List<AlbumCollection>> mAlbumCollectionList; // 二级歌单列表
|
|
|
|
|
private Context mContext; // 上下文环境
|
|
|
|
|
private OnChildItemClickListener mChildClickListener; // 二级项的点击监听器
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数,初始化适配器。
|
|
|
|
|
* @param context 上下文环境
|
|
|
|
|
* @param groupStrings 一级标题数组
|
|
|
|
|
* @param albumCollectionList 二级歌单列表
|
|
|
|
|
*/
|
|
|
|
|
public ExpandableListViewAdapter(Context context, String[] groupStrings, List<List<AlbumCollection>> albumCollectionList) {
|
|
|
|
|
mAlbumCollectionList = albumCollectionList;
|
|
|
|
|
mGroupStrings = groupStrings;
|
|
|
|
|
mContext = context;
|
|
|
|
|
}
|
|
|
|
|
//提供给外部使用
|
|
|
|
|
public void setOnChildItemClickListener(OnChildItemClickListener onChildItemClickListener){
|
|
|
|
|
mChildClickListener=onChildItemClickListener;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置二级项的点击监听器。
|
|
|
|
|
* @param onChildItemClickListener 点击监听器
|
|
|
|
|
*/
|
|
|
|
|
public void setOnChildItemClickListener(OnChildItemClickListener onChildItemClickListener){
|
|
|
|
|
mChildClickListener = onChildItemClickListener;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取一级列表的组数
|
|
|
|
|
@Override
|
|
|
|
|
public int getGroupCount() {
|
|
|
|
|
return mGroupStrings.length;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定组的子项数
|
|
|
|
|
@Override
|
|
|
|
|
public int getChildrenCount(int groupPosition) {
|
|
|
|
|
return mAlbumCollectionList.get(groupPosition).size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定组的对象
|
|
|
|
|
@Override
|
|
|
|
|
public Object getGroup(int groupPosition) {
|
|
|
|
|
return mGroupStrings[groupPosition];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定子项的对象
|
|
|
|
|
@Override
|
|
|
|
|
public Object getChild(int groupPosition, int childPosition) {
|
|
|
|
|
return mAlbumCollectionList.get(groupPosition).get(childPosition);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定组的ID
|
|
|
|
|
@Override
|
|
|
|
|
public long getGroupId(int groupPosition) {
|
|
|
|
|
return groupPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定子项的ID
|
|
|
|
|
@Override
|
|
|
|
|
public long getChildId(int groupPosition, int childPosition) {
|
|
|
|
|
return childPosition;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否有稳定的ID
|
|
|
|
|
@Override
|
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//绘制一级列表
|
|
|
|
|
// 绘制一级列表项
|
|
|
|
|
@Override
|
|
|
|
|
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
|
|
|
|
|
View view;
|
|
|
|
|
@ -90,7 +106,7 @@ public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
groupViewHolder = (GroupViewHolder) view.getTag();
|
|
|
|
|
}
|
|
|
|
|
groupViewHolder.groupTextView.setText(mGroupStrings[groupPosition]);
|
|
|
|
|
//根据展开的状态来改变箭头方向
|
|
|
|
|
// 根据展开状态改变箭头方向
|
|
|
|
|
if (isExpanded) {
|
|
|
|
|
groupViewHolder.pointIv.setImageResource(R.drawable.up);
|
|
|
|
|
} else {
|
|
|
|
|
@ -99,8 +115,7 @@ public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//绘制二级列表
|
|
|
|
|
// 绘制二级列表项
|
|
|
|
|
@Override
|
|
|
|
|
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
|
|
|
|
|
View view;
|
|
|
|
|
@ -122,26 +137,28 @@ public class ExpandableListViewAdapter extends BaseExpandableListAdapter {
|
|
|
|
|
childViewHolder.authorTv.setText(mAlbumCollectionList.get(groupPosition).get(childPosition).getSingerName());
|
|
|
|
|
CommonUtil.setImgWithGlide(mContext,
|
|
|
|
|
mAlbumCollectionList.get(groupPosition).get(childPosition).getAlbumPic(), childViewHolder.faceIv);
|
|
|
|
|
//点击水波纹效果,结束后开始点击效果
|
|
|
|
|
childViewHolder.childView.setOnRippleCompleteListener(rippleView -> mChildClickListener.onClick(groupPosition,childPosition));
|
|
|
|
|
// 点击水波纹效果,结束后开始点击效果
|
|
|
|
|
childViewHolder.childView.setOnRippleCompleteListener(rippleView -> mChildClickListener.onClick(groupPosition, childPosition));
|
|
|
|
|
return view;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 是否可以选择子项
|
|
|
|
|
@Override
|
|
|
|
|
public boolean isChildSelectable(int groupPosition, int childPosition) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 一级列表项的ViewHolder
|
|
|
|
|
class GroupViewHolder {
|
|
|
|
|
private TextView groupTextView;
|
|
|
|
|
private ImageView pointIv;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 二级列表项的ViewHolder
|
|
|
|
|
class ChildViewHolder {
|
|
|
|
|
TextView albumNameTv;
|
|
|
|
|
ImageView faceIv;
|
|
|
|
|
TextView authorTv;
|
|
|
|
|
RippleView childView;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|