Browse Source

对接手机号注册

316044749 7 years ago
parent
commit
3e80070d08

+ 32 - 4
app/src/main/java/com/ynstkz/shitu/android/activity/RegisterActivity.java

@@ -1,8 +1,11 @@
 package com.ynstkz.shitu.android.activity;
 
+import android.annotation.SuppressLint;
 import android.content.Intent;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
 import android.support.annotation.Nullable;
 import android.text.TextUtils;
 import android.view.View;
@@ -31,6 +34,7 @@ import butterknife.Bind;
 
 public class RegisterActivity extends TitleBarActivity implements VerifyCodeCallback, CheckVerifyCodeCallback{
 
+
     @Bind(R.id.iv_cancel)
     ImageView ivCancel;
     @Bind(R.id.tv_login)
@@ -47,6 +51,7 @@ public class RegisterActivity extends TitleBarActivity implements VerifyCodeCall
     String phoneNumber;
     private String thirdId;
     private String thirdType;
+    private int time_interval = 60;
 
     @Override
     protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -121,6 +126,29 @@ public class RegisterActivity extends TitleBarActivity implements VerifyCodeCall
         });
     }
 
+    @SuppressLint("HandlerLeak")
+    Handler handler = new Handler(){
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what){
+                case 1:
+                    if(time_interval > 0){
+                        tvVerifycode.setClickable(false);
+                        tvVerifycode.setText(time_interval + "s后重新获取");
+                        tvVerifycode.setTextColor(getResources().getColor(R.color.color_999));
+                        time_interval --;
+                        handler.sendEmptyMessageDelayed(1, 1000);
+                    } else {
+                        tvVerifycode.setClickable(true);
+                        tvVerifycode.setText("获取手机验证码");
+                        tvVerifycode.setTextColor(getResources().getColor(R.color.main_color));
+                        time_interval = 60;
+                    }
+                    break;
+            }
+        }
+    };
+
     /**
      * 下一步
      * @param phoneNumber
@@ -136,15 +164,15 @@ public class RegisterActivity extends TitleBarActivity implements VerifyCodeCall
     }
 
     @Override
-    public void codeCallback(int type, String verifyCode) {
-        if(type == 1){
-
+    public void codeCallback(int type) {
+        if(type == 1){ //注册
+            handler.sendEmptyMessage(1);
         }
     }
 
     @Override
     public void isVerifyCodeSuccess(int type, String phoneNumber, boolean isSuccess) {
-        if(isSuccess){
+        if(type == 1 && isSuccess){
             nextEvent(phoneNumber);
         }
     }

+ 24 - 8
app/src/main/java/com/ynstkz/shitu/android/application/STSign.java

@@ -9,11 +9,14 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.TextView;
+import android.widget.Toast;
 
 import com.common.library.cache.Cache;
 import com.common.library.okhttp.callback.Callback;
 import com.common.library.utils.PixelUtil;
+import com.google.gson.Gson;
 import com.ynstkz.shitu.android.R;
+import com.ynstkz.shitu.android.base.BaseBean;
 import com.ynstkz.shitu.android.bean.UserInfoBean;
 import com.ynstkz.shitu.android.common.Constants;
 import com.ynstkz.shitu.android.data.RequestGroup;
@@ -68,18 +71,24 @@ public class STSign {
         RequestGroup.snedSms(String.valueOf(type), phoneNumber, new Callback() {
             @Override
             public Object parseNetworkResponse(Response response, int id) throws Exception {
-                return null;
+                return new Gson().fromJson(response.body().string(), BaseBean.class);
             }
 
             @Override
             public void onError(Call call, Exception e, int id) {
-
+                Toast.makeText(STApplication.getContext(), "发送失败!", Toast.LENGTH_SHORT).show();
             }
 
             @Override
             public void onResponse(Object response, int id) {
-                if(callback != null){
-                    callback.codeCallback(type, "123456");
+                BaseBean baseBean = (BaseBean)response;
+                if(baseBean != null){
+                    if("200".equals(baseBean.getCode())){
+                        if(callback != null){
+                            callback.codeCallback(type);
+                        }
+                    }
+                    Toast.makeText(STApplication.getContext(), baseBean.getMsg(), Toast.LENGTH_SHORT).show();
                 }
             }
         });
@@ -95,21 +104,28 @@ public class STSign {
         RequestGroup.verifySms(String.valueOf(type), phoneNumber, code, new Callback() {
             @Override
             public Object parseNetworkResponse(Response response, int id) throws Exception {
-                return null;
+                return new Gson().fromJson(response.body().string(), BaseBean.class);
             }
 
             @Override
             public void onError(Call call, Exception e, int id) {
                 if(callback != null){
-                    callback.isVerifyCodeSuccess(type, phoneNumber, true);
+                    callback.isVerifyCodeSuccess(type, phoneNumber, false);
                 }
             }
 
             @Override
             public void onResponse(Object response, int id) {
-                if(callback != null){
-                    callback.isVerifyCodeSuccess(type, phoneNumber, true);
+                BaseBean baseBean = (BaseBean)response;
+                if(baseBean != null){
+                    if("200".equals(baseBean.getCode())){
+                        if(callback != null){
+                            callback.isVerifyCodeSuccess(type, phoneNumber, true);
+                        }
+                    }
+                    Toast.makeText(STApplication.getContext(), baseBean.getMsg(), Toast.LENGTH_SHORT).show();
                 }
+
             }
         });
     }

+ 1 - 1
app/src/main/java/com/ynstkz/shitu/android/listener/VerifyCodeCallback.java

@@ -6,5 +6,5 @@ package com.ynstkz.shitu.android.listener;
 
 public interface VerifyCodeCallback {
 
-    void codeCallback(int type, String verifyCode);
+    void codeCallback(int type);
 }

+ 1 - 1
library/src/main/java/com/common/library/okhttp/request/OtherRequest.java

@@ -16,7 +16,7 @@ import okhttp3.internal.http.HttpMethod;
  */
 public class OtherRequest extends OkHttpRequest
 {
-    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("text/plain;charset=utf-8");
+    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("application/json;charset=utf-8");
 
     private RequestBody requestBody;
     private String method;

+ 2 - 1
library/src/main/java/com/common/library/okhttp/request/PostStringRequest.java

@@ -12,7 +12,8 @@ import okhttp3.RequestBody;
  */
 public class PostStringRequest extends OkHttpRequest
 {
-    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("text/plain;charset=utf-8");
+//    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("text/plain;charset=utf-8");
+    private static MediaType MEDIA_TYPE_PLAIN = MediaType.parse("application/json;charset=utf-8");
 
     private String content;
     private MediaType mediaType;