package com.bonait.bnframework.modules.home.fragment.mode;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.bonait.bnframework.R;
import com.bonait.bnframework.common.db.res.lcMode;
import com.bonait.bnframework.common.helper.I.MyClickListener;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class jingdutiao1 extends LinearLayout {
    @BindView(R.id.t_progressBar)
    ProgressBar t_progressBar;
    @BindView(R.id.t_text)
    TextView t_text;

    @BindView(R.id.xuhao)
    TextView xuhao;

    @BindView(R.id.silosname)
    TextView silosname;

    @BindView(R.id.silos_sz)
    RelativeLayout silos_sz;

    public MyClickListener listener=null;
    /**
     * 当前进度
     */
    public int value=0;
    private View root;

    public jingdutiao1(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        root= LayoutInflater.from(context).inflate(R.layout.item_jingdutiao1, this);
        ButterKnife.bind(this, root);
        Init();
    }

    public void Init()
    {
        SetValue(60);
    }
    /**
     * 点击事件
     *
     * @param view
     */
    @OnClick({R.id.silos_sz})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.silos_sz://
                if(listener!=null)
                {
                    listener.clickListener(view,mode);
                }
                break;
        }
    }
    /**
     * 设置级别
     * @param
     */
    public void SetValue(int data)
    {
        String str= this.getTag().toString();
        String str1= this.getContentDescription().toString();
        xuhao.setText(str1+"");
        silosname.setText(str+"");
        value=data;
        t_progressBar.setProgress(data);
        t_text.setText(data+"%");
    }
    public lcMode mode=null;
    /**
     * 设置级别
     * @param
     */
    public void SetValue(lcMode data,MyClickListener _listener)
    {
        mode=data;
        listener=_listener;
        xuhao.setText(GetNum(data.num)+"");
        silosname.setText(data.materialName+"");
        int bfb=0;
        int yl=data.silosmargin;
        int zl=data.siloszl;
        int gj=data.warningValue;
        if(zl==0)
        {
            bfb=0;
        }else
        {
            bfb=((yl*100)/zl)>=100?100:((yl*100)/zl);
        }
        value=bfb;
        t_progressBar.setProgress(bfb);
        if(yl<=gj)
        {
            t_progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress_gj));
        }else
        {
            t_progressBar.setProgressDrawable(getResources().getDrawable(R.drawable.progress_zc));
        }
        t_text.setText(bfb+"%");
    }

    public String GetNum(int num)
    {
        if(num==1)
        {
            return "①";
        }else if(num==2)
        {
            return "②";
        }else if(num==3)
        {
            return "③";
        }else if(num==4)
        {
            return "④(水阀)";
        }else if(num==5)
        {
            return "⑤";
        }else if(num==6)
        {
            return "⑥";
        }else
        {
            return "①";
        }
    }
}
