package com.example.day07_lx_2;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.bean.User;
import com.example.core.BaseLogin;
import com.example.presenter.MyPresenter;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class MainActivity extends AppCompatActivity {
@BindView(R.id.edit_name)
EditText editName;
@BindView(R.id.edit_pwd)
EditText editPwd;
@BindView(R.id.but_ton)
Button butTon;
private MyPresenter myPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
myPresenter = new MyPresenter();
myPresenter.bindBaseLogin(new LoginCall());
}
@OnClick(R.id.but_ton)
public void onViewClicked() {
String name = editName.getText().toString();
String pwd = editPwd.getText().toString();
myPresenter.loginData(name,pwd);
}
class LoginCall implements BaseLogin {
@Override
public void loginSuccess(User user) {
Toast.makeText(MainActivity.this, user.toString(), Toast.LENGTH_SHORT).show();
}
@Override
public void loginError(String msg) {
Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
myPresenter.unbindBaseLogin();
}
}
core类
package com.example.core;
import com.example.bean.User;
public interface BaseLogin {
void loginSuccess(User user);
void loginError(String msg);
}