package com.zhilin.patrol.ui.activity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.support.v7.app.AppCompatActivity;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cjj.MaterialRefreshLayout;
import com.cjj.MaterialRefreshListener;
import com.zhilin.patrol.R;
import com.zhilin.patrol.bean.HomeEntity;
import com.zhilin.patrol.bean.LoginEntity;
import com.zhilin.patrol.http.HttpUrl;
import com.zhilin.patrol.tool.DialogUtil;
import com.zhilin.patrol.tool.IpUtils;
import com.zhilin.patrol.tool.JsonUtils;
import com.zhilin.patrol.tool.SPUtil;
import com.zhilin.patrol.views.AlertDialog;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.Callback;
import com.zhy.http.okhttp.request.RequestCall;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import okhttp3.Call;
import okhttp3.Response;

/**
 * 主页面
 */
public class RectifyMainActivity extends AppCompatActivity {

    @BindView(R.id.tv_user)
    TextView mUserTv;//用户
    @BindView(R.id.tv_sex)
    TextView mSexTv;//性别
    @BindView(R.id.tv_logout)
    TextView mLogoutTv;//注销



    /** 用户信息 */
    LoginEntity.InfoListBean mInfoListBean;
    private LoginEntity.InfoListBean.UserInfoBean mUserInfo;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_rectify);
        ButterKnife.bind(this);
        mInfoListBean = (LoginEntity.InfoListBean) getIntent().getSerializableExtra("infoList");
        mUserInfo = mInfoListBean.getUserInfo();
        init();
    }

    private void init() {
        if (mUserInfo != null) {
            mUserTv.setText(mUserInfo.getUserName());
            mSexTv.setText(mUserInfo.getUserSex());
        }

    }

    @OnClick({ R.id.tv_logout,R.id.rl_rectify_task,R.id.rl_unpass_task,R.id.rl_reject_task})
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_unpass_task://整改不通过
                Intent intent = new Intent(RectifyMainActivity.this, RectifyTaskActivity.class);
                intent.putExtra("userInfo", mUserInfo);
                intent.putExtra("mType",3);
                startActivity(intent);
                break;
            case R.id.rl_rectify_task://整改任务
                Intent intent2 = new Intent(RectifyMainActivity.this, RectifyTaskActivity.class);
                intent2.putExtra("userInfo", mUserInfo);
                intent2.putExtra("mType",1);
                startActivity(intent2);
                break;
            case R.id.rl_reject_task://复议被驳回
                Intent intent3 = new Intent(RectifyMainActivity.this, ReconsiderActivity.class);
                intent3.putExtra("userInfo", mUserInfo);
                intent3.putExtra("mType",2);
                startActivity(intent3);
                break;
            case R.id.tv_logout://注销
                new AlertDialog(this).builder()
                        .setTitle(getString(R.string.tv_tishi))
                        .setMsg("确定要注销?")
                        .setPositiveButton("注销", new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                SPUtil.savaToShared(RectifyMainActivity.this, SPUtil.SP_COMMON_CONFIG, "infoList", "");
                                finish();
                                Intent intent=new Intent(RectifyMainActivity.this,LoginActivity.class);
                                startActivity(intent);
                            }
                        }).setNegativeButton("取消", new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {

                    }
                }).show();
                break;
            default:
                break;
        }
    }

}
