package com.sheep.gamegroup.view.activity;

import android.app.Activity;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sheep.gamegroup.di.components.DaggerCommitWxMakeMoneyComponent;
import com.sheep.gamegroup.di.modules.CommitWxMakeMoneyModule;
import com.sheep.gamegroup.model.entity.BaseMessage;
import com.sheep.gamegroup.presenter.CommitWxMakeMoneyContract;
import com.sheep.gamegroup.presenter.CommitWxMakeMoneyPresenter;
import com.sheep.gamegroup.util.Jump2View;
import com.sheep.gamegroup.util.StringUtils;
import com.sheep.jiuyan.samllsheep.BuildConfig;
import com.sheep.jiuyan.samllsheep.R;
import com.sheep.jiuyan.samllsheep.SheepApp;
import com.sheep.gamegroup.absBase.BaseActivity;
import com.sheep.jiuyan.samllsheep.utils.G;
import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by realicing on 2018/3/23.
 * realicing@sina.com
 */

public class CommitWxAct extends BaseActivity implements CommitWxMakeMoneyContract.View{

    @BindView(R.id.tv_wx_commit)
    TextView tv_wx_commit;
    @BindView(R.id.et_wx_account)
    EditText et_wx_account;
    @BindView(R.id.et_wx_pwd)
    EditText et_wx_pwd;
    @OnClick({R.id.tv_wx_commit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_wx_commit:
                String account = et_wx_account.getText().toString();
                String password = et_wx_pwd.getText().toString();
                if(TextUtils.isEmpty(account)){
                    G.showToast("手机号不能为空");
                } else if(!StringUtils.isMobile(account)){
                    G.showToast("请输入正确的手机号");
                } else if(TextUtils.isEmpty(password)){
                    G.showToast("微信密码不能为空");
                } else if(presenter != null) {
                    showProgress();
                    presenter.postWebchat(account, password);
                } else {
                    if(BuildConfig.DEBUG) G.showToast("功能不正常");
                }
                break;
        }
    }
    @Inject
    CommitWxMakeMoneyPresenter presenter;

    private Activity activity;

    @Override
    protected int getLayoutId() {
        return R.layout.commit_wx_make_money;
    }

    @Override
    public void initView() {
        activity = this;
        TitleBarUtils.getInstance()
                .setTitle(activity, "挂机赚钱")
                .setTitleFinish(activity);
        DaggerCommitWxMakeMoneyComponent.builder()
                .netComponent(SheepApp.getInstance().getNetComponent())
                .commitWxMakeMoneyModule(new CommitWxMakeMoneyModule(this))
                .build()
                .inject(this);
        et_wx_account.setHint("请输入微信号");
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void postWebchatUpdataView(BaseMessage baseMessage) {
        hideProgress();
        G.showToast(baseMessage.getData().toString());//提示信息在data里面
        Jump2View.getInstance().goLyingView(this, null);
    }

    @Override
    public void failPostWebchat2View(BaseMessage baseMessage) {
        hideProgress();
        G.showToast(baseMessage);
    }
}
