package com.icaynia.soundki.View;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.icaynia.soundki.Model.MusicDto;
import com.icaynia.soundki.Model.PlayList;
import com.icaynia.soundki.R;

import java.util.ArrayList;

/**
 * Created by icaynia on 19/02/2017.
 */

public class PlayListAdapter extends BaseAdapter
{
    public Context context;
    public PlayList list;
    private LayoutInflater inflater;

    public PlayListAdapter(Context context, PlayList list)
    {
        this.context = context;
        this.list = list;
        inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount()
    {
        return list.size();
    }

    @Override
    public Object getItem(int position)
    {
        return list.get(position);
    }

    @Override
    public long getItemId(int position)
    {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            convertView = inflater.inflate(R.layout.view_list_musicrows, parent, false);
            ListView.LayoutParams layoutParams = new ListView.LayoutParams(ListView.LayoutParams.MATCH_PARENT, ListView.LayoutParams.MATCH_PARENT);
            convertView.setLayoutParams(layoutParams);
        }


        return convertView;
    }
}

@@ -60,16 +60,102 @@
 ontext;%0A
+import android.graphics.Bitmap;%0Aimport android.os.AsyncTask;%0Aimport android.util.Log;%0A
 import a
@@ -368,24 +368,109 @@
 .TextView;%0A%0A
+import com.icaynia.soundki.Data.MusicFileManager;%0Aimport com.icaynia.soundki.Global;%0A
 import com.i
@@ -792,16 +792,44 @@
 later;%0A%0A
+    private Global global;%0A%0A
     publ
@@ -1038,16 +1038,75 @@
 RVICE);%0A
+        global = (Global) context.getApplicationContext();%0A
     %7D%0A%0A 
@@ -1829,36 +1829,1959 @@
  %7D%0A%0A
-%0A        return convertView;
+        ImageView album = (ImageView) convertView.findViewById(R.id.view_album);%0A        album.setImageDrawable(context.getResources().getDrawable(android.R.drawable.ic_menu_report_image));%0A        TextView title = (TextView) convertView.findViewById(R.id.view_title);%0A        TextView artist = (TextView) convertView.findViewById(R.id.view_artist);%0A%0A        title.setText(list.get(position).title);%0A        artist.setText(list.get(position).artist + %22 - %22 + list.get(position).album + %22 - %22 + global.mMusicManager.convertToTime(list.get(position).length));%0A%0A        convertView.setTag(list.get(position).id);%0A        MyAsyncTask myAsyncTask = new MyAsyncTask();%0A        myAsyncTask.setImgView(album);%0A        myAsyncTask.execute(position + %22%22);%0A%0A%0A        return convertView;%0A    %7D%0A%0A    public class MyAsyncTask extends AsyncTask%3CString, Void, Bitmap%3E%0A    %7B%0A        private static final String TAG = %22AlbumImageTask%22;%0A        private int position;%0A        private ImageView imgView;%0A        private MusicFileManager mMusicFileManager = new MusicFileManager(context);%0A%0A        public void setImgView(ImageView _imgView)%0A        %7B%0A            this.imgView = _imgView;%0A        %7D%0A%0A        @Override%0A        protected void onPreExecute()%0A        %7B%0A            super.onPreExecute();%0A            Log.i(TAG, %22PreExecute%22);%0A            mMusicFileManager = new MusicFileManager(context);%0A%0A        %7D%0A%0A        @Override%0A        protected Bitmap doInBackground(String... id)%0A        %7B%0A            Bitmap bitmap = null;%0A            for (String i : id)%0A            %7B%0A                this.position = Integer.parseInt(i);%0A                bitmap = mMusicFileManager.getAlbumImage(context, Integer.parseInt(list.get(position).albumid), 100);%0A            %7D%0A            return bitmap;%0A        %7D%0A%0A        @Override%0A        protected void onPostExecute(Bitmap result)%0A        %7B%0A            super.onPostExecute(result);%0A%0A            imgView.setImageBitmap(result);%0A        %7D%0A
 %0A   

Connect data to playlistactivity