Commit deaf0bd6 authored by 张释方's avatar 张释方

提交手机号绑定代码

parent c70818f0
......@@ -57,4 +57,15 @@ interface MainApi {
@POST("api/baseMsg")
fun baseMsg():Observable<Response<BaseResponse<MyInfo>>>
/**
* 绑定手机号接口
*/
@POST("api/bindingMobile")
fun bindingMobile(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<BindMobileBean>>>
/**
* 获取绑定手机号验证码接口
*/
@POST("api/sendMobileBindingCode")
fun sendMobileBindingCode(@Body vo:@JvmSuppressWildcards Map<String,Any>):Observable<Response<BaseResponse<Any>>>
}
\ No newline at end of file
package com.mints.street.bean
data class BindMobileBean(
val consumer: Consumer,
val token: Any
)
data class Consumer(
val createTime: Int,
val expireTime: Int,
val idcode: String,
val isForever: Boolean,
val mobile: String,
val nickname: String,
val pk_id: Long
)
\ No newline at end of file
......@@ -100,7 +100,7 @@ class LoginActivity : BaseActivity<ActivityLoginBinding, LoginViewModel>(), View
override fun initViewObservable() {
super.initViewObservable()
viewModel.data.observe(this, Observer<String> {
ToastUtils.showLong("初始化成功")
ToastUtils.showLong("登录成功")
startActivityThenKill(MainActivity::class.java)
})
......
......@@ -27,7 +27,7 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
}
/**
* 手机验证码
* 获取手机验证码
*
* @param mobile
*/
......@@ -49,6 +49,9 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
})
}
/**
* 调用登录接口
*/
fun login(mobile: String, smsCode: String) {
// showDialog()
val vo = HashMap<String, Any>()
......@@ -60,15 +63,18 @@ class LoginViewModel(application: Application) : BaseViewModel(application) {
object : HttpSubscribeImpl<BaseResponse<UserBean>>(
this@LoginViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<UserBean>) {
// dismissDialog()
//提交设备信息
this@LoginViewModel.saveTerminalInfo()
//保存用户信息到Usermanager
UserManager.INSTANCE.saveUserInfo(response.result)
data.value = response.message
KLog.e("login", response.result.toString())
ToastUtils.showShort("登录信息="+response.result.consumer?.idcode)
// ToastUtils.showShort("登录信息="+response.result.consumer?.idcode)
data.value = response.message
}
override fun onError(e: Throwable) {
......
......@@ -4,10 +4,13 @@ import android.Manifest
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import androidx.lifecycle.Observer
import com.fry.base.base.BaseActivity
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.bean.BindMobileBean
import com.mints.street.databinding.ActivityBindmobileBinding
import com.mints.street.main.MainActivity
import com.mints.street.utils.BackInputUtil
import com.tbruyelle.rxpermissions2.RxPermissions
import kotlinx.android.synthetic.main.activity_bindmobile.*
......@@ -60,7 +63,7 @@ class BindMobileActivity : BaseActivity<ActivityBindmobileBinding, BindMobileVie
mobile = mobile.replace(" ".toRegex(), "")
// loginPresenter.sendMobileBindingCode(mobile)
viewModel.sendMobileCode(mobile)
viewModel.bindingMobilecode(mobile)
}
R.id.tvLoginNext -> {
var mobile = etLoginMobile.text.toString().trim()
......@@ -80,7 +83,7 @@ class BindMobileActivity : BaseActivity<ActivityBindmobileBinding, BindMobileVie
.subscribe { granted: Boolean ->
if (granted) {
mobile = mobile.replace(" ".toRegex(), "")
// loginPresenter.bindingMobile(mobile, code)
viewModel.bindingMobile(mobile,code)
} else {
// showMissingPermissionDialog("设备")
}
......@@ -89,6 +92,20 @@ class BindMobileActivity : BaseActivity<ActivityBindmobileBinding, BindMobileVie
}
}
override fun initViewObservable() {
super.initViewObservable()
viewModel.bindmobiledata.observe(this, Observer<BindMobileBean> {
ToastUtils.showLong("请求绑定手机号接口成功")
startActivityThenKill(MainActivity::class.java)
})
viewModel.data.observe(this, Observer {
})
}
/**
* 发送手机验证码,按钮动态改变状态
*/
var num = 0
var run: Runnable? = null
fun sendCodeThread() {
......
......@@ -3,6 +3,7 @@ package com.mints.street.main.my
import android.app.Application
import androidx.lifecycle.MutableLiveData
import com.mints.street.bean.BaseResponse
import com.mints.street.bean.BindMobileBean
import com.mints.street.model.ApiModel
import com.mints.street.netwrok.base.HttpSubscribeImpl
import me.goldze.mvvmhabit.base.BaseViewModel
......@@ -11,19 +12,21 @@ import java.util.HashMap
class BindMobileViewModel (application: Application): BaseViewModel(application) {
val data : MutableLiveData<String> = MutableLiveData()
val bindmobiledata : MutableLiveData<BindMobileBean> = MutableLiveData()
val data :MutableLiveData<String> = MutableLiveData()
/**
* 手机验证码
* 绑定手机号验证码
*
* @param mobile
*/
fun sendMobileCode(mobile: String) {
fun bindingMobilecode(mobile: String) {
val vo = HashMap<String, Any>()
vo["mobile"] = mobile
vo["type"] = 1
ApiModel.sendMobileCode(lifecycleProvider,vo).safeSubscribe(
ApiModel.bindingMobilecode(lifecycleProvider,vo).safeSubscribe(
object : HttpSubscribeImpl<BaseResponse<Any>>(
this@BindMobileViewModel, true) {
override fun onBusinessSuccess(response: BaseResponse<Any>) {
......@@ -31,8 +34,35 @@ class BindMobileViewModel (application: Application): BaseViewModel(application)
}
override fun onError(e: Throwable) {
data.value = "失败"
KLog.e("sendMobileCode", "发送验证码错误")
KLog.e("sendMobileCode", "绑定手机号发送验证码错误")
}
})
}
/**
* 绑定手机号
*/
fun bindingMobile(mobile: String,smsCode:String){
val vo=HashMap<String,Any>()
vo["mobile"]=mobile
vo["smsCode"]=smsCode
ApiModel.bindingMobile(lifecycleProvider,vo).safeSubscribe(
object :HttpSubscribeImpl<BaseResponse<BindMobileBean>>(
this@BindMobileViewModel,true){
override fun onBusinessSuccess(response: BaseResponse<BindMobileBean>) {
bindmobiledata.value=response.result
KLog.e("bindingMobile",response.result.toString())
}
override fun onBusinessFail(response: BaseResponse<BindMobileBean>?) {
super.onBusinessFail(response)
}
override fun onError(e: Throwable) {
KLog.e("bindingMobile","绑定手机号接口失败")
}
}
)
}
}
......@@ -10,11 +10,17 @@ import com.fry.base.base.BaseActivity
import com.mints.street.BR
import com.mints.street.R
import com.mints.street.databinding.ActivityMoresettingsBinding
import com.mints.street.main.MainActivity
import com.mints.street.manager.UserManager
import kotlinx.android.synthetic.main.activity_moresettings.*
import kotlinx.android.synthetic.main.include_header.*
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.ToastUtils
class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, MoresettingsViewModel>(), View.OnClickListener {
private val userManager by lazy { UserManager.INSTANCE }
override fun initVariableId() = BR.viewModel
override fun initContentView(savedInstanceState: Bundle?) = R.layout.activity_moresettings
override fun initData() {
......@@ -29,6 +35,7 @@ class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, Moresetti
iv_left_icon.setOnClickListener(this)
item_userAgree.setOnClickListener(this)
item_privacyAgree.setOnClickListener(this)
btn_switch.setOnClickListener(this)
}
......@@ -39,7 +46,7 @@ class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, Moresetti
iv_left_icon.setImageResource(R.mipmap.ic_arrow_back)
iv_left_icon.visibility = View.VISIBLE
item_phone.findViewById<TextView>(R.id.tv_title).text = "手机号"
item_phone.findViewById<TextView>(R.id.tv_title).text = "绑定手机号"
val phone = ContextCompat.getDrawable(this, R.mipmap.icon_settings_tel)
phone?.setBounds(0, 0, 56, 56)
item_phone.findViewById<TextView>(R.id.tv_title).setCompoundDrawables(phone, null, null, null)
......@@ -76,10 +83,19 @@ class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, Moresetti
// return
// }
// if (userManager.mobile.isEmpty()) {
startActivity(BindMobileActivity::class.java)
// if (userManager.getMobile().isEmpty()) {
startActivity(BindMobileActivity::class.java)
// }else{
// ToastUtils.showLong("当前手机号已绑定")
// }
}
R.id.btn_switch -> {//推出登录
if (!userManager.getMobile().isEmpty()){
UserManager.INSTANCE.userLogout()
startActivityThenKill(MainActivity::class.java)
}
KLog.e("setOnClick","btn_switch has been clicked.")
}
R.id.item_userAgree -> {
}
......@@ -91,6 +107,5 @@ class MoresettingsActivity : BaseActivity<ActivityMoresettingsBinding, Moresetti
}
}
......@@ -29,6 +29,7 @@ import com.scwang.smartrefresh.layout.listener.OnRefreshListener
import kotlinx.android.synthetic.main.activity_moresettings.*
import kotlinx.android.synthetic.main.fragment_my.*
import me.goldze.mvvmhabit.utils.KLog
import me.goldze.mvvmhabit.utils.ToastUtils
/**
......@@ -55,6 +56,7 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
override fun initVariableId() = BR.viewModel
override fun initData() {
super.initData()
srl_my.setOnRefreshListener(this)
initView()
initListener()
}
......@@ -63,7 +65,11 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
super.onResume()
if (userManager.userIsLogin()) {
//查询用户登录信息
viewModel.getmyInfo()
}else{
//重新显示界面信息
setUserLoginStatus()
}
}
......@@ -89,7 +95,11 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
//设置立即领取点击事件
binding.btTry.setOnClickListener {
// startActivity(PermissionsActivity::class.java)
startActivity(OpenvipActivity::class.java)
if (userManager.userIsLogin()) {
startActivity(OpenvipActivity::class.java)
} else {
ToastUtils.showLong("请先登录!")
}
}
aboutus.setOnClickListener(this)
......@@ -124,9 +134,9 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
}
R.id.iv_weixin -> {
if (cb_checked!!.isChecked) {
Toast.makeText(context, "未完成微信登录对接", Toast.LENGTH_SHORT).show()
ToastUtils.showShort("未完成微信登录对接")
} else {
Toast.makeText(context, "请先同意用户协议与隐私政策", Toast.LENGTH_SHORT).show()
ToastUtils.showShort("请先同意用户协议与隐私政策")
}
}
R.id.ly_phone -> {
......@@ -134,7 +144,7 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
startActivity(LoginActivity::class.java)
mBottomSheetDialog!!.dismiss()
} else {
Toast.makeText(context, "请先同意用户协议与隐私政策", Toast.LENGTH_SHORT).show()
ToastUtils.showShort("请先同意用户协议与隐私政策")
}
}
......@@ -157,21 +167,18 @@ class MyFragment : BaseFragment<FragmentMyBinding, MyViewModel>(), OnRefreshList
}
private fun setUserLoginStatus() {
// if (userManager.userIsLogin()) {
// if (userManager.getMobile().isNotEmpty()) {
item_title_id.text = userManager.getMobile()
// } else {
// item_title_id.text = "未登录"
// }
// }
if (userManager.getMobile().isNotEmpty()) {
item_title_id.text = userManager.getMobile()
} else {
item_title_id.text = "未登录"
}
}
override fun onRefresh(refreshLayout: RefreshLayout) {
KLog.e("onRefresh","The current page has been refreshed.")
//重新显示界面信息
setUserLoginStatus()
}
// if (it.consumer!!.mobile.isNotEmpty()) {
// item_title_id.text = it.consumer.mobile
// }
}
......
......@@ -170,6 +170,7 @@ class UserManager {
fun userLogout() {
MMKV.mmkvWithID(USER_ID).remove(USER_ID)
MMKV.mmkvWithID(MOBILE).remove(MOBILE)
MMKV.mmkvWithID(CODE_ID).remove(CODE_ID)
MMKV.mmkvWithID(TOKEN_ID).remove(TOKEN_ID)
MMKV.mmkvWithID(WX_OPENID).remove(WX_OPENID)
......
......@@ -6,6 +6,7 @@ import com.mints.street.netwrok.common.HttpManager
import com.trello.rxlifecycle2.LifecycleProvider
import io.reactivex.Observable
import retrofit2.Response
import retrofit2.http.Body
/**
* Created by 冯瑞雨 on 2021/7/2.
......@@ -60,4 +61,18 @@ object ApiModel {
return HttpManager.getInstance()
.execute(lifecycleProvider, MainApi.newInstance().baseMsg())
}
/**
* 绑定手机号登录
*/
fun bindingMobile(lifecycleProvider: LifecycleProvider<Any>?, map: Map<String, Any>):Observable<Response<BaseResponse<BindMobileBean>>>{
return HttpManager.getInstance().execute(lifecycleProvider,MainApi.newInstance().bindingMobile(map))
}
/**
* 获取绑定手机号验证码
*/
fun bindingMobilecode(lifecycleProvider: LifecycleProvider<Any>?, map: Map<String, Any>):Observable<Response<BaseResponse<Any>>>{
return HttpManager.getInstance().execute(lifecycleProvider,MainApi.newInstance().sendMobileBindingCode(map))
}
}
\ No newline at end of file
......@@ -63,13 +63,13 @@ abstract class HttpSubscribeImpl<T : BaseResponse<*>>(viewModel: BaseViewModel?,
return
}
if (needToast) {
ToastUtils.showShort(response.getMessage())
ToastUtils.showLong(response.getMessage())
}
}
open fun onFailed(throwable: ResponseThrowable?) {
if (needToast) {
ToastUtils.showShort(throwable?.responseMessage)
ToastUtils.showLong(throwable?.responseMessage)
}
if (throwable?.code == ExceptionHandle.ERROR.HTTP_ERROR || throwable?.code == ExceptionHandle.ERROR.NETWORD_ERROR || throwable?.code == ExceptionHandle.ERROR.TIMEOUT_ERROR) {
viewModel?.viewSwitch(ViewStatus.NONETWORK)
......
......@@ -92,7 +92,7 @@ public class GsonConverterFactory extends Converter.Factory {
int code = br.getstatus();
if (code == 401) {
try {
// UserManager.Companion.getINSTANCE().userLogout();
UserManager.Companion.getINSTANCE().userLogout();
// Activity forwardActivity = ForegroundOrBackground.getApp_activity();
// if (forwardActivity != null) {
......
......@@ -45,6 +45,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="手机号:" />
<com.mints.street.widget.ClearEditText
......@@ -79,6 +80,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:text="验证码:" />
<RelativeLayout
......
......@@ -2,9 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:background="@mipmap/icon_card"
android:orientation="vertical">
</LinearLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment