|
|
@@ -0,0 +1,211 @@
|
|
|
+package com.sheep.jiuyan.samllsheep.page;
|
|
|
+
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Handler;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.View;
|
|
|
+import android.widget.Button;
|
|
|
+import android.widget.EditText;
|
|
|
+import android.widget.TextView;
|
|
|
+import android.widget.Toast;
|
|
|
+
|
|
|
+import com.sheep.jiuyan.samllsheep.R;
|
|
|
+import com.sheep.jiuyan.samllsheep.base.BaseActivity;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.NetManager;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.SheepCallback;
|
|
|
+import com.sheep.jiuyan.samllsheep.net.Url;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.StringUtils;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.TitleBarUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Administrator on 2018/2/23.
|
|
|
+ */
|
|
|
+
|
|
|
+public class BindPhoneActivity extends BaseActivity implements View.OnClickListener{
|
|
|
+
|
|
|
+ EditText et_phone;
|
|
|
+ EditText et_code;
|
|
|
+ Button btn;
|
|
|
+ TextView tv;
|
|
|
+ int mTime = 0;
|
|
|
+ Handler handler = new Handler();
|
|
|
+ Runnable runnable = new Runnable() {
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ mTime--;
|
|
|
+ if (mTime <= 0) {
|
|
|
+ tv.setText("重新发送");
|
|
|
+ tv.setEnabled(true);
|
|
|
+ } else {
|
|
|
+ tv.setText("重新发送(" + mTime + ")");
|
|
|
+ handler.postDelayed(this, 1000);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected int getLayoutId() {
|
|
|
+ return R.layout.activity_bind_phone;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initView() {
|
|
|
+ et_phone=(EditText)findViewById(R.id.et_phone);
|
|
|
+ et_code=(EditText)findViewById(R.id.et_code);
|
|
|
+ btn=(Button)findViewById(R.id.btn);
|
|
|
+ tv=(TextView)findViewById(R.id.tv);
|
|
|
+ TitleBarUtils.getInstance()
|
|
|
+ .setTitle(this, "绑定手机号")
|
|
|
+ .setTitleFinish(this);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initListener() {
|
|
|
+ btn.setOnClickListener(this);
|
|
|
+ tv.setOnClickListener(this);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void initData() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onClick(View view) {
|
|
|
+ switch (view.getId()){
|
|
|
+ case R.id.btn:
|
|
|
+ bindPhone();
|
|
|
+ break;
|
|
|
+ case R.id.tv:
|
|
|
+ sendCode();
|
|
|
+ break;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkLoginIsOverdue(){
|
|
|
+ if(TextUtils.isEmpty(SpUtils.getAppToken(BindPhoneActivity.this))){
|
|
|
+ SpUtils.login(this,"");
|
|
|
+ SpUtils.saveAppToken(this,"");
|
|
|
+ Toast.makeText(this,"登录已过期!请重新登录...",Toast.LENGTH_LONG).show();
|
|
|
+ Intent i=new Intent(this,LoginActivity.class);
|
|
|
+ startActivity(i);
|
|
|
+ finish();
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void sendCode(){
|
|
|
+ checkLoginIsOverdue();
|
|
|
+ tv.setEnabled(false);
|
|
|
+ String moble = et_phone.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(moble)) {
|
|
|
+ et_phone.setError("请输入手机号");
|
|
|
+ tv.setEnabled(true);
|
|
|
+
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(!StringUtils.checkMobileNum(moble)){
|
|
|
+ et_phone.setError("请填写正确的手机号码");
|
|
|
+ tv.setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("Mobile", moble);
|
|
|
+ map.put("Step", "1");
|
|
|
+ map.put("Token", SpUtils.getAppToken(BindPhoneActivity.this));
|
|
|
+ showProgress();
|
|
|
+ NetManager.post(Url.BINDUSER, map, getApplicationContext(), new SheepCallback<String>(BindPhoneActivity.this) {
|
|
|
+ @Override
|
|
|
+ public void success(String o) {
|
|
|
+ hideProgress();
|
|
|
+ Toast.makeText(BindPhoneActivity.this, "验证码已发送", Toast.LENGTH_SHORT).show();
|
|
|
+ mTime = 60;
|
|
|
+ handler.postDelayed(runnable, 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void failure(IOException e) {
|
|
|
+ hideProgress();
|
|
|
+ tv.setEnabled(true);
|
|
|
+ String message = e.getMessage();
|
|
|
+ if (message.contains("参数错误")) {
|
|
|
+ message = message.replace("参数错误", "");
|
|
|
+ }
|
|
|
+ message = message.trim();
|
|
|
+ Toast.makeText(BindPhoneActivity.this, message, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void bindPhone(){
|
|
|
+ checkLoginIsOverdue();
|
|
|
+ btn.setEnabled(false);
|
|
|
+ String moble = et_phone.getText().toString().trim();
|
|
|
+ String code = et_code.getText().toString().trim();
|
|
|
+ if (TextUtils.isEmpty(moble)) {
|
|
|
+ btn.setEnabled(true);
|
|
|
+ et_phone.setError("请输入手机号");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(!StringUtils.checkMobileNum(moble)){
|
|
|
+ et_phone.setError("请填写正确的手机号码");
|
|
|
+ btn.setEnabled(true);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(code)) {
|
|
|
+ btn.setEnabled(true);
|
|
|
+ et_code.setError("请输入验证码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (code.length()!=6) {
|
|
|
+ btn.setEnabled(true);
|
|
|
+ et_code.setError("请填写6位手机验证码");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ showProgress();
|
|
|
+ HashMap<String, String> map = new HashMap<>();
|
|
|
+ map.put("Mobile", moble);
|
|
|
+ map.put("Step", "2");
|
|
|
+ map.put("Seccode", code);
|
|
|
+ map.put("Token", SpUtils.getAppToken(BindPhoneActivity.this));
|
|
|
+ NetManager.post(Url.BINDUSER, map, getApplicationContext(), new SheepCallback<String>(BindPhoneActivity.this) {
|
|
|
+ @Override
|
|
|
+ public void success(String o) {
|
|
|
+ hideProgress();
|
|
|
+ Toast.makeText(BindPhoneActivity.this,"绑定手机号成功",Toast.LENGTH_LONG).show();
|
|
|
+ finish();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void failure(IOException e) {
|
|
|
+ hideProgress();
|
|
|
+ btn.setEnabled(true);
|
|
|
+ String message = e.getMessage();
|
|
|
+ if (message.contains("参数错误")) {
|
|
|
+ message = message.replace("参数错误", "");
|
|
|
+ }
|
|
|
+ message = message.trim();
|
|
|
+ Toast.makeText(BindPhoneActivity.this, message, Toast.LENGTH_SHORT).show();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|