package com.sebastian.sokolowski.auctionhunter.main.adapter;

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

import com.sebastian.sokolowski.auctionhunter.R;
import com.sebastian.sokolowski.auctionhunter.database.models.Target;
import com.sebastian.sokolowski.auctionhunter.main.MainPresenter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Sebastain Sokołowski on 21.02.17.
 */

public class DrawerAdapter extends BaseAdapter {
    private final MainPresenter mainPresenter;
    private final Context context;


    private List<Target> targetList = new ArrayList<>();

    {
        Target target1 = new Target();
        target1.setDrawerName("czekolada");
        target1.setCountAll(12);
        Target target2 = new Target();
        target2.setDrawerName("laptop");
        target2.setCountAll(41);
        Target target3 = new Target();
        target3.setDrawerName("samsung s6");
        target3.setCountAll(100);

        targetList.add(target1);
        targetList.add(target2);
        targetList.add(target3);
    }

    public DrawerAdapter(Context context, MainPresenter mainPresenter) {
        this.context = context;
        this.mainPresenter = mainPresenter;
    }

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

    @Override
    public Target getItem(int position) {
        return targetList.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).
                    inflate(R.layout.list_drawer_target_item, parent, false);
        }
        Target currentItem = getItem(position);

        TextView targetNameTv = (TextView)
                convertView.findViewById(R.id.target_name_tv);
        TextView targetCountTv = (TextView)
                convertView.findViewById(R.id.target_counter_tv);

        targetNameTv.setText(currentItem.getDrawerName());
        targetCountTv.setText(currentItem.getCountNow() + "/" + currentItem.getCountAll());

        return convertView;
    }
}

@@ -370,74 +370,8 @@
 get;
-%0Aimport com.sebastian.sokolowski.auctionhunter.main.MainPresenter;
 %0A%0Aim
@@ -530,55 +530,8 @@
 r %7B%0A
-    private final MainPresenter mainPresenter;%0A
     
@@ -561,18 +561,16 @@
 ontext;%0A
-%0A%0A
     priv
@@ -622,614 +622,268 @@
 ();%0A
-%0A    %7B%0A        Target target1 = new Target();%0A        target1.setDrawerName(%22czekolada%22);%0A        target1.setCountAll(12);%0A        Target target2 = new Target();%0A        target2.setDrawerName(%22laptop%22);%0A        target2.setCountAll(41);%0A        Target target3 = new Target();%0A        target3.setDrawerName(%22samsung s6%22);%0A        target3.setCountAll(100);%0A%0A        targetList.add(target1);%0A        targetList.add(target2);%0A        targetList.add(target3);%0A    %7D%0A%0A    public DrawerAdapter(Context context, MainPresenter mainPres
+    private OnClickDrawerItemListener mOnClickListener;%0A%0A    public DrawerAdapter(Context context) %7B%0A        this.context = context;%0A    %7D%0A%0A    public void setOnClickListener(OnClickDrawerItemList
 en
-t
 er
-) %7B%0A        this.context = context;%0A        this.mainPres
+ onClickListener) %7B%0A        mOnClickList
 en
-t
 er = 
-mainPres
+onClickList
 en
-t
 er;%0A
@@ -1441,16 +1441,22 @@
         
+final 
 Target c
@@ -1815,17 +1815,17 @@
 etCountN
-o
+e
 w() + %22/
@@ -1869,26 +1869,575 @@
     
-return convertView
+if (mOnClickListener != null) %7B%0A            convertView.setOnClickListener(new View.OnClickListener() %7B%0A                @Override%0A                public void onClick(View v) %7B%0A                    mOnClickListener.onClick(currentItem);%0A                %7D%0A            %7D);%0A        %7D%0A%0A        return convertView;%0A    %7D%0A%0A    public void setItems(List%3CTarget%3E targetList) %7B%0A        this.targetList.clear();%0A        this.targetList.addAll(targetList);%0A        notifyDataSetChanged();%0A    %7D%0A%0A    public interface OnClickDrawerItemListener %7B%0A        void onClick(Target target)
 ;%0A  

Add missing changes to drawer adapter