package com.uas.module.mine;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.alibaba.fastjson.JSON;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.SPUtils;
import com.uas.module.common.base.fragment.EasyFragment;
import com.uas.module.common.glide.ImageUtils;
import com.uas.module.common.model.AccountInfo;
import com.uas.module.common.model.CompanyBean;
import com.uas.module.common.utils.Constants;
import com.uas.module.common.utils.StatusBarUtil;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;


public class MineFragment extends EasyFragment implements View.OnClickListener{

    private FrameLayout vg;
    private TextView company_tv;
    private RelativeLayout rl_company_change;
    private TextView mNickNameTv;
    private TextView mPhoneNumTv;

    private CircleImageView mUserHeader;

    public static MineFragment newInstance() {
        return new MineFragment();
    }

    @Override
    protected int inflateLayoutId() {
        return R.layout.fragment_mine;
    }

    @Override
    protected void onCreateView(Bundle savedInstanceState, boolean createView) {
         if(createView){
             initView();
         }
    }


    private void initView() {
        android.support.v7.widget.Toolbar meToolbar = findViewById(R.id.meToolbar);
        TextView meTitleTv = findViewById(R.id.meTitleTv);
        vg = findViewById(R.id.vg);

        if (meToolbar != null) {
            StatusBarUtil.immersive(getActivity(), 0x00000000, 0.0f);
            ((AppCompatActivity) ct).setSupportActionBar(meToolbar);
            ((AppCompatActivity) ct).getSupportActionBar().setDisplayShowTitleEnabled(false);
            StatusBarUtil.setPaddingSmart(ct, meToolbar);
        }
        meTitleTv.setText(R.string.me);


        company_tv = findViewById(R.id.company_tv);
        rl_company_change = findViewById(R.id.rl_company_change);
        mNickNameTv = findViewById(R.id.nick_name_tv);
        
        mPhoneNumTv = findViewById(R.id.phone_number_tv);
        mUserHeader=findViewById(R.id.avatar_img);
        
        findViewById(R.id.setting_rl).setOnClickListener(this);
        findViewById(R.id.rl_company_change).setOnClickListener(this);



        initData();
    }
   
    public void initData(){
        LogUtils.d("user:"+SPUtils.getInstance(Constants.spName).getString("user"));
        AccountInfo account= JSON.parseObject(SPUtils.getInstance(Constants.spName).getString("user")
      ,AccountInfo.class);
       LogUtils.d("accountInfo:"+JSON.toJSONString(account));

       String companys= SPUtils.getInstance(Constants.spName).getString("companyList");
       LogUtils.d("companys:"+companys);
      
      mNickNameTv.setText(account.getRealname());
      mPhoneNumTv.setText(account.getMobile());
        
      List<CompanyBean> companyBeans=JSON.parseArray(companys,CompanyBean.class);
      company_tv.setText(companyBeans.get(0).getName());
      
        
      
      //https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2581650008,2183127638&fm=27&gp=0.jpg

      ImageUtils.loadImageView("https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2581650008,2183127638&fm=27&gp=0.jpg",
                mUserHeader);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.setting_rl) {
            ARouter.getInstance().build("/home/setting").navigation();
        }else if(i ==R.id.rl_company_change){
            
        }
    }
}
