package com.example.administrator.zhapp.activity.ajhxcgl;

import android.content.Intent;
import android.os.Bundle;
import androidx.core.content.ContextCompat;
import com.baoyachi.stepview.VerticalStepView;
import com.example.administrator.zhapp.BaseListViewAdapter.CommonAdapter;
import com.example.administrator.zhapp.R;
import com.example.administrator.zhapp.activity.BaseActivity;
import com.example.administrator.zhapp.contans.Contans;
import com.example.administrator.zhapp.entity.GzqkrzBean;
import com.example.administrator.zhapp.utils.GsonUtils;
import com.example.administrator.zhapp.utils.HttpListener;
import com.example.administrator.zhapp.utils.NohttpUtils;
import com.yolanda.nohttp.NoHttp;
import com.yolanda.nohttp.RequestMethod;
import com.yolanda.nohttp.rest.Request;
import com.yolanda.nohttp.rest.Response;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by ruihong on 2019/9/19.
 */

public class GzqkrzckActivity extends BaseActivity {

    VerticalStepView stepView0;
    private CommonAdapter<GzqkrzBean.RowsBean> adapter;
    private List<GzqkrzBean.RowsBean> datas;
    private String fid;
    private Intent intent;
    private List<String> steapdatas;

    @Override
    public int getContentViewID() {
        return R.layout.activity_gzqkrzck;
    }

    @Override
    protected void initView() {
        stepView0 = findViewById(R.id.step_view0);
        datas = new ArrayList<>();
        steapdatas = new ArrayList<>();
        intent = getIntent();
        fid = intent.getStringExtra("fid");
        setBack();
        setTitle("工作情况日志");
        requestData();
    }

    @Override
    protected void initData() {

    }

    private void requestData() {
        Request<String> request = NoHttp.createStringRequest(Contans.IP + Contans.GZQKRZLIST, RequestMethod.POST);
        request.setDefineRequestBodyForJson(getJson(fid));
        NohttpUtils.getInstance().add(this, 0, request, callback, true, true, "加载中...");

    }

    private HttpListener<String> callback = new HttpListener<String>() {
        @Override
        public void onSucceed(int what, Response<String> response) {

            try {
                GzqkrzBean info = GsonUtils.GsonToBean(response.get(), GzqkrzBean.class);

                if (info != null) {
                    if (!info.getTotal().equals("0")) {
                        datas.clear();
                        datas.addAll(info.getRows());

                        for (int i = 0; i < datas.size(); i++) {
                            steapdatas.add(datas.get(i).getDescription() + "  " + datas.get(i).getOperdate() + " (" + datas.get(i).getName() + ")");
                        }

                        setStepView();
                    } else {
                        datas.clear();
                    }
                } else {
                    showToast("暂无数据");
                }
            } catch (Exception e) {
                e.printStackTrace();
                showToast("数据出错");
            }

        }

        @Override
        public void onFailed(int what, Response<String> response) {

        }


        private void setStepView() {
            stepView0.setStepsViewIndicatorComplectingPosition(steapdatas.size())//设置完成的步数
                    .reverseDraw(false)//default is true
                    .setTextSize(14)
                    .setStepViewTexts(steapdatas)//总步骤
                    .setStepsViewIndicatorCompletedLineColor(ContextCompat.getColor(GzqkrzckActivity.this, R.color.gray2))//设置StepsViewIndicator完成线的颜色
                    .setStepsViewIndicatorUnCompletedLineColor(ContextCompat.getColor(GzqkrzckActivity.this, R.color.d4))//设置StepsViewIndicator未完成线的颜色
                    .setStepViewComplectedTextColor(ContextCompat.getColor(GzqkrzckActivity.this, R.color.tabTextColor))//设置StepsView text完成线的颜色
                    .setStepViewUnComplectedTextColor(ContextCompat.getColor(GzqkrzckActivity.this, R.color.red))//设置StepsView text未完成线的颜色
                    .setStepsViewIndicatorCompleteIcon(ContextCompat.getDrawable(GzqkrzckActivity.this, R.mipmap.icon_complted))//设置StepsViewIndicator CompleteIcon
                    .setStepsViewIndicatorDefaultIcon(ContextCompat.getDrawable(GzqkrzckActivity.this, R.drawable.default_icon))//设置StepsViewIndicator DefaultIcon
                    .setStepsViewIndicatorAttentionIcon(ContextCompat.getDrawable(GzqkrzckActivity.this, R.drawable.attention));//设置StepsViewIndicator AttentionIcon
        }

    };

    private String getJson(String fid) {
        String json = "{\"Rows\": [{\"fid\": \"" + fid + "\"} ],\"Total\": 1}";
        return json;
    }
}
