它不是读取文件夹中的唱片封面,而是读取播放列表的封面
private ArrayList<String> folderNames;
static ArrayList<MusicFiles> musicFiles;
private Context mContext;
public FolderAdapter(ArrayList<String> folderNames, ArrayList<MusicFiles> musicFiles, Context mContext) {
this.folderNames = folderNames;
this.musicFiles = musicFiles;
this.mContext = mContext;
}
@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.folder_item, parent,
false);
return new MyHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyHolder holder, final int position) {
int index = folderNames.get(position).lastIndexOf("/");
String folder = folderNames.get(position).substring(index + 1);
holder.folder.setText(folder);
holder.counterFiles.setText(String.valueOf(NumberOffFiles(folderNames.get(position))));
Bitmap image = getAlbum(musicFiles.get(position).getPatch());
if (image != null) {
Glide.with(mContext).asBitmap()
.load(image)
.into(holder.cover);
} else {
Glide.with(mContext)
.load(R.drawable.img_music)
.into(holder.cover);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(mContext,VideoFolderActivity.class);
intent.putExtra("folderNames", folderNames.get(position));
mContext.startActivity(intent);
}
});
}
@Override
public int getItemCount() {
return folderNames.size();
}
static class MyHolder extends RecyclerView.ViewHolder {
TextView folder, counterFiles;
ImageView capa_da_pasta;
public MyHolder(@NonNull View itemView) {
super(itemView);
folder = itemView.findViewById(R.id.folderName);
counterFiles = itemView.findViewById(R.id.count_files_folder);
cover = itemView.findViewById(R.id.folderImage);
}
}
int NumberOffFiles(String folderNames){
int countFiles = 0;
for (MusicFiles musicFiles : musicFiles) {
if (musicFiles.getPatch()
.substring(0, musicFiles.getPatch().lastIndexOf("/"))
.endsWith(folderNames)) {
countFiles++;
}
}
return countFiles;
}
代码必须阅读专辑封面!!!
代码必须阅读专辑封面!!!
它不是读取文件夹中的唱片封面,而是读取播放列表的封面
暂无答案!
目前还没有任何答案,快来回答吧!