public class MainActivity extends AppCompatActivity implements IManintenter {
private String path=“http://172.17.8.100/small/user/v1/login”;
private EditText name;
private EditText pwd;
private Button denglu;
private Button zhuce;
private HoemPresenter hoemPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
pwd = findViewById(R.id.pwd);
denglu = findViewById(R.id.denglu);
zhuce = findViewById(R.id.zhuce);
hoemPresenter = new HoemPresenter(this);
denglu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String sname = name.getText().toString();
String spwd = pwd.getText().toString();
hoemPresenter.getpresenter(path,sname,spwd);
}
});
zhuce.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,ZhuChe.class);
startActivity(intent);
}
});
}
@Override
public void getview(String s) {
Log.i("AA","ss"+s);
Gson gson = new Gson();
DengLu dengLu = gson.fromJson(s, DengLu.class);
if (dengLu.getStatus().equals("0000")) {
Intent intent = new Intent(MainActivity.this, ZhanShiActivity.class);
startActivity(intent);
} else if (dengLu.getStatus().equals("1001")) {
Intent intent = new Intent(MainActivity.this, ZhuChe.class);
startActivity(intent);
}
}
}
public class HoemPresenter {
private final Okhttp getdanli;
MainActivity mainActivity;
public HoemPresenter(MainActivity mainActivity1) {
this.mainActivity = mainActivity1;
getdanli = Okhttp.getdanli();
}
public void getpresenter(String s, String name, String pwd) {
getdanli.post(s, name, pwd, new Okhttp.getokhttp() {
@Override
public void getcheng(String s) {
mainActivity.getview(s);
}
});
}
}