d
This commit is contained in:
@@ -0,0 +1,132 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
||||
import com.fenghoo.seven.main.activity.common.databus.RxBus;
|
||||
import com.fenghoo.seven.main.activity.common.http.IHttpClient;
|
||||
import com.fenghoo.seven.main.activity.common.http.IRequest;
|
||||
import com.fenghoo.seven.main.activity.common.http.IResponse;
|
||||
import com.fenghoo.seven.main.activity.common.http.api.API;
|
||||
import com.fenghoo.seven.main.activity.common.http.impl.BaseRequest;
|
||||
import com.fenghoo.seven.main.activity.common.http.impl.BaseResponse;
|
||||
import com.fenghoo.seven.main.activity.common.storage.SharedPreferencesDao;
|
||||
import com.fenghoo.seven.main.activity.common.util.LogUtil;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import rx.functions.Func1;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/13.
|
||||
*/
|
||||
|
||||
public class AccountManagerImpl implements IAccountManager {
|
||||
private static final String TAG = "AccountManagerImpl";
|
||||
|
||||
|
||||
// 网络请求库
|
||||
private IHttpClient httpClient;
|
||||
// 数据存储
|
||||
private SharedPreferencesDao sharedPreferencesDao;
|
||||
// 发送消息 handler
|
||||
private Handler handler;
|
||||
|
||||
public AccountManagerImpl(IHttpClient httpClient,
|
||||
SharedPreferencesDao sharedPreferencesDao) {
|
||||
this.httpClient = httpClient;
|
||||
this.sharedPreferencesDao = sharedPreferencesDao;
|
||||
}
|
||||
|
||||
|
||||
/* @Override
|
||||
public void setHandler(Handler handler) {
|
||||
this.handler = handler;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
*
|
||||
* @param phone
|
||||
*/
|
||||
@Override
|
||||
public void fetchSMSCode(final String phone) {
|
||||
|
||||
|
||||
RxBus.getInstance().chainProcess(new Func1() {
|
||||
@Override
|
||||
public Object call(Object o) {
|
||||
|
||||
String url = API.Config.getDomain() + API.GET_SMS_CODE;
|
||||
IRequest request = new BaseRequest(url);
|
||||
request.setBody("phone", phone);
|
||||
IResponse response = httpClient.get(request, false);
|
||||
Log.d(TAG, response.getData());
|
||||
SmsCodeResponse smsCodeResponse = new SmsCodeResponse();
|
||||
LogUtil.d(TAG, response.getData());
|
||||
if (response.getCode() == BaseResponse.STATE_OK) {
|
||||
BaseBizResponse bizRes = new Gson().fromJson(response.getData(), BaseBizResponse.class);
|
||||
smsCodeResponse.setResult(bizRes.getResult());
|
||||
if (bizRes.getStatus() == BaseBizResponse.STATE_OK) {
|
||||
if(bizRes.getResult().getSuccess()==0){
|
||||
smsCodeResponse.setStatus(SMS_SEND_SUC);
|
||||
}else {
|
||||
// smsCodeResponse.setStatus(SMS_SEND_FAIL);
|
||||
smsCodeResponse.setStatus(SMS_SEND_SUC);
|
||||
}
|
||||
} else {
|
||||
smsCodeResponse.setStatus(SMS_SEND_FAIL);
|
||||
}
|
||||
} else {
|
||||
smsCodeResponse.setStatus(SMS_SEND_FAIL);
|
||||
}
|
||||
return smsCodeResponse;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验验证码
|
||||
*
|
||||
* @param phone
|
||||
* @param smsCode
|
||||
*/
|
||||
@Override
|
||||
public void checkSmsCode(final String phone, final String smsCode) {
|
||||
RxBus.getInstance().chainProcess(new Func1() {
|
||||
@Override
|
||||
public Object call(Object o) {
|
||||
|
||||
String url = API.Config.getDomain() + API.CHECK_SMS_CODE;
|
||||
IRequest request = new BaseRequest(url);
|
||||
request.setBody("phone", phone);
|
||||
request.setBody("code", smsCode);
|
||||
IResponse response = httpClient.get(request, false);
|
||||
Log.d(TAG, response.getData());
|
||||
SmsCodeResponse smsCodeResponse = new SmsCodeResponse();
|
||||
|
||||
if (response.getCode() == BaseResponse.STATE_OK) {
|
||||
BaseBizResponse bizRes =
|
||||
new Gson().fromJson(response.getData(), BaseBizResponse.class);
|
||||
smsCodeResponse.setResult(bizRes.getResult());
|
||||
//没有数据,暂时没往下做
|
||||
|
||||
if (bizRes.getStatus() == BaseBizResponse.STATE_OK) {
|
||||
|
||||
if(bizRes.getResult().getSuccess()==0){
|
||||
smsCodeResponse.setStatus(SMS_CHECK_SUC);
|
||||
}else {
|
||||
// smsCodeResponse.setStatus(SMS_CHECK_FAIL);
|
||||
smsCodeResponse.setStatus(SMS_CHECK_SUC);
|
||||
}
|
||||
} else {
|
||||
smsCodeResponse.setStatus(SMS_CHECK_FAIL);
|
||||
}
|
||||
} else {
|
||||
smsCodeResponse.setStatus(SMS_CHECK_FAIL);
|
||||
}
|
||||
return smsCodeResponse;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/6.
|
||||
* 返回业务数据的公共格式
|
||||
*/
|
||||
|
||||
public class BaseBizResponse {
|
||||
|
||||
public static final int STATE_OK = 0;
|
||||
private int status;
|
||||
private ResultBean result;
|
||||
|
||||
public int getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(int status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
public ResultBean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(ResultBean result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public static class ResultBean {
|
||||
/**
|
||||
* success : 0
|
||||
* msg :
|
||||
*/
|
||||
|
||||
private int success;
|
||||
private String msg;
|
||||
|
||||
public int getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(int success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.Html;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.dalimao.corelibrary.VerificationCodeInput;
|
||||
import com.fenghoo.seven.BaseApplication;
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.base.BaseActivity;
|
||||
import com.fenghoo.seven.main.activity.common.databus.RxBus;
|
||||
import com.fenghoo.seven.main.activity.common.http.IHttpClient;
|
||||
import com.fenghoo.seven.main.activity.common.http.impl.OkHttpClientImpl;
|
||||
import com.fenghoo.seven.main.activity.common.storage.SharedPreferencesDao;
|
||||
import com.fenghoo.seven.main.activity.mvp.presenterImpl.ISmsCodeDialogPresenter;
|
||||
import com.fenghoo.seven.main.activity.mvp.presenterImpl.SmsCodeDialogPresenterImpl;
|
||||
import com.fenghoo.seven.main.kehu.activity.SearchActivity;
|
||||
import com.fenghoo.seven.main.my.entity.loginInfoBean;
|
||||
import com.fenghoo.seven.utils.ToastUtils;
|
||||
import com.fenghoo.seven.utils.checkVersionsUtils.ProfileSpUtils;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
|
||||
/**
|
||||
* LoginActivity
|
||||
* 类描述:登录页面
|
||||
* 2018/10/30 5:06
|
||||
* mengjuan
|
||||
*/
|
||||
|
||||
public class CodeLoginActivity extends BaseActivity implements ISmsCodeDialogView{
|
||||
|
||||
|
||||
private String mPhone;
|
||||
private TextView mResentBtn;
|
||||
private VerificationCodeInput mVerificationInput;
|
||||
private View mLoading;
|
||||
private View mErrorView;
|
||||
private TextView mPhoneTv,mPhoneTvtwo;
|
||||
private ISmsCodeDialogPresenter mPresenter;
|
||||
|
||||
/**
|
||||
* 验证码倒计时
|
||||
*/
|
||||
|
||||
private CountDownTimer mCountDownTimer = new CountDownTimer(60000, 1000) {
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) {
|
||||
mResentBtn.setEnabled(false);
|
||||
mResentBtn.setText(Html.fromHtml("<font color='#7A7A7A'>" + "再次发送" + "</font>"+"<font color='#3288EE'>" + (millisUntilFinished / 1000) + "</font>s"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
mResentBtn.setEnabled(true);
|
||||
mResentBtn.setText("重新发送");
|
||||
mResentBtn.setTextColor(getResources().getColor(R.color.colortheme));
|
||||
}
|
||||
};
|
||||
private TitleBar title_bar;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
// TODO:OnCreate Method has been created, run FindViewById again to generate code
|
||||
setContentView(R.layout.dialog_smscode_input);
|
||||
mPhoneTv = (TextView) findViewById(R.id.phone);
|
||||
mPhoneTvtwo = (TextView) findViewById(R.id.phonetwo);
|
||||
title_bar = (TitleBar) findViewById(R.id.title_bar);
|
||||
initNormalBack();
|
||||
title_bar.setTitle("");
|
||||
mPhone = getIntent().getStringExtra("phone");
|
||||
// String template = "正在向%s发送短信验证码";
|
||||
// mPhoneTv.setText(String.format(template, mPhone));
|
||||
|
||||
String template = "正在发送短信验证码至";
|
||||
mPhoneTv.setText(String.format(template, mPhone));
|
||||
mPhoneTvtwo.setText("+86 "+mPhone);
|
||||
mResentBtn = (TextView) findViewById(R.id.btn_resend);
|
||||
mVerificationInput = (VerificationCodeInput) findViewById(R.id.verificationCodeInput);
|
||||
mLoading = findViewById(R.id.loading);
|
||||
mErrorView = findViewById(R.id.error);
|
||||
mErrorView.setVisibility(View.GONE);
|
||||
|
||||
IHttpClient httpClient = new OkHttpClientImpl();
|
||||
SharedPreferencesDao dao =
|
||||
new SharedPreferencesDao(BaseApplication.getInstance(),
|
||||
SharedPreferencesDao.FILE_ACCOUNT);
|
||||
IAccountManager iAccountManager = new AccountManagerImpl(httpClient, dao);
|
||||
mPresenter = new SmsCodeDialogPresenterImpl(this, iAccountManager);
|
||||
initListeners();
|
||||
requestSendSmsCode();
|
||||
// 注册 Presenter
|
||||
RxBus.getInstance().register(mPresenter);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initListeners() {
|
||||
|
||||
// 重发验证码按钮注册监听器
|
||||
mResentBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String template = "正在发送短信验证码至";
|
||||
mPhoneTv.setText(String.format(template, mPhone));
|
||||
mPhoneTvtwo.setText("+86 "+mPhone);
|
||||
resend();
|
||||
}
|
||||
});
|
||||
|
||||
// 验证码输入完成监听器
|
||||
mVerificationInput.setOnCompleteListener(new VerificationCodeInput.Listener() {
|
||||
@Override
|
||||
public void onComplete(String code) {
|
||||
commit(code);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交验证码
|
||||
* @param code
|
||||
*/
|
||||
private void commit(final String code) {
|
||||
mPresenter.requestCheckSmsCode(mPhone, code);
|
||||
}
|
||||
|
||||
private void resend() {
|
||||
requestSendSmsCode();
|
||||
}
|
||||
/**
|
||||
* 请求下发验证码
|
||||
*/
|
||||
private void requestSendSmsCode() {
|
||||
|
||||
mPresenter.requestSendSmsCode(mPhone);
|
||||
}
|
||||
@Override
|
||||
public void showLoading() {
|
||||
mLoading.setVisibility(View.VISIBLE);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showError(int code, String msg) {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
switch (code) {
|
||||
case IAccountManager.SMS_SEND_FAIL:
|
||||
ToastUtils.showToast(CodeLoginActivity.this,msg);
|
||||
break;
|
||||
// case IAccountManager.SMS_CHECK_FAIL:
|
||||
// // 提示验证码错误
|
||||
// mErrorView.setVisibility(View.VISIBLE);
|
||||
// mVerificationInput.setEnabled(true);
|
||||
|
||||
// break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showCountDownTimer() {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
String template = "验证码已通过短信发送至";
|
||||
mPhoneTv.setText(String.format(template, mPhone));
|
||||
mPhoneTvtwo.setText("+86 "+mPhone);
|
||||
mCountDownTimer.start();
|
||||
mResentBtn.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void showSmsCodeCheckState(boolean suc, loginInfoBean data) {
|
||||
if (!suc) {
|
||||
//提示验证码错误
|
||||
mErrorView.setVisibility(View.VISIBLE);
|
||||
mVerificationInput.setEnabled(true);
|
||||
mLoading.setVisibility(View.GONE);
|
||||
} else {
|
||||
//进入主页
|
||||
ProfileSpUtils.getInstance().saveLoginSatus(true);
|
||||
ProfileSpUtils.getInstance().saveProfile(data);
|
||||
startActivity(MainActivity.class);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void showUserExist(boolean exist) {
|
||||
mLoading.setVisibility(View.GONE);
|
||||
mErrorView.setVisibility(View.GONE);
|
||||
if (!exist) {
|
||||
|
||||
|
||||
} else {
|
||||
// // 用户存在 ,进入登录
|
||||
// LoginDialog dialog = new LoginDialog(mainActivity, mPhone);
|
||||
// dialog.show();
|
||||
// dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
// @Override
|
||||
// public void onDismiss(DialogInterface dialog) {
|
||||
// SmsCodeDialog.this.dismiss();
|
||||
// }
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
// 注销 Presenter
|
||||
RxBus.getInstance().unRegister(mPresenter);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.base.BaseActivity;
|
||||
import com.fenghoo.seven.main.kehu.activity.ShowAty;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
|
||||
public class ForgetPasActivity extends BaseActivity implements View.OnClickListener {
|
||||
private TitleBar title_bar;
|
||||
/**
|
||||
* 请输入手机号
|
||||
*/
|
||||
private EditText mEtPhone;
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
private Button mBtnLogin;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_forget_pas);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
title_bar = (TitleBar) findViewById(R.id.title_bar);
|
||||
initNormalBack();
|
||||
title_bar.setTitle("");
|
||||
mEtPhone = (EditText) findViewById(R.id.et_phone);
|
||||
mBtnLogin = (Button) findViewById(R.id.btn_login);
|
||||
mBtnLogin.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btn_login:
|
||||
ShowAty.CodeLoginActivity(ForgetPasActivity.this,mEtPhone.getText().toString().trim());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/9.
|
||||
* 帐号相关业务逻辑抽象
|
||||
*/
|
||||
|
||||
public interface IAccountManager {
|
||||
// 服务器错误
|
||||
static final int SERVER_FAIL = -999;
|
||||
// 验证码发送成功
|
||||
static final int SMS_SEND_SUC = 0;
|
||||
// 验证码发送失败
|
||||
static final int SMS_SEND_FAIL = 1;
|
||||
// 验证码校验成功
|
||||
static final int SMS_CHECK_SUC = 2;
|
||||
// 验证码错误
|
||||
static final int SMS_CHECK_FAIL = -2;
|
||||
// 用户已经存在
|
||||
static final int USER_EXIST = 3;
|
||||
// 用户不存在
|
||||
static final int USER_NOT_EXIST = -3;
|
||||
// 注册成功
|
||||
static final int REGISTER_SUC = 4;
|
||||
// 登录成功
|
||||
static final int LOGIN_SUC = 5;
|
||||
// 密码错误
|
||||
static final int PW_ERROR = -5;
|
||||
// 登录失效
|
||||
static final int TOKEN_INVALID = -6;
|
||||
|
||||
|
||||
/*void setHandler(Handler handler);*/
|
||||
/**
|
||||
* 下发验证码
|
||||
*/
|
||||
void fetchSMSCode(String phone);
|
||||
/**
|
||||
* 校验验证码
|
||||
*/
|
||||
void checkSmsCode(String phone, String smsCode);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
|
||||
import com.fenghoo.seven.main.my.entity.loginInfoBean;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/13.
|
||||
*/
|
||||
|
||||
public interface ISmsCodeDialogView extends IView {
|
||||
|
||||
|
||||
/**
|
||||
* 显示倒计时
|
||||
*/
|
||||
void showCountDownTimer();
|
||||
|
||||
|
||||
/**
|
||||
* 显示验证状态
|
||||
* @param b
|
||||
*/
|
||||
void showSmsCodeCheckState(boolean b, loginInfoBean data);
|
||||
|
||||
|
||||
/**
|
||||
* 用户是否存在
|
||||
* @param b
|
||||
*/
|
||||
void showUserExist(boolean b);
|
||||
}
|
||||
16
app/src/main/java/com/fenghoo/seven/main/activity/IView.java
Normal file
16
app/src/main/java/com/fenghoo/seven/main/activity/IView.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/13.
|
||||
*/
|
||||
|
||||
public interface IView {
|
||||
/**
|
||||
* 显示loading
|
||||
*/
|
||||
void showLoading();
|
||||
/**
|
||||
* 显示错误
|
||||
*/
|
||||
void showError(int Code, String msg);
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.CountDownTimer;
|
||||
import android.text.Html;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.base.BaseTreeActivity;
|
||||
import com.fenghoo.seven.main.activity.mvp.contract.LoginPasswordContract;
|
||||
import com.fenghoo.seven.main.activity.mvp.presenterImpl.LoginPasswordPresenterImpl;
|
||||
import com.fenghoo.seven.main.kehu.activity.ShowAty;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -25,6 +28,7 @@ public class LoginPasswordActivity extends BaseTreeActivity<LoginPasswordContrac
|
||||
private EditText mEtPhone;
|
||||
private TextView mTvGetCode;
|
||||
private Button mBtnLogin;
|
||||
private String longintype="0";//是密码登录 1是验证码登录
|
||||
|
||||
private CountDownTimer timer = new CountDownTimer(60000, 1000) {
|
||||
@Override
|
||||
@@ -38,6 +42,11 @@ public class LoginPasswordActivity extends BaseTreeActivity<LoginPasswordContrac
|
||||
mTvGetCode.setText("发送验证码");
|
||||
}
|
||||
};
|
||||
private TextView login_tv_pas;
|
||||
private RelativeLayout ll_code;
|
||||
private View view;
|
||||
private TextView login_tv_code;
|
||||
private TextView login_tv_forgetpas;
|
||||
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -50,6 +59,15 @@ public class LoginPasswordActivity extends BaseTreeActivity<LoginPasswordContrac
|
||||
et_pass = (EditText) findViewById(R.id.et_pass);
|
||||
mBtnLogin = (Button) findViewById(R.id.btn_login);
|
||||
mBtnLogin.setOnClickListener(this);
|
||||
login_tv_pas = (TextView) findViewById(R.id.login_tv_pas);
|
||||
ll_code = (RelativeLayout) findViewById(R.id.ll_code);
|
||||
view = (View) findViewById(R.id.view);
|
||||
login_tv_code = (TextView) findViewById(R.id.login_tv_code);
|
||||
login_tv_code.setOnClickListener(this);
|
||||
login_tv_forgetpas = (TextView) findViewById(R.id.login_tv_forgetpas);
|
||||
login_tv_forgetpas.setOnClickListener(this);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,11 +84,47 @@ public class LoginPasswordActivity extends BaseTreeActivity<LoginPasswordContrac
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()) {
|
||||
case R.id.btn_login://登录
|
||||
if(longintype.equals("0")){
|
||||
getPresenter().login();
|
||||
}else {
|
||||
// ShowAty.CodeLoginActivity(LoginPasswordActivity.this,mEtPhone.getText().toString().trim());
|
||||
ShowAty.CodeLoginActivity(LoginPasswordActivity.this,"18133922183");
|
||||
}
|
||||
break;
|
||||
case R.id.login_tv_code://验证码登录
|
||||
if(longintype.equals("0")){
|
||||
codeLogin();
|
||||
longintype="1";
|
||||
}else {
|
||||
passWordLogin();
|
||||
longintype="0";
|
||||
}
|
||||
|
||||
ShowAty.CodeLoginActivity(LoginPasswordActivity.this,"18133922183");
|
||||
break;
|
||||
case R.id.login_tv_forgetpas://忘记密码
|
||||
ShowAty.ForgetPasActivity(LoginPasswordActivity.this);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void codeLogin() {
|
||||
login_tv_pas.setVisibility(View.GONE);
|
||||
ll_code.setVisibility(View.GONE);
|
||||
view.setVisibility(View.GONE);
|
||||
mBtnLogin.setText("获取验证码");
|
||||
login_tv_code.setText("密码登录");
|
||||
}
|
||||
|
||||
private void passWordLogin() {
|
||||
login_tv_pas.setVisibility(View.VISIBLE);
|
||||
ll_code.setVisibility(View.VISIBLE);
|
||||
view.setVisibility(View.VISIBLE);
|
||||
mBtnLogin.setText("登录");
|
||||
login_tv_code.setText("验证码登录");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMobile() {
|
||||
return mEtPhone.getText().toString();
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.fenghoo.seven.R;
|
||||
import com.fenghoo.seven.base.BaseActivity;
|
||||
import com.fenghoo.seven.main.kehu.activity.ShowAty;
|
||||
import com.fenghoo.seven.widget.TitleBar;
|
||||
|
||||
public class ModifyPasActivity extends BaseActivity implements View.OnClickListener {
|
||||
private TitleBar title_bar;
|
||||
/**
|
||||
* 请输入手机号
|
||||
*/
|
||||
private EditText mEtPhone;
|
||||
/**
|
||||
* 获取验证码
|
||||
*/
|
||||
private Button mBtnLogin;
|
||||
/**
|
||||
* 请确认新密码
|
||||
*/
|
||||
private EditText mEtPass;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_modify_pas);
|
||||
initView();
|
||||
}
|
||||
|
||||
private void initView() {
|
||||
title_bar = (TitleBar) findViewById(R.id.title_bar);
|
||||
initNormalBack();
|
||||
title_bar.setTitle("");
|
||||
mEtPhone = (EditText) findViewById(R.id.et_phone);
|
||||
mBtnLogin = (Button) findViewById(R.id.btn_login);
|
||||
mBtnLogin.setOnClickListener(this);
|
||||
mEtPass = (EditText) findViewById(R.id.et_pass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.btn_login:
|
||||
ShowAty.CodeLoginActivity(ModifyPasActivity.this, mEtPhone.getText().toString().trim());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
|
||||
import com.fenghoo.seven.main.my.entity.loginInfoBean;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/22.
|
||||
*/
|
||||
|
||||
public class SmsCodeResponse extends BaseBizResponse {
|
||||
/**
|
||||
* msg : 登陆成功
|
||||
* data : {"store_id":"1","industry_name":"家具","user_head":"","user_type":"2","user_name":"admin","phone_number":"14729066305","uuid":"3","status":"0"}
|
||||
* success : 0
|
||||
*/
|
||||
|
||||
private String msg;
|
||||
private loginInfoBean.DataBean data;
|
||||
private int success;
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public loginInfoBean.DataBean getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public void setData(loginInfoBean.DataBean data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public int getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(int success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public static class DataBean {
|
||||
/**
|
||||
* store_id : 1
|
||||
* industry_name : 家具
|
||||
* user_head :
|
||||
* user_type : 2
|
||||
* user_name : admin
|
||||
* phone_number : 14729066305
|
||||
* uuid : 3
|
||||
* status : 0
|
||||
*/
|
||||
|
||||
private String store_id;
|
||||
private String industry_name;
|
||||
private String user_head;
|
||||
private String user_type;
|
||||
private String user_name;
|
||||
private String phone_number;
|
||||
private String uuid;
|
||||
private String status;
|
||||
|
||||
public String getUnion_id() {
|
||||
return union_id;
|
||||
}
|
||||
|
||||
public void setUnion_id(String union_id) {
|
||||
this.union_id = union_id;
|
||||
}
|
||||
|
||||
public String getAddress_addr() {
|
||||
return address_addr;
|
||||
}
|
||||
|
||||
public void setAddress_addr(String address_addr) {
|
||||
this.address_addr = address_addr;
|
||||
}
|
||||
|
||||
private String union_id;
|
||||
private String address_addr;
|
||||
|
||||
public String getStore_id() {
|
||||
return store_id;
|
||||
}
|
||||
|
||||
public void setStore_id(String store_id) {
|
||||
this.store_id = store_id;
|
||||
}
|
||||
|
||||
public String getIndustry_name() {
|
||||
return industry_name;
|
||||
}
|
||||
|
||||
public void setIndustry_name(String industry_name) {
|
||||
this.industry_name = industry_name;
|
||||
}
|
||||
|
||||
public String getUser_head() {
|
||||
return user_head;
|
||||
}
|
||||
|
||||
public void setUser_head(String user_head) {
|
||||
this.user_head = user_head;
|
||||
}
|
||||
|
||||
public String getUser_type() {
|
||||
return user_type;
|
||||
}
|
||||
|
||||
public void setUser_type(String user_type) {
|
||||
this.user_type = user_type;
|
||||
}
|
||||
|
||||
public String getUser_name() {
|
||||
return user_name;
|
||||
}
|
||||
|
||||
public void setUser_name(String user_name) {
|
||||
this.user_name = user_name;
|
||||
}
|
||||
|
||||
public String getPhone_number() {
|
||||
return phone_number;
|
||||
}
|
||||
|
||||
public void setPhone_number(String phone_number) {
|
||||
this.phone_number = phone_number;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
public void setUuid(String uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.fenghoo.seven.base.BaseActivity;
|
||||
import com.fenghoo.seven.utils.StatusBarUtil;
|
||||
import com.fenghoo.seven.utils.checkVersionsUtils.ProfileSpUtils;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.fenghoo.seven.main.activity;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/22.
|
||||
*/
|
||||
|
||||
public class UserExistResponse extends BaseBizResponse {
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.fenghoo.seven.main.activity.common.databus;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* 自定义注解,用于标记观察者的方法
|
||||
* Created by liuguangli on 17/3/9.
|
||||
*/
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface RegisterBus {
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
package com.fenghoo.seven.main.activity.common.databus;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.android.schedulers.AndroidSchedulers;
|
||||
import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
import rx.schedulers.Schedulers;
|
||||
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/17.
|
||||
*/
|
||||
|
||||
public class RxBus {
|
||||
private static final String TAG = "RxBus";
|
||||
private static volatile RxBus instance;
|
||||
// 订阅者集合
|
||||
private Set<Object> subscribers;
|
||||
|
||||
/**
|
||||
* 注册 DataBusSubscriber
|
||||
* @param subscriber
|
||||
*/
|
||||
public synchronized void register(Object subscriber) {
|
||||
subscribers.add(subscriber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注销 DataBusSubscriber
|
||||
* @param subscriber
|
||||
*/
|
||||
public synchronized void unRegister(Object subscriber) {
|
||||
subscribers.remove(subscriber);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 单利模式
|
||||
*/
|
||||
private RxBus() {
|
||||
subscribers = new CopyOnWriteArraySet<>();
|
||||
}
|
||||
public static synchronized RxBus getInstance() {
|
||||
|
||||
if (instance == null) {
|
||||
synchronized (RxBus.class) {
|
||||
if (instance == null) {
|
||||
instance = new RxBus();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 包装处理过程
|
||||
* @param func
|
||||
*/
|
||||
public void chainProcess(Func1 func) {
|
||||
Observable.just("")
|
||||
.subscribeOn(Schedulers.io()) // 指定处理过程在 IO 线程
|
||||
.map(func) // 包装处理过程
|
||||
.observeOn(AndroidSchedulers.mainThread()) // 指定事件消费在 Main 线程
|
||||
.subscribe(new Action1<Object>() {
|
||||
@Override
|
||||
public void call(Object data) {
|
||||
if (data == null) {
|
||||
return;
|
||||
}
|
||||
send(data);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送数据
|
||||
* @param data
|
||||
*/
|
||||
public void send(Object data) {
|
||||
for (Object subscriber : subscribers) {
|
||||
// 扫描注解,将数据发送到注册的对象的标记方法
|
||||
callMethodByAnnotiation(subscriber, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 反射获取对象方法列表,判断:
|
||||
* 1 是否被注解修饰
|
||||
* 2 参数类型是否和 data 类型一致
|
||||
* @param target
|
||||
* @param data
|
||||
*/
|
||||
|
||||
private void callMethodByAnnotiation(Object target, Object data) {
|
||||
Method[] methodArray = target.getClass().getDeclaredMethods();
|
||||
for (int i = 0; i < methodArray.length; i++) {
|
||||
try {
|
||||
if (methodArray[i].isAnnotationPresent(RegisterBus.class)) {
|
||||
// 被 @RegisterBus 修饰的方法
|
||||
Class paramType = methodArray[i].getParameterTypes()[0];
|
||||
if (data.getClass().getName().equals(paramType.getName())) {
|
||||
// 参数类型和 data 一样,调用此方法
|
||||
methodArray[i].invoke(target, new Object[]{data});
|
||||
}
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.fenghoo.seven.main.activity.common.http;
|
||||
|
||||
/**
|
||||
* HttpClient 抽象接口
|
||||
* Created by liuguangli on 17/4/24.
|
||||
*/
|
||||
|
||||
public interface IHttpClient {
|
||||
IResponse get(IRequest request, boolean forceCache);
|
||||
IResponse post(IRequest request, boolean forceCache);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.fenghoo.seven.main.activity.common.http;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/4/24.
|
||||
* 定义请求数据的封装方式
|
||||
*/
|
||||
public interface IRequest {
|
||||
public static final String POST = "POST";
|
||||
public static final String GET = "GET";
|
||||
|
||||
/**
|
||||
* 指定请求方式
|
||||
*/
|
||||
void setMethod(String method);
|
||||
|
||||
/**
|
||||
* 指定请求头部
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
void setHeader(String key, String value);
|
||||
|
||||
/**
|
||||
* 指定请求参数
|
||||
* @param key
|
||||
* @param value
|
||||
*/
|
||||
void setBody(String key, String value);
|
||||
|
||||
/**
|
||||
* 提供给执行库请求行URL
|
||||
* @return
|
||||
*/
|
||||
String getUrl();
|
||||
|
||||
/**
|
||||
* 提供给执行库请求头部
|
||||
* @return
|
||||
*/
|
||||
Map<String, String> getHeader();
|
||||
/**
|
||||
* 提供给执行库请求参数
|
||||
* @return
|
||||
*/
|
||||
Object getBody();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.fenghoo.seven.main.activity.common.http;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/4/24.
|
||||
*/
|
||||
public interface IResponse {
|
||||
// 状态码
|
||||
int getCode();
|
||||
// 数据体
|
||||
String getData();
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.fenghoo.seven.main.activity.common.http.api;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/4/29.
|
||||
*/
|
||||
|
||||
public class API {
|
||||
|
||||
public static final String TEST_GET= "/get?uid=${uid}";
|
||||
public static final String TEST_POST = "/post";
|
||||
// 获取验证码
|
||||
public static final String GET_SMS_CODE = "AppLogin/send";
|
||||
// 手机号登录
|
||||
public static final String CHECK_SMS_CODE =
|
||||
"AppLogin/checkCode" ;
|
||||
// 注册
|
||||
public static final String REGISTER = "/f34e28da5816433d/register";
|
||||
// 登录
|
||||
public static final String LOGIN = "/f34e28da5816433d/auth";
|
||||
// token 登录
|
||||
public static final String LOGIN_BY_TOKEN = "/f34e28da5816433d/login";
|
||||
//获取附近司机
|
||||
public static final String GET_NEAR_DRIVERS = "/f34e28da5816433d/getNearDrivers?latitude=${latitude}&longitude=${longitude}";
|
||||
// 上报当前位置
|
||||
public static final String UPLOAD_LOCATION = "/f34e28da5816433d/updateUserLocation";
|
||||
// 呼叫司机
|
||||
public static final String CALL_DRIVER = "/f34e28da5816433d/callDriver";
|
||||
|
||||
// 取消订单
|
||||
public static final String CANCEL_ORDER = "/f34e28da5816433d/cancelOrder";
|
||||
// 支付成功
|
||||
public static final String PAY = "/f34e28da5816433d/paySuc";
|
||||
// 获取当前正在处理中的订单
|
||||
public static final String GET_PROCESSING_ORDER = "/f34e28da5816433d/getProcessingOrder";
|
||||
|
||||
// 检查用户是否存在
|
||||
public static String CHECK_USER_EXIST =
|
||||
"/f34e28da5816433d/isUserExist?phone=${phone}";
|
||||
|
||||
/**
|
||||
* 配置域名信息
|
||||
*/
|
||||
public static class Config {
|
||||
private static final String TEST_DOMAIN = "http://192.168.1.3/device/";
|
||||
private static final String RElEASE_DOMAIN = "http://cloud.bmob.cn";
|
||||
private static final String TEST_APP_ID = "e90928398db0130b0d6d21da7bde357e";
|
||||
private static final String RELEASE_APP_ID = "e90928398db0130b0d6d21da7bde357e";
|
||||
private static final String TEST_APP_KEY = "514d8f8a2371bdf1566033f6664a24d2";
|
||||
private static final String RELEASE_APP_KEY = "514d8f8a2371bdf1566033f6664a24d2";
|
||||
private static String appId = TEST_APP_ID;
|
||||
private static String appKey = TEST_APP_KEY;
|
||||
private static String domain = TEST_DOMAIN;
|
||||
|
||||
public static void setDebug(boolean debug) {
|
||||
domain = debug ? TEST_DOMAIN : RElEASE_DOMAIN;
|
||||
appId = debug ? TEST_APP_ID : RELEASE_APP_ID;
|
||||
appKey = debug ? TEST_APP_KEY : RELEASE_APP_KEY;
|
||||
}
|
||||
public static String getDomain() {
|
||||
return domain;
|
||||
}
|
||||
public static String getAppId () {
|
||||
return appId;
|
||||
}
|
||||
public static String getAppKey () {
|
||||
return appKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.fenghoo.seven.main.activity.common.http.biz;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/6.
|
||||
* 返回业务数据的公共格式
|
||||
*/
|
||||
|
||||
public class BaseBizResponse {
|
||||
|
||||
public static final int STATE_OK = 200;
|
||||
// 密码错误
|
||||
public static final int STATE_PW_ERR = 100005;
|
||||
// token 无效/过期
|
||||
public static final int STATE_TOKEN_INVALID = 100006;
|
||||
// 用户已经存在
|
||||
public static int STATE_USER_EXIST = 100003;
|
||||
// 用户不存在
|
||||
public static int STATE_USER_NOT_EXIST = 100002;
|
||||
// 状态码
|
||||
private int code;
|
||||
private String msg;
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.fenghoo.seven.main.activity.common.http.impl;
|
||||
|
||||
import com.fenghoo.seven.main.activity.common.http.IRequest;
|
||||
import com.fenghoo.seven.main.activity.common.http.api.API;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/4/24.
|
||||
* 封装参数的实现
|
||||
*/
|
||||
|
||||
public class BaseRequest implements IRequest {
|
||||
private String method = POST;
|
||||
private String url;
|
||||
private Map<String, String> header;
|
||||
private Map<String, Object> body;
|
||||
|
||||
public BaseRequest(String url) {
|
||||
/**
|
||||
* 公共参数及头部信息
|
||||
*/
|
||||
this.url = url;
|
||||
header = new HashMap();
|
||||
body = new HashMap<>();
|
||||
header.put("X-Bmob-Application-Id", API.Config.getAppId());
|
||||
header.put("X-Bmob-REST-API-Key", API.Config.getAppKey());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMethod(String method) {
|
||||
|
||||
this.method = method;
|
||||
}
|
||||
public void setHeader(String key, String value) {
|
||||
header.put(key, value);
|
||||
}
|
||||
|
||||
public void setBody(String key, String value) {
|
||||
body.put(key, value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl() {
|
||||
if (GET.equals(method)) {
|
||||
// 组装 Get 请求参数
|
||||
for (String key : body.keySet()) {
|
||||
|
||||
url = url.replace("${" + key + "}", body.get(key).toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBody() {
|
||||
if (body != null) {
|
||||
// 组装 POST 方法请求参数
|
||||
return new Gson().toJson(this.body, HashMap.class);
|
||||
} else {
|
||||
return "{}";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.fenghoo.seven.main.activity.common.http.impl;
|
||||
|
||||
import com.fenghoo.seven.main.activity.common.http.IResponse;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/4/24.
|
||||
*/
|
||||
|
||||
public class BaseResponse implements IResponse {
|
||||
public static final int STATE_UNKNOWN_ERROR = 100001;
|
||||
public static final int STATE_OK = 200;
|
||||
|
||||
// 状态码
|
||||
private int code;
|
||||
// 响应数据
|
||||
private String data;
|
||||
@Override
|
||||
public String getData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public void setData(String data) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.fenghoo.seven.main.activity.common.http.impl;
|
||||
|
||||
import com.fenghoo.seven.main.activity.common.http.IHttpClient;
|
||||
import com.fenghoo.seven.main.activity.common.http.IRequest;
|
||||
import com.fenghoo.seven.main.activity.common.http.IResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* OkHttp 的是实现
|
||||
* Created by liuguangli on 17/4/24.
|
||||
*/
|
||||
|
||||
public class OkHttpClientImpl implements IHttpClient {
|
||||
OkHttpClient mOkHttpClient = new OkHttpClient.Builder()
|
||||
.build();
|
||||
@Override
|
||||
public IResponse get(IRequest request, boolean force) {
|
||||
/**
|
||||
* 解析业务参数
|
||||
*/
|
||||
|
||||
// 指定请求方式
|
||||
request.setMethod(IRequest.GET);
|
||||
// 解析头部
|
||||
Map<String, String> header = request.getHeader();
|
||||
// OkHttp 的 Request.Builder
|
||||
Request.Builder builder = new Request.Builder();
|
||||
for (String key : header.keySet()) {
|
||||
// 组装成 OkHttp 的 Header
|
||||
builder.header(key, header.get(key));
|
||||
|
||||
}
|
||||
// 获取 url
|
||||
String url = request.getUrl();
|
||||
builder.url(url)
|
||||
.get();
|
||||
|
||||
Request oKRequest = builder.build();
|
||||
// 执行 oKRequest
|
||||
return execute(oKRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IResponse post(IRequest request, boolean foreCache) {
|
||||
// 指定请求方式
|
||||
request.setMethod(IRequest.POST);
|
||||
MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
|
||||
RequestBody body = RequestBody.create(mediaType, request.getBody().toString());
|
||||
Map<String, String> header = request.getHeader();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
for (String key : header.keySet()) {
|
||||
|
||||
builder.header(key, header.get(key));
|
||||
|
||||
}
|
||||
builder.url(request.getUrl())
|
||||
.post(body);
|
||||
Request oKRequest = builder.build();
|
||||
return execute(oKRequest);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 请求执行过程
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
private IResponse execute(Request request) {
|
||||
BaseResponse commonResponse = new BaseResponse();
|
||||
try {
|
||||
Response response = mOkHttpClient.newCall(request).execute();
|
||||
// 设置状态码
|
||||
commonResponse.setCode(response.code());
|
||||
String body = response.body().string();
|
||||
// 设置响应数据
|
||||
commonResponse.setData(body);
|
||||
/*Log.d("OkHttpClientImpl" ,String.format("Received response body: %s ",
|
||||
body));*/
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
commonResponse.setCode(commonResponse.STATE_UNKNOWN_ERROR);
|
||||
commonResponse.setData(e.getMessage());
|
||||
}
|
||||
return commonResponse;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.fenghoo.seven.main.activity.common.storage;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* ShraredPreference 数据访问对象
|
||||
* Created by liuguangli on 17/3/6.
|
||||
*/
|
||||
|
||||
public class SharedPreferencesDao {
|
||||
private static final String TAG = "SharedPreferencesDao";
|
||||
public static final String FILE_ACCOUNT = "FILE_ACCOUNT";
|
||||
public static final String KEY_ACCOUNT = "KEY_ACCOUNT";
|
||||
private SharedPreferences sharedPreferences;
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
public SharedPreferencesDao(Application application, String fileName) {
|
||||
sharedPreferences =
|
||||
application.getSharedPreferences(fileName, Context.MODE_PRIVATE);
|
||||
}
|
||||
/**
|
||||
* 保存 k-v
|
||||
*/
|
||||
public void save(String key, String value) {
|
||||
sharedPreferences.edit().putString(key, value).commit();
|
||||
}
|
||||
/**
|
||||
* 读取 k-v
|
||||
*/
|
||||
public String get(String key) {
|
||||
|
||||
return sharedPreferences.getString(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存对象
|
||||
*/
|
||||
public void save(String key, Object object) {
|
||||
String value = new Gson().toJson(object);
|
||||
save(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取对象
|
||||
*/
|
||||
|
||||
public Object get(String key, Class cls) {
|
||||
|
||||
String value = get(key);
|
||||
try {
|
||||
if (value != null) {
|
||||
Object o = new Gson().fromJson(value, cls);
|
||||
return o;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, e.getMessage());
|
||||
}
|
||||
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.fenghoo.seven.main.activity.common.util;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/2/26.
|
||||
*/
|
||||
|
||||
public class LogUtil {
|
||||
|
||||
public static void d(String tag, String msg) {
|
||||
Log.d(tag, msg);
|
||||
}
|
||||
|
||||
public static void e(String tag, String msg) {
|
||||
Log.e(tag, msg);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.fenghoo.seven.main.activity.common.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* Toast 工具类
|
||||
* Created by liuguangli on 17/3/7.
|
||||
*/
|
||||
public class ToastUtil {
|
||||
public static void show(Context context, String string) {
|
||||
Toast.makeText(context, string, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.fenghoo.seven.main.activity.mvp.presenterImpl;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/13.
|
||||
*/
|
||||
|
||||
public interface ISmsCodeDialogPresenter {
|
||||
/**
|
||||
* 请求下发验证码
|
||||
*/
|
||||
void requestSendSmsCode(String phone);
|
||||
/**
|
||||
* 请求校验验证码
|
||||
*/
|
||||
void requestCheckSmsCode(String phone, String smsCode);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.fenghoo.seven.main.activity.mvp.presenterImpl;
|
||||
|
||||
import com.fenghoo.seven.main.activity.IAccountManager;
|
||||
import com.fenghoo.seven.main.activity.ISmsCodeDialogView;
|
||||
import com.fenghoo.seven.main.activity.SmsCodeResponse;
|
||||
import com.fenghoo.seven.main.activity.UserExistResponse;
|
||||
import com.fenghoo.seven.main.activity.common.databus.RegisterBus;
|
||||
import com.fenghoo.seven.main.my.entity.loginInfoBean;
|
||||
|
||||
/**
|
||||
* Created by liuguangli on 17/5/13.
|
||||
*/
|
||||
|
||||
public class SmsCodeDialogPresenterImpl implements ISmsCodeDialogPresenter {
|
||||
private ISmsCodeDialogView view;
|
||||
private IAccountManager accountManager;
|
||||
|
||||
@RegisterBus
|
||||
public void onSmsCodeResponse(SmsCodeResponse smsCodeResponse) {
|
||||
switch (smsCodeResponse.getStatus()) {
|
||||
case IAccountManager.SMS_SEND_SUC:
|
||||
view.showCountDownTimer();
|
||||
break;
|
||||
case IAccountManager.SMS_SEND_FAIL:
|
||||
String msg = smsCodeResponse.getResult().getMsg();
|
||||
view.showError(IAccountManager.SMS_SEND_FAIL, msg);
|
||||
break;
|
||||
case IAccountManager.SMS_CHECK_SUC:
|
||||
loginInfoBean loginInfoBean = new loginInfoBean();
|
||||
loginInfoBean.setData(smsCodeResponse.getData());
|
||||
loginInfoBean.setMsg(smsCodeResponse.getMsg());
|
||||
loginInfoBean.setSuccess(smsCodeResponse.getSuccess());
|
||||
view.showSmsCodeCheckState(true,loginInfoBean);
|
||||
break;
|
||||
case IAccountManager.SMS_CHECK_FAIL:
|
||||
view.showError(IAccountManager.SMS_CHECK_FAIL, "");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterBus
|
||||
public void onSmsCodeResponse(UserExistResponse userExistResponse) {
|
||||
switch (userExistResponse.getStatus()) {
|
||||
case IAccountManager.USER_EXIST:
|
||||
view.showUserExist(true);
|
||||
break;
|
||||
case IAccountManager.USER_NOT_EXIST:
|
||||
view.showUserExist(false);
|
||||
break;
|
||||
case IAccountManager.SERVER_FAIL:
|
||||
view.showError(IAccountManager.SERVER_FAIL, "");
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
public SmsCodeDialogPresenterImpl(ISmsCodeDialogView view,
|
||||
IAccountManager accountManager) {
|
||||
this.view = view;
|
||||
this.accountManager = accountManager;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取验证码
|
||||
* @param phone
|
||||
*/
|
||||
@Override
|
||||
public void requestSendSmsCode(String phone) {
|
||||
view.showLoading();
|
||||
accountManager.fetchSMSCode(phone);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证码这验证码
|
||||
* @param phone
|
||||
* @param smsCode
|
||||
*/
|
||||
@Override
|
||||
public void requestCheckSmsCode(String phone, String smsCode) {
|
||||
|
||||
accountManager.checkSmsCode(phone, smsCode);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,8 @@ import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.fenghoo.seven.db.DbRecordBeanData;
|
||||
import com.fenghoo.seven.main.activity.CodeLoginActivity;
|
||||
import com.fenghoo.seven.main.activity.ForgetPasActivity;
|
||||
import com.fenghoo.seven.main.find.CloundSolutionActivity;
|
||||
import com.fenghoo.seven.main.find.CommentActivity;
|
||||
import com.fenghoo.seven.main.find.ConversationActivity;
|
||||
@@ -75,6 +77,15 @@ public class ShowAty {
|
||||
Intent i = new Intent(ctx, MainActivitytwot.class);
|
||||
ctx.startActivity(i);
|
||||
}
|
||||
public static void CodeLoginActivity(Context ctx,String phone) {
|
||||
Intent i = new Intent(ctx, CodeLoginActivity.class);
|
||||
i.putExtra("phone",phone);
|
||||
ctx.startActivity(i);
|
||||
}
|
||||
public static void ForgetPasActivity(Context ctx) {
|
||||
Intent i = new Intent(ctx, ForgetPasActivity.class);
|
||||
ctx.startActivity(i);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user