Commit d8b159ee40c69d21ddb22d81478328e1a529d644

Authored by 姚旭斌
1 parent 6684682d

no message

app/src/main/java/com/shunzhi/parent/contract/loginandregister/LoginAndRegisterContract.java
1 package com.shunzhi.parent.contract.loginandregister; 1 package com.shunzhi.parent.contract.loginandregister;
2 2
  3 +import com.google.gson.JsonObject;
3 import com.share.mvpsdk.base.BasePresenter; 4 import com.share.mvpsdk.base.BasePresenter;
4 import com.share.mvpsdk.base.IBaseFragment; 5 import com.share.mvpsdk.base.IBaseFragment;
5 import com.share.mvpsdk.base.IBaseModel; 6 import com.share.mvpsdk.base.IBaseModel;
6 7
  8 +import io.reactivex.Observable;
  9 +
7 /** 10 /**
8 * Created by Administrator on 2018/3/6 0006. 11 * Created by Administrator on 2018/3/6 0006.
9 */ 12 */
@@ -13,11 +16,22 @@ public interface LoginAndRegisterContract { @@ -13,11 +16,22 @@ public interface LoginAndRegisterContract {
13 abstract class LoginPresenter extends BasePresenter<ILoginModel,ILoginView>{ 16 abstract class LoginPresenter extends BasePresenter<ILoginModel,ILoginView>{
14 public abstract void loginResult(String loginName,String loginPwd); 17 public abstract void loginResult(String loginName,String loginPwd);
15 18
  19 + public abstract void registerResult(String adminName,String idCode,String password);
  20 +
  21 + public abstract void idCodeResult(String phoneNumber);
  22 +
16 public abstract void getUserInfo(); 23 public abstract void getUserInfo();
17 } 24 }
18 25
19 interface ILoginModel extends IBaseModel{ 26 interface ILoginModel extends IBaseModel{
  27 + Observable<JsonObject> getLoginResult(String loginName, String loginPed);
  28 +
  29 + Observable<JsonObject> getRegisterResult(String adminName,String idCode,String password);
  30 +
  31 + Observable<JsonObject> getidCodeResult(String phoneNumber);
20 32
  33 + //获取登录用户信息
  34 +// Observable<CurrentBean> getUserInfo();
21 } 35 }
22 interface ILoginView extends IBaseFragment { 36 interface ILoginView extends IBaseFragment {
23 37
app/src/main/java/com/shunzhi/parent/model/loginandregister/LoginAndRegisterModel.java 0 → 100644
@@ -0,0 +1,37 @@ @@ -0,0 +1,37 @@
  1 +package com.shunzhi.parent.model.loginandregister;
  2 +
  3 +import com.google.gson.JsonObject;
  4 +import com.share.mvpsdk.base.BaseModel;
  5 +import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract;
  6 +
  7 +import io.reactivex.Observable;
  8 +
  9 +/**
  10 + * Created by Administrator on 2018/3/6 0006.
  11 + */
  12 +
  13 +public class LoginAndRegisterModel extends BaseModel implements LoginAndRegisterContract.ILoginModel {
  14 +
  15 +
  16 +
  17 + public static LoginAndRegisterModel newInstance() {
  18 + return new LoginAndRegisterModel();
  19 + }
  20 +
  21 +
  22 + @Override
  23 + public Observable<JsonObject> getLoginResult(String loginName, String loginPed) {
  24 + return null;
  25 + }
  26 +
  27 + @Override
  28 + public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) {
  29 + return null;
  30 + }
  31 +
  32 + @Override
  33 + public Observable<JsonObject> getidCodeResult(String phoneNumber) {
  34 + return null;
  35 + }
  36 +
  37 +}
app/src/main/java/com/shunzhi/parent/model/loginandregister/loginAndRegisterModel.java
1 package com.shunzhi.parent.model.loginandregister; 1 package com.shunzhi.parent.model.loginandregister;
2 2
  3 +import com.google.gson.JsonObject;
3 import com.share.mvpsdk.base.BaseModel; 4 import com.share.mvpsdk.base.BaseModel;
  5 +import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract;
  6 +
  7 +import io.reactivex.Observable;
4 8
5 /** 9 /**
6 * Created by Administrator on 2018/3/6 0006. 10 * Created by Administrator on 2018/3/6 0006.
7 */ 11 */
8 12
9 -public class loginAndRegisterModel extends BaseModel { 13 +public class LoginAndRegisterModel extends BaseModel implements LoginAndRegisterContract.ILoginModel {
  14 +
  15 +
  16 +
  17 + public static LoginAndRegisterModel newInstance() {
  18 + return new LoginAndRegisterModel();
  19 + }
  20 +
  21 +
  22 + @Override
  23 + public Observable<JsonObject> getLoginResult(String loginName, String loginPed) {
  24 + return null;
  25 + }
  26 +
  27 + @Override
  28 + public Observable<JsonObject> getRegisterResult(String adminName, String idCode, String password) {
  29 + return null;
  30 + }
  31 +
  32 + @Override
  33 + public Observable<JsonObject> getidCodeResult(String phoneNumber) {
  34 + return null;
  35 + }
  36 +
10 } 37 }
app/src/main/java/com/shunzhi/parent/presenter/loginandregister/LoginAndRegisterPresenter.java
1 package com.shunzhi.parent.presenter.loginandregister; 1 package com.shunzhi.parent.presenter.loginandregister;
2 2
  3 +import android.text.TextUtils;
  4 +
  5 +import com.share.mvpsdk.utils.ToastUtils;
3 import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; 6 import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract;
  7 +import com.shunzhi.parent.model.loginandregister.LoginAndRegisterModel;
4 8
5 /** 9 /**
6 * Created by Administrator on 2018/3/6 0006. 10 * Created by Administrator on 2018/3/6 0006.
@@ -9,17 +13,39 @@ import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; @@ -9,17 +13,39 @@ import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract;
9 public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPresenter { 13 public class LoginAndRegisterPresenter extends LoginAndRegisterContract.LoginPresenter {
10 @Override 14 @Override
11 public void loginResult(String loginName, String loginPwd) { 15 public void loginResult(String loginName, String loginPwd) {
  16 + if (TextUtils.isEmpty(loginName)){
  17 + ToastUtils.showToast("登录名不能为空");
  18 + return;
  19 + }else if(TextUtils.isEmpty(loginPwd)){
  20 + ToastUtils.showToast("密码不能为空");
  21 + return;
  22 + }
  23 +
  24 + }
  25 +
  26 + @Override
  27 + public void registerResult(String adminName, String idCode, String password) {
  28 +
12 29
13 } 30 }
14 31
15 @Override 32 @Override
  33 + public void idCodeResult(String phoneNumber) {
  34 + if(TextUtils.isEmpty(phoneNumber)){
  35 + ToastUtils.showToast("请先输入手机号");
  36 + return;
  37 + }
  38 + }
  39 +
  40 + @Override
16 public void getUserInfo() { 41 public void getUserInfo() {
17 42
18 } 43 }
19 44
  45 +
20 @Override 46 @Override
21 public LoginAndRegisterContract.ILoginModel getModel() { 47 public LoginAndRegisterContract.ILoginModel getModel() {
22 - return null; 48 + return LoginAndRegisterModel.newInstance();
23 } 49 }
24 50
25 @Override 51 @Override
app/src/main/java/com/shunzhi/parent/ui/activity/LoginAndRegistActivity.java
@@ -9,15 +9,19 @@ import com.shunzhi.parent.ui.fragment.loginandregistfragment.LoginAndRegistFragm @@ -9,15 +9,19 @@ import com.shunzhi.parent.ui.fragment.loginandregistfragment.LoginAndRegistFragm
9 import me.yokeyword.fragmentation.SupportFragment; 9 import me.yokeyword.fragmentation.SupportFragment;
10 10
11 public class LoginAndRegistActivity extends BaseCompatActivity { 11 public class LoginAndRegistActivity extends BaseCompatActivity {
  12 + String type = "注册";
  13 +
12 14
13 private SupportFragment[] mFragments = new SupportFragment[1]; 15 private SupportFragment[] mFragments = new SupportFragment[1];
  16 +
14 @Override 17 @Override
15 protected void initView(Bundle savedInstanceState) { 18 protected void initView(Bundle savedInstanceState) {
16 - if (savedInstanceState==null){  
17 - mFragments[0]= LoginAndRegistFragment.getInstance();  
18 - loadRootFragment(R.id.frame,mFragments[0]);  
19 - }else {  
20 - mFragments[0]=findFragment(LoginAndRegistFragment.class); 19 + if (savedInstanceState == null) {
  20 + type = getIntent().getStringExtra("type");
  21 + mFragments[0] = LoginAndRegistFragment.getInstance(type);
  22 + loadRootFragment(R.id.frame, mFragments[0]);
  23 + } else {
  24 + mFragments[0] = findFragment(LoginAndRegistFragment.class);
21 } 25 }
22 } 26 }
23 27
app/src/main/java/com/shunzhi/parent/ui/fragment/loginandregistfragment/LoginAndRegistFragment.java
@@ -4,7 +4,11 @@ import android.os.Bundle; @@ -4,7 +4,11 @@ import android.os.Bundle;
4 import android.support.annotation.NonNull; 4 import android.support.annotation.NonNull;
5 import android.support.annotation.Nullable; 5 import android.support.annotation.Nullable;
6 import android.view.View; 6 import android.view.View;
  7 +import android.widget.EditText;
  8 +import android.widget.LinearLayout;
  9 +import android.widget.TextView;
7 10
  11 +import com.makeramen.roundedimageview.RoundedImageView;
8 import com.share.mvpsdk.base.BasePresenter; 12 import com.share.mvpsdk.base.BasePresenter;
9 import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment; 13 import com.share.mvpsdk.base.fragment.BaseMVPCompatFragment;
10 import com.shunzhi.parent.R; 14 import com.shunzhi.parent.R;
@@ -12,12 +16,19 @@ import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract; @@ -12,12 +16,19 @@ import com.shunzhi.parent.contract.loginandregister.LoginAndRegisterContract;
12 import com.shunzhi.parent.presenter.loginandregister.LoginAndRegisterPresenter; 16 import com.shunzhi.parent.presenter.loginandregister.LoginAndRegisterPresenter;
13 17
14 18
15 -public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegisterContract.LoginPresenter,LoginAndRegisterContract.ILoginModel>  
16 -implements LoginAndRegisterContract.ILoginView{ 19 +public class LoginAndRegistFragment extends BaseMVPCompatFragment<LoginAndRegisterContract.LoginPresenter, LoginAndRegisterContract.ILoginModel>
  20 + implements LoginAndRegisterContract.ILoginView, View.OnClickListener {
17 21
  22 + public RoundedImageView roundedImageView;
  23 + public EditText phoneNumber, idCode, password;
  24 + public TextView get_idCode, loginAndRegister, tv_info, tv_goto;
  25 + public LinearLayout phoneLayout, idCodeLayout, passwordLayout;
  26 + public static String typepage;
18 27
19 - public static LoginAndRegistFragment getInstance(){  
20 - LoginAndRegistFragment loginFragment=new LoginAndRegistFragment(); 28 +
  29 + public static LoginAndRegistFragment getInstance(String type) {
  30 + typepage = type;
  31 + LoginAndRegistFragment loginFragment = new LoginAndRegistFragment();
21 return loginFragment; 32 return loginFragment;
22 } 33 }
23 34
@@ -36,12 +47,56 @@ implements LoginAndRegisterContract.ILoginView{ @@ -36,12 +47,56 @@ implements LoginAndRegisterContract.ILoginView{
36 @Override 47 @Override
37 public void initUI(View view, @Nullable Bundle savedInstanceState) { 48 public void initUI(View view, @Nullable Bundle savedInstanceState) {
38 49
  50 + roundedImageView = view.findViewById(R.id.photoImage);
  51 + phoneNumber = view.findViewById(R.id.et_phoneNumber);
  52 + idCode = view.findViewById(R.id.et_idCode);
  53 + password = view.findViewById(R.id.et_password);
  54 + get_idCode = view.findViewById(R.id.get_idCode);
  55 + loginAndRegister = view.findViewById(R.id.loginAndRegister);
  56 + tv_info = view.findViewById(R.id.tv_info);
  57 + tv_goto = view.findViewById(R.id.tv_goto);
  58 + phoneLayout = view.findViewById(R.id.phoneLayout);
  59 + idCodeLayout = view.findViewById(R.id.idCodeLayout);
  60 + passwordLayout = view.findViewById(R.id.passwordLayout);
  61 + get_idCode.setOnClickListener(this);
  62 + tv_goto.setOnClickListener(this);
  63 + loginAndRegister.setOnClickListener(this);
  64 + if (typepage.equals("登录")) {
  65 + idCodeLayout.setVisibility(View.GONE);
  66 + loginAndRegister.setText("登录");
  67 + tv_info.setText("还没有账号");
  68 + tv_goto.setText("注册");
  69 + }else if(typepage.equals("注册")){
  70 + idCodeLayout.setVisibility(View.VISIBLE);
  71 + loginAndRegister.setText("注册");
  72 + tv_info.setText("已注册,直接登录");
  73 + tv_goto.setText("登录");
  74 + }
39 } 75 }
40 76
41 77
42 -  
43 @Override 78 @Override
44 public void getUserInfo() { 79 public void getUserInfo() {
45 80
46 } 81 }
  82 +
  83 + @Override
  84 + public void onClick(View v) {
  85 + if (v == loginAndRegister) {
  86 + if (loginAndRegister.getText().toString().trim().equals("登录")) {
  87 + mPresenter.loginResult(phoneNumber.getText().toString(), password.getText().toString());
  88 + } else if (loginAndRegister.getText().toString().trim().equals("注册")) {
  89 + mPresenter.registerResult(phoneNumber.getText().toString(), idCode.getText().toString(), password.getText().toString());
  90 + }
  91 +
  92 + } else if (v == tv_goto) {
  93 + if (tv_goto.equals("登录")) {
  94 +
  95 + } else if (tv_goto.equals("注册")) {
  96 +
  97 + }
  98 + } else if (v == get_idCode) {
  99 + mPresenter.idCodeResult(phoneNumber.getText().toString());
  100 + }
  101 + }
47 } 102 }
app/src/main/res/layout/fragment_login_and_regist.xml
@@ -12,6 +12,7 @@ @@ -12,6 +12,7 @@
12 android:orientation="vertical"> 12 android:orientation="vertical">
13 13
14 <com.makeramen.roundedimageview.RoundedImageView 14 <com.makeramen.roundedimageview.RoundedImageView
  15 + android:id="@+id/photoImage"
15 android:layout_width="80dp" 16 android:layout_width="80dp"
16 android:layout_height="80dp" 17 android:layout_height="80dp"
17 android:layout_gravity="center" 18 android:layout_gravity="center"
@@ -31,11 +32,13 @@ @@ -31,11 +32,13 @@
31 android:orientation="vertical"> 32 android:orientation="vertical">
32 33
33 <LinearLayout 34 <LinearLayout
  35 + android:id="@+id/phoneLayout"
34 android:layout_width="match_parent" 36 android:layout_width="match_parent"
35 android:layout_height="wrap_content" 37 android:layout_height="wrap_content"
36 android:orientation="vertical"> 38 android:orientation="vertical">
37 39
38 <EditText 40 <EditText
  41 + android:id="@+id/et_phoneNumber"
39 android:layout_width="match_parent" 42 android:layout_width="match_parent"
40 android:layout_height="50dp" 43 android:layout_height="50dp"
41 android:background="@null" 44 android:background="@null"
@@ -50,6 +53,7 @@ @@ -50,6 +53,7 @@
50 </LinearLayout> 53 </LinearLayout>
51 54
52 <LinearLayout 55 <LinearLayout
  56 + android:id="@+id/idCodeLayout"
53 android:layout_width="match_parent" 57 android:layout_width="match_parent"
54 android:layout_height="wrap_content" 58 android:layout_height="wrap_content"
55 android:orientation="vertical"> 59 android:orientation="vertical">
@@ -60,6 +64,7 @@ @@ -60,6 +64,7 @@
60 android:orientation="horizontal"> 64 android:orientation="horizontal">
61 65
62 <EditText 66 <EditText
  67 + android:id="@+id/et_idCode"
63 android:layout_width="wrap_content" 68 android:layout_width="wrap_content"
64 android:layout_height="50dp" 69 android:layout_height="50dp"
65 android:layout_weight="1" 70 android:layout_weight="1"
@@ -69,6 +74,7 @@ @@ -69,6 +74,7 @@
69 android:textSize="@dimen/sp_16" /> 74 android:textSize="@dimen/sp_16" />
70 75
71 <TextView 76 <TextView
  77 + android:id="@+id/get_idCode"
72 android:layout_width="wrap_content" 78 android:layout_width="wrap_content"
73 android:layout_height="wrap_content" 79 android:layout_height="wrap_content"
74 android:background="@drawable/rudiobtn2" 80 android:background="@drawable/rudiobtn2"
@@ -92,6 +98,7 @@ @@ -92,6 +98,7 @@
92 </LinearLayout> 98 </LinearLayout>
93 99
94 <LinearLayout 100 <LinearLayout
  101 + android:id="@+id/passwordLayout"
95 android:layout_width="match_parent" 102 android:layout_width="match_parent"
96 android:layout_height="wrap_content" 103 android:layout_height="wrap_content"
97 android:orientation="vertical"> 104 android:orientation="vertical">
@@ -101,6 +108,7 @@ @@ -101,6 +108,7 @@
101 android:layout_height="wrap_content"> 108 android:layout_height="wrap_content">
102 109
103 <EditText 110 <EditText
  111 + android:id="@+id/et_password"
104 android:layout_width="wrap_content" 112 android:layout_width="wrap_content"
105 android:layout_height="50dp" 113 android:layout_height="50dp"
106 android:layout_weight="1" 114 android:layout_weight="1"
@@ -110,6 +118,7 @@ @@ -110,6 +118,7 @@
110 android:textSize="@dimen/sp_16" /> 118 android:textSize="@dimen/sp_16" />
111 119
112 <ImageView 120 <ImageView
  121 + android:id="@+id/img_eye"
113 android:layout_width="wrap_content" 122 android:layout_width="wrap_content"
114 android:layout_height="match_parent" 123 android:layout_height="match_parent"
115 android:layout_gravity="center" 124 android:layout_gravity="center"
@@ -126,6 +135,7 @@ @@ -126,6 +135,7 @@
126 </LinearLayout> 135 </LinearLayout>
127 136
128 <TextView 137 <TextView
  138 + android:id="@+id/loginAndRegister"
129 android:layout_width="match_parent" 139 android:layout_width="match_parent"
130 android:layout_height="wrap_content" 140 android:layout_height="wrap_content"
131 android:layout_marginTop="40dp" 141 android:layout_marginTop="40dp"
@@ -145,6 +155,7 @@ @@ -145,6 +155,7 @@
145 android:orientation="horizontal"> 155 android:orientation="horizontal">
146 156
147 <TextView 157 <TextView
  158 + android:id="@+id/tv_info"
148 android:layout_width="wrap_content" 159 android:layout_width="wrap_content"
149 android:layout_height="wrap_content" 160 android:layout_height="wrap_content"
150 android:text="已注册,直接登录" 161 android:text="已注册,直接登录"
@@ -152,6 +163,7 @@ @@ -152,6 +163,7 @@
152 android:textSize="@dimen/sp_16" /> 163 android:textSize="@dimen/sp_16" />
153 164
154 <TextView 165 <TextView
  166 + android:id="@+id/tv_goto"
155 android:layout_width="wrap_content" 167 android:layout_width="wrap_content"
156 android:layout_height="wrap_content" 168 android:layout_height="wrap_content"
157 android:layout_marginLeft="20dp" 169 android:layout_marginLeft="20dp"