package com.fxy.base.fragment;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.elvishew.xlog.XLog;
import com.fxy.baselibrary.base.BaseFragment;
import com.fxy.baselibrary.views.dialog.RxDialogZoomImageView;
import com.fxy.R;
import com.fxy.adapter.ShowImgAdapter;

import java.util.ArrayList;

/**
 * Created by lijie on 2018/4/10.
 */

public class ShowImgFragment  extends BaseFragment {

    private RecyclerView mRvShowImg ;
    private ShowImgAdapter mPhotoAdapter;
    private ArrayList<String>imgPathList=new ArrayList<>();

    @Override
    protected int getLayoutRes() {
        return R.layout.fragment_show_img;
    }

    public static ShowImgFragment newInstance(ArrayList<String> imgList){
        Bundle bundle = new Bundle();
        bundle.putStringArrayList("imgList",imgList);
        ShowImgFragment showImgFragment = new ShowImgFragment();
        showImgFragment.setArguments(bundle);
        return showImgFragment;
    }

    @Override
    protected void initView(View rootView) {
        mRvShowImg = rootView.findViewById(R.id.rv_show_img);
        rootView.findViewById(R.id.ll_add_img).setVisibility(imgPathList.size()==0?View.GONE:View.VISIBLE);
        initAdapter();
    }

    private void initAdapter() {
        mPhotoAdapter = new ShowImgAdapter(getActivity(), imgPathList);
        mRvShowImg.setLayoutManager(new GridLayoutManager(getActivity(),3));
        mRvShowImg.setAdapter(mPhotoAdapter);
        XLog.d("imgList: " +imgPathList.toString());
        mPhotoAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                RxDialogZoomImageView rxDialogZoomImageView = new RxDialogZoomImageView(getActivity());
                rxDialogZoomImageView.setImagePath(imgPathList.get(position));
                rxDialogZoomImageView.show();
            }
        });
    }

    @Override
    protected void getBundleExtras(Bundle bundle) {
        imgPathList.addAll(bundle.getStringArrayList("imgList"));
    }

    @Override
    protected void initLogic() {

    }


}
