package com.lzy.mmd.activity;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.lzy.mmd.R;
import com.lzy.mmd.bean.User;
import com.lzy.mmd.exoplayer.SampleChooserActivity;
import com.lzy.mmd.mvptest.ui.LoginInfoActivity;
import com.lzy.mmd.presenter.LoginPresenter;
import com.lzy.mmd.presenter.LoginPresenterImpl;
import com.lzy.mmd.view.ILoginView;
import com.lzy.mmd.widget.CircleImageView;

/**
 * Created by lizhaoyong on 2016/3/30.
 */
public class LoginActivity extends BaseActivity implements ILoginView{
    private com.lzy.mmd.widget.CircleImageView civ_logo;
    private android.widget.EditText tv_username;
    private android.widget.EditText tv_password;
    private android.widget.Button btn_login;
    private android.widget.TextView tv_unlogin;
    private android.widget.TextView tv_register;
    private LoginPresenter loginPresenter;

    @Override
    protected void initViews() {
        setContentView(R.layout.activity_login);
        tv_register = (TextView) findViewById(R.id.tv_register);
        tv_unlogin = (TextView) findViewById(R.id.tv_unlogin);
        btn_login = (Button) findViewById(R.id.btn_login);
        tv_password = (EditText) findViewById(R.id.tv_password);
        tv_username = (EditText) findViewById(R.id.tv_username);
        civ_logo = (CircleImageView) findViewById(R.id.civ_logo);
//        tv_unlogin.setAutoLinkMask(Linkify.ALL);
//        tv_unlogin.setText("http://www.erdian.net/m.html");
        initEvents();
    }

    @Override
    protected void initEvents() {
        loginPresenter = new LoginPresenterImpl(LoginActivity.this);
        loginPresenter.setUser();
        btn_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                Map<String,String> parameter = new HashMap<String,String>();
//                parameter.put("logintype", "2");
//                parameter.put("username","15311437664");
//                parameter.put("userpwd", DES.encryptpwd("15311437664", "123456"));
//                loginPresenter.login(parameter);
                Intent intent = new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
        tv_register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(LoginActivity.this,SampleChooserActivity.class);
                startActivity(intent);
            }
        });
        tv_unlogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(LoginActivity.this,LoginInfoActivity.class);
                startActivity(intent);
            }
        });
    }

    @Override
    public void login(int ok) {
//        if (ok==1){
            Intent intent = new Intent(this,MainActivity.class);
            startActivity(intent);
//        }
    }

    @Override
    public void setUser(User user) {
//        Glide.with(this).load(user.getEBS_logo()).into(civ_logo);
    }
}
