Skip to content

Commit

Permalink
show the songs which is belong to the specific Album
Browse files Browse the repository at this point in the history
  • Loading branch information
Wriprin committed Dec 5, 2020
1 parent 9fdb3b5 commit b9a0a33
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/AlbumDetails.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.wriprin.android.ipod;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.media.Image;
Expand All @@ -20,6 +21,7 @@ public class AlbumDetails extends AppCompatActivity {
ImageView albumPhoto;
String albumName;
ArrayList<MusicFiles> albumSongs = new ArrayList<>();
AlbumDetailsAdapter albumDetailsAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -50,6 +52,19 @@ protected void onCreate(Bundle savedInstanceState) {
.load(R.drawable.bewedoc)
.into(albumPhoto);
}

}

@Override
protected void onResume() {
super.onResume();
if (!(albumSongs.size() < 1))
{
albumDetailsAdapter = new AlbumDetailsAdapter(this, albumSongs);
recyclerView.setAdapter(albumDetailsAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this,
RecyclerView.VERTICAL, false));
}
}

private byte[] getAlbumArt(String uri)
Expand Down
79 changes: 79 additions & 0 deletions app/src/main/java/io/wriprin/android/ipod/AlbumDetailsAdapter.java
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;
}

}
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_album_details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:background="@color/colorPrimary"
tools:context=".AlbumDetails">

<ImageView
Expand Down

0 comments on commit b9a0a33

Please sign in to comment.