package com.android.chmo.ui.fragment.home;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.android.chmo.R;
import com.android.chmo.base.BaseFragment;
import com.android.chmo.http.HttpApi;
import com.android.chmo.utils.XUtilsImage;

import butterknife.BindView;

/**
 * 轮播图
 */
public class ImageFragment extends BaseFragment {
    @BindView(R.id.ad_image)
    ImageView imageView;



    private View.OnClickListener clickListener;

    private String url;



    @Override
    public int getLayoutRes() {
        return R.layout.banner_image;
    }

    @Override
    public void initView() {
        Bundle args = getArguments();
        ImageView.ScaleType scaleType = ImageView.ScaleType.CENTER_CROP;
        if (null != args) {
            url = args.getString("url");
            String type = args.getString("caleType");
            if(!TextUtils.isEmpty(type) && type.equals("center")){
                scaleType = ImageView.ScaleType.CENTER;
            }
        }

        if (null != url) {
            XUtilsImage.display(imageView, HttpApi.getImgUrl(url),scaleType, R.mipmap.def_img2);
        }
        if (null != clickListener) {
            imageView.setOnClickListener(clickListener);
        }
    }

    public void setClickListener(View.OnClickListener listener) {
        clickListener = listener;
        if (null != imageView) {
            imageView.setOnClickListener(clickListener);
        }
    }

}
