-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
show the songs which is belong to the specific Album
- Loading branch information
Showing
3 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/main/java/io/wriprin/android/ipod/AlbumDetailsAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.wriprin.android.ipod; | ||
|
||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.media.Image; | ||
import android.media.MediaMetadataRetriever; | ||
import android.text.Layout; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.ImageView; | ||
import android.widget.TextView; | ||
|
||
import androidx.annotation.NonNull; | ||
import androidx.recyclerview.widget.RecyclerView; | ||
|
||
import com.bumptech.glide.Glide; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class AlbumDetailsAdapter extends RecyclerView.Adapter<AlbumDetailsAdapter.MyHolder> { | ||
private Context mContext; | ||
private ArrayList<MusicFiles> albumFiles; | ||
View view; | ||
public AlbumDetailsAdapter(Context mContext, ArrayList<MusicFiles> albumFiles) { | ||
this.mContext = mContext; | ||
this.albumFiles = albumFiles; | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) { | ||
view = LayoutInflater.from(mContext).inflate(R.layout.music_items, parent, false); | ||
return new MyHolder(view); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(@NonNull MyHolder holder, final int position) { | ||
holder.album_name.setText(albumFiles.get(position).getTitle()); | ||
byte[] image = getAlbumArt(albumFiles.get(position).getPath()); | ||
if (image != null) | ||
{ | ||
Glide.with(mContext).asBitmap() | ||
.load(image) | ||
.into(holder.album_image); | ||
} | ||
else { | ||
Glide.with(mContext) | ||
.load(R.drawable.bewedoc) | ||
.into(holder.album_image); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public int getItemCount() { | ||
return albumFiles.size(); | ||
} | ||
|
||
public class MyHolder extends RecyclerView.ViewHolder { | ||
ImageView album_image; | ||
TextView album_name; | ||
public MyHolder(@NonNull View itemView) { | ||
super(itemView); | ||
album_image = itemView.findViewById(R.id.music_img); | ||
album_name = itemView.findViewById(R.id.music_file_name); | ||
} | ||
} | ||
|
||
private byte[] getAlbumArt(String uri) | ||
{ | ||
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); | ||
retriever.setDataSource(uri); | ||
byte[] art = retriever.getEmbeddedPicture(); | ||
retriever.release(); | ||
return art; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters