package me.jessyan.mvpart.demo.mvp.ui.holder;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import me.jessyan.art.base.App;
import me.jessyan.art.base.BaseHolder;
import me.jessyan.art.di.component.AppComponent;
import me.jessyan.art.widget.imageloader.ImageLoader;
import me.jessyan.art.widget.imageloader.glide.GlideImageConfig;
import me.jessyan.mvpart.demo.R;
import me.jessyan.mvpart.demo.mvp.model.entity.User;

/**
 * Created by jess on 9/4/16 12:56
 * Contact with jess.yan.effort@gmail.com
 */
public class UserItemHolder extends BaseHolder<User> {

    @Nullable
    @BindView(R.id.iv_avatar)
    ImageView mAvater;
    @Nullable
    @BindView(R.id.tv_name)
    TextView mName;
    private AppComponent mAppComponent;
    private ImageLoader mImageLoader;//用于加载图片的管理类,默认使用glide,使用策略模式,可替换框架

    public UserItemHolder(View itemView) {
        super(itemView);
        //可以在任何可以拿到Application的地方,拿到AppComponent,从而得到用Dagger管理的单例对象
        mAppComponent = ((App) itemView.getContext().getApplicationContext()).getAppComponent();
        mImageLoader = mAppComponent.imageLoader();
    }

    @Override
    public void setData(User data, int position) {

        mName.setText(data.getLogin());

        mImageLoader.loadImage(mAppComponent.appManager().getCurrentActivity(), GlideImageConfig
                .builder()
                .url(data.getAvatarUrl())
                .imageView(mAvater)
                .build());
    }


    @Override
    protected void onRelease() {
        mImageLoader.clear(mAppComponent.Application(),GlideImageConfig.builder()
                .imageViews(mAvater)
                .build());
    }
}

@@ -1392,17 +1392,145 @@
 tivity()
-,
+ == null%0A                        ? mAppComponent.Application() : mAppComponent.appManager().getCurrentActivity(),%0A               
  GlideIm
@@ -1551,24 +1551,32 @@
             
+        
 .builder()%0A 
@@ -1590,16 +1590,24 @@
         
+     
+   
 .url(dat
@@ -1632,32 +1632,40 @@
                 
+        
 .imageView(mAvat
@@ -1660,32 +1660,40 @@
 geView(mAvater)%0A
+        
                 
@@ -1813,16 +1813,17 @@
 ation(),
+ 
 GlideIma

fix demo bug