我是靠谱客的博主 受伤枫叶,最近开发中收集的这篇文章主要介绍Android - 原生登录注册页面【仿】淘宝Appbean文件夹:解析数据图片文件xml文件model文件夹:数据层view文件夹:视图层persenter文件夹:逻辑层,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

这里写图片描述这里写图片描述

bean文件夹:解析数据

LoginBean.java

private String msg;
private String code;
private DataBean data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public DataBean getData() {
return data;
}
public void setData(DataBean data) {
this.data = data;
}
public static class DataBean {
private Object age;
private String appkey;
private String appsecret;
private String createtime;
private Object email;
private Object fans;
private Object follow;
private Object gender;
private Object icon;
private Object latitude;
private Object longitude;
private String mobile;
private Object money;
private String nickname;
private String password;
private Object praiseNum;
private String token;
private int uid;
private Object userId;
private String username;
public Object getAge() {
return age;
}
public void setAge(Object age) {
this.age = age;
}
public String getAppkey() {
return appkey;
}
public void setAppkey(String appkey) {
this.appkey = appkey;
}
public String getAppsecret() {
return appsecret;
}
public void setAppsecret(String appsecret) {
this.appsecret = appsecret;
}
public String getCreatetime() {
return createtime;
}
public void setCreatetime(String createtime) {
this.createtime = createtime;
}
public Object getEmail() {
return email;
}
public void setEmail(Object email) {
this.email = email;
}
public Object getFans() {
return fans;
}
public void setFans(Object fans) {
this.fans = fans;
}
public Object getFollow() {
return follow;
}
public void setFollow(Object follow) {
this.follow = follow;
}
public Object getGender() {
return gender;
}
public void setGender(Object gender) {
this.gender = gender;
}
public Object getIcon() {
return icon;
}
public void setIcon(Object icon) {
this.icon = icon;
}
public Object getLatitude() {
return latitude;
}
public void setLatitude(Object latitude) {
this.latitude = latitude;
}
public Object getLongitude() {
return longitude;
}
public void setLongitude(Object longitude) {
this.longitude = longitude;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Object getMoney() {
return money;
}
public void setMoney(Object money) {
this.money = money;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Object getPraiseNum() {
return praiseNum;
}
public void setPraiseNum(Object praiseNum) {
this.praiseNum = praiseNum;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public int getUid() {
return uid;
}
public void setUid(int uid) {
this.uid = uid;
}
public Object getUserId() {
return userId;
}
public void setUserId(Object userId) {
this.userId = userId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
}

RegisBean.java

public class RegisBean {
private String msg;
private String code;
private String data;
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
}

图片文件

这里写图片描述

xml文件

activity_main.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<ImageView

android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:src="@drawable/taobao_img" />
<EditText

android:id="@+id/ed_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="手机号/会员号/邮箱" />
<EditText

android:id="@+id/ed_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码" />
<LinearLayout

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button

android:id="@+id/login"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#fc7802"
android:text="登录"
android:textColor="#fff" />
<Button

android:id="@+id/regis"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_weight="1"
android:background="#fc7802"
android:text="注册"
android:textColor="#fff" />
</LinearLayout>
</LinearLayout>

activity_regis.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="10dp">
<EditText

android:id="@+id/ed_user"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="手机号/会员号/邮箱" />
<EditText

android:id="@+id/ed_pass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入密码" />
<Button

android:id="@+id/regis"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="注册" />
</LinearLayout>

主页面

public class MainActivity extends AppCompatActivity implements IView {
@BindView(R.id.ed_user)
EditText edUser;
@BindView(R.id.ed_pass)
EditText edPass;
@BindView(R.id.login)
Button login;
@BindView(R.id.regis)
Button regis;
private LoginPresenter loginPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
}
@OnClick({R.id.login, R.id.regis})
public void onViewClicked(View view) {
switch (view.getId()) {
case R.id.login:
loginPresenter = new LoginPresenter(this);
Map<String, String> map = new HashMap<>();
map.put("mobile", edUser.getText().toString().trim());
map.put("password", edPass.getText().toString().trim());
loginPresenter.get("http://120.27.23.105/", map);
break;
case R.id.regis:
startActivity(new Intent(this, RegisActivity.class));
break;
}
}
@Override
public void onSuccess(Object o) {
LoginBean b = (LoginBean) o;
if (b.getMsg() != null) {
Toast.makeText(this, b.getMsg(), Toast.LENGTH_SHORT).show();
}
if (b.getCode().equals("0")) {
// 跳转列表信息
startActivity(new Intent(this, DetailsActivity.class));
}
}
@Override
public void onFailed(Exception e) {
}
@Override
protected void onDestroy() {
super.onDestroy();
if (loginPresenter != null) {
loginPresenter.detatch();
}
}
}

model文件夹:数据层

IModel.java

public interface IModel {
void get(String baseurl, Map<String, String> map);
}

LoginModel.java

public class LoginModel implements IModel {
private LoginPresenter presenter;
public LoginModel(LoginPresenter presenter) {
this.presenter = presenter;
}
@Override
public void get(String baseurl, Map<String, String> map) {
Flowable<LoginBean> flowable = RetrofitUtils.getInstance(baseurl).getretrofit().create(ApiService.class).loginget(map);
presenter.getData(flowable);
}

RegisModel.java

public class RegisModel implements IModel {
private RegisPresenter presenter;
public RegisModel(RegisPresenter presenter) {
this.presenter = presenter;
}
@Override
public void get(String baseurl, Map<String, String> map) {
Flowable<RegisBean> flowable = RetrofitUtils.getInstance(baseurl).getretrofit().create(ApiService.class).regisget(map);
presenter.getData(flowable);
}
}

view文件夹:视图层

IView.java

public interface IView {
void onSuccess(Object o);
void onFailed(Exception e);
}

RegisActivity.java

public class RegisActivity extends AppCompatActivity implements IView {
@BindView(R.id.ed_user)
EditText edUser;
@BindView(R.id.ed_pass)
EditText edPass;
@BindView(R.id.regis)
Button regis;
private RegisPresenter regisPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_regis);
ButterKnife.bind(this);
}
@OnClick(R.id.regis)
public void onViewClicked() {
regisPresenter = new RegisPresenter(this);
Map<String, String> map = new HashMap<>();
map.put("mobile", edUser.getText().toString().trim());
map.put("password", edPass.getText().toString().trim());
regisPresenter.get("http://120.27.23.105/", map);
}
@Override
public void onSuccess(Object o) {
RegisBean b = (RegisBean) o;
Toast.makeText(this, b.getMsg(), Toast.LENGTH_SHORT).show();
}
@Override
public void onFailed(Exception e) {
}
@Override
protected void onDestroy() {
super.onDestroy();
if (regisPresenter != null) {
regisPresenter.detatch();
}
}

persenter文件夹:逻辑层

BasePresenter.java

public interface BasePresenter {
void get(String baseurl, Map<String, String> map);
void get2(String baseurl, Map<String, String> map);
}

LoginPresenter.java

public class LoginPresenter implements BasePresenter {
private IView iv;
private DisposableSubscriber<LoginBean> disposableSubscriber;
public LoginPresenter(IView iv) {
this.iv = iv;
}
@Override
public void get(String baseurl, Map<String, String> map) {
LoginModel model = new LoginModel(this);
model.get(baseurl, map);
}
@Override
public void get2(String baseurl, Map<String, String> map) {
}
public void getData(Flowable<LoginBean> flowable) {
disposableSubscriber = flowable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSubscriber<LoginBean>() {
@Override
public void onNext(LoginBean loginBean) {
iv.onSuccess(loginBean);
}
@Override
public void onError(Throwable t) {
iv.onFailed((Exception) t);
}
@Override
public void onComplete() {
}
});
}
//防止内存泄漏
public void detatch() {
if (iv != null) {
iv = null;
}
if (disposableSubscriber != null) {
if (!disposableSubscriber.isDisposed()) {
disposableSubscriber.dispose();
}
}
}
}

RegisPresenter.java

public class RegisPresenter implements BasePresenter {
private IView iv;
private DisposableSubscriber<LoginBean> disposableSubscriber;
public RegisPresenter(IView iv) {
this.iv = iv;
}
@Override
public void get(String baseurl, Map<String, String> map) {
RegisModel model = new RegisModel(this);
model.get(baseurl, map);
}
@Override
public void get2(String baseurl, Map<String, String> map) {
}
public void getData(Flowable<RegisBean> flowable) {
flowable.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSubscriber<RegisBean>() {
@Override
public void onNext(RegisBean regisBean) {
iv.onSuccess(regisBean);
}
@Override
public void onError(Throwable t) {
iv.onFailed((Exception) t);
}
@Override
public void onComplete() {
}
});
}
//防止内存泄漏
public void detatch() {
if (iv != null) {
iv = null;
}
if (disposableSubscriber != null) {
if (!disposableSubscriber.isDisposed()) {
disposableSubscriber.dispose();
}
}
}
}

最后

以上就是受伤枫叶为你收集整理的Android - 原生登录注册页面【仿】淘宝Appbean文件夹:解析数据图片文件xml文件model文件夹:数据层view文件夹:视图层persenter文件夹:逻辑层的全部内容,希望文章能够帮你解决Android - 原生登录注册页面【仿】淘宝Appbean文件夹:解析数据图片文件xml文件model文件夹:数据层view文件夹:视图层persenter文件夹:逻辑层所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(38)

评论列表共有 0 条评论

立即
投稿
返回
顶部