package me.echeung.moemoekyun.adapters;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

import me.echeung.listenmoeapi.models.Song;
import me.echeung.moemoekyun.R;

public class SongDetailAdapter extends ArrayAdapter<Song> {

    public SongDetailAdapter(@NonNull Context context, List<Song> songs) {
        super(context, 0, songs);
    }

    @NonNull
    @Override
    public View getView(int position, View view, @NonNull ViewGroup parent) {
        if (view == null) {
            view = LayoutInflater.from(getContext()).inflate(R.layout.song_detail_item, parent, false);
        }

        final Song song = getItem(position);

        ((TextView) view.findViewById(R.id.title)).setText(song.getTitle());
        ((TextView) view.findViewById(R.id.artist)).setText(song.getArtistString());

        return view;
    }

}

@@ -109,16 +109,47 @@
 onNull;%0A
+import android.text.TextUtils;%0A
 import a
@@ -291,24 +291,198 @@
 .widget.
-TextView
+ImageView;%0Aimport android.widget.TextView;%0A%0Aimport com.bumptech.glide.Glide;%0Aimport com.bumptech.glide.load.engine.DiskCacheStrategy;%0Aimport com.bumptech.glide.request.RequestOptions
 ;%0A%0Aimpor
@@ -740,9 +740,33 @@
 xt, 
-0
+R.layout.song_detail_item
 , so
@@ -848,17 +848,24 @@
 n, View 
-v
+convertV
 iew, @No
@@ -902,129 +902,605 @@
     
-if (view == null) %7B%0A            view = LayoutInflater.from(getContext()).inflate(R.layout.song_detail_item, parent, false
+ViewHolder viewHolder;%0A        if (convertView == null) %7B%0A            viewHolder = new ViewHolder();%0A%0A            LayoutInflater inflater = LayoutInflater.from(getContext());%0A            convertView = inflater.inflate(R.layout.song_detail_item, parent, false);%0A%0A            viewHolder.title = convertView.findViewById(R.id.title);%0A            viewHolder.artist = convertView.findViewById(R.id.artist);%0A            viewHolder.albumArt = convertView.findViewById(R.id.album_art);%0A%0A            convertView.setTag(viewHolder);%0A        %7D else %7B%0A            viewHolder = (ViewHolder) convertView.getTag(
 );%0A 
@@ -1554,25 +1554,24 @@
 ition);%0A
-%0A
         
 ((TextVi
@@ -1566,50 +1566,76 @@
     
-((TextView) view.findViewById(R.id.title))
+viewHolder.title.setText(song.getTitle());%0A        viewHolder.artist
 .set
@@ -1647,34 +1647,42 @@
 song.get
-Title
+ArtistString
 ());%0A
+%0A
         
 ((TextVi
@@ -1677,105 +1677,634 @@
     
-((TextView) view.findViewById(R.id.artist)).setText(song.getArtistString());%0A%0A        return view
+if (!TextUtils.isEmpty(song.getAlbumArtUrl())) %7B%0A            Glide.with(getContext())%0A                    .asBitmap()%0A                    .load(song.getAlbumArtUrl())%0A                    .apply(new RequestOptions()%0A                            .diskCacheStrategy(DiskCacheStrategy.NONE)%0A                            .centerCrop())%0A                    .into(viewHolder.albumArt);%0A        %7D else %7B%0A            viewHolder.albumArt.setBackgroundResource(R.drawable.blank);%0A        %7D%0A%0A        return convertView;%0A    %7D%0A%0A    private static class ViewHolder %7B%0A        TextView title;%0A        TextView artist;%0A        ImageView albumArt
 ;%0A  

Use a view holder for song details list