Skip to content

Commit

Permalink
Finish resetPassword
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchao29 committed Jul 24, 2019
1 parent 42ba4d5 commit a0d9c18
Show file tree
Hide file tree
Showing 21 changed files with 370 additions and 58 deletions.
2 changes: 1 addition & 1 deletion data/src/main/java
2 changes: 1 addition & 1 deletion platform/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ android {


defaultConfig {
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
2 changes: 1 addition & 1 deletion resume/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
compileSdkVersion 28
defaultConfig {
applicationId "com.oo.resume"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
Expand Down
3 changes: 3 additions & 0 deletions resume/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
android:name=".activity.SignInActivity"
android:launchMode="singleTop"
android:screenOrientation="portrait"/>
<activity
android:name=".activity.ResetPasswordActivity"
android:screenOrientation="portrait"/>


</application>
Expand Down
3 changes: 1 addition & 2 deletions resume/src/main/java/com/oo/resume/ResumeApplication.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.oo.resume

import android.app.Application
import androidx.multidex.MultiDexApplication
import com.chenenyu.router.Router
import com.facebook.drawee.backends.pipeline.Fresco
import com.oo.resume.activity.RouteSessionInterceptor
Expand All @@ -12,7 +11,7 @@ import com.oo.resume.activity.RouteSessionInterceptor
* $date 2019-06-02 17:18
* $describe
*/
class ResumeApplication : MultiDexApplication() {
class ResumeApplication : Application() {

companion object {
var INSTANCE: Application? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MineFragment : BaseFragment() {
.addSheetItem("", BottomDialog.OnSheetItemClickListener { sex.text = "" })
.addSheetItem("", BottomDialog.OnSheetItemClickListener { sex.text = "" }).show()
})
password.setOnClickListener { }
password.setOnClickListener { Router.build(RouteUrl.RESET_PASSWORD_PAGE).go(this) }
exit.setOnClickListener { viewModel.logout() }
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package com.oo.resume.activity

import android.os.Bundle
import android.text.TextUtils
import android.widget.Toast
import androidx.lifecycle.Observer
import com.chenenyu.router.annotation.Route
import com.oo.platform.view.BaseActivity
import com.oo.platform.viewmodel.ViewModelBinder
import com.oo.resume.R
import com.oo.resume.viewmodel.ResetPasswordViewModel
import com.oo.widget.OoDialog
import kotlinx.android.synthetic.main.activity_reset_password.*

/**
* $author yangchao
* $email [email protected]
* $date 2019-07-24 16:07
* $describe
*/
@Route(RouteUrl.RESET_PASSWORD_PAGE)
class ResetPasswordActivity : BaseActivity() {

lateinit var viewModel: ResetPasswordViewModel

private lateinit var loading: OoDialog

override fun getContentViewResId(): Int {
return R.layout.activity_reset_password
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewModel = ViewModelBinder.bind(this, ResetPasswordViewModel::class.java)
loading = OoDialog(this, OoDialog.TYPE_LOADING, "Loading")
observe()
setListener()
}

private fun observe() {
viewModel.getResetPasswordResult().observe(this, Observer { result ->
if (result == null) return@Observer
if (result.isLoading) {
loading.show()
return@Observer
}
loading.dismiss()
if (result.isSuccess) {
Toast.makeText(this, "密码修改成功", Toast.LENGTH_SHORT).show()
} else if (!TextUtils.isEmpty(result.errors?.msg)) {
Toast.makeText(this, result.errors?.msg, Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "密码修改失败", Toast.LENGTH_SHORT).show()
}
})
viewModel.getAccountInfo().observe(this, Observer { account ->
tv_phone.text = account.phone
})
}

private fun setListener() {
btn_submit.setOnClickListener { submit() }
iv_back.setOnClickListener { finish() }
}

private fun submit() {
val oldPassword = et_old_password.text.toString()
val newPassword = et_new_password.text.toString()
val confrimPassword = et_password_confirm.text.toString()
if (illegale(oldPassword, newPassword, confrimPassword)) return

viewModel.update(oldPassword, newPassword)
}

private fun illegale(oldPassword: String?, newPassword: String?, confirmPassword: String?): Boolean {
if (oldPassword.isNullOrBlank()) {
Toast.makeText(this, "请输入旧密码", Toast.LENGTH_SHORT).show()
return true
}
if (newPassword.isNullOrBlank() || confirmPassword.isNullOrBlank()) {
Toast.makeText(this, "请输入新密码", Toast.LENGTH_SHORT).show()
return true
}
if (newPassword != confirmPassword) {
Toast.makeText(this, "两次输入的密码不一致", Toast.LENGTH_SHORT).show()
return true
}
return false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import kotlinx.android.synthetic.main.item_resume_card.view.*
class ResumeListFragment : BaseFragment() {


private lateinit var viewmodel: ResumeListViewModel
private lateinit var viewModel: ResumeListViewModel
private lateinit var adapter: ResumeAdapter

override fun getContentViewResId(): Int {
Expand All @@ -27,7 +27,7 @@ class ResumeListFragment : BaseFragment() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
viewmodel = ViewModelBinder.bind(this, ResumeListViewModel::class.java)
viewModel = ViewModelBinder.bind(this, ResumeListViewModel::class.java)
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand All @@ -43,7 +43,7 @@ class ResumeListFragment : BaseFragment() {
}

private fun observe() {
viewmodel.getResumeList().observe(this, Observer { result ->
viewModel.getResumeList().observe(this, Observer { result ->
if (result == null) return@Observer
if (result.isLoading) {
srl_refresh.isRefreshing = true
Expand All @@ -56,11 +56,11 @@ class ResumeListFragment : BaseFragment() {
showToast(result.errors.msg)
}
})
viewmodel.refresh()
viewModel.refresh()
}

private fun setListener() {
srl_refresh.setOnRefreshListener { viewmodel.refresh() }
srl_refresh.setOnRefreshListener { viewModel.refresh() }
}


Expand Down
1 change: 1 addition & 0 deletions resume/src/main/java/com/oo/resume/activity/RouteUrl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ interface RouteUrl {
companion object {
const val HOME_PAGE = "home_page"
const val SIGNIN_PAGE = "signin_page"
const val RESET_PASSWORD_PAGE = "reset_password_page"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class SignInActivity : BaseActivity() {
private fun doConfirm() {
val name = et_name.text.toString()
val phone = et_phone.text.toString()
val password = et_password.text.toString()
val password = et_new_password.text.toString()
if (phone.isNullOrEmpty()) {
showToast("电话不能为空")
return
Expand Down
10 changes: 5 additions & 5 deletions resume/src/main/java/com/oo/resume/net/BaseObserver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ abstract class BaseObserver<T> : DisposableObserver<T>() {

private fun asApiErrors(throwable: Throwable): ErrorBody? {
// We had non-200 http error
when (throwable.javaClass) {
HttpException::class.java -> return handApiError(throwable as HttpException)
SocketTimeoutException::class.java -> return ErrorBody(ApiErrorCode.SOCKET_TIMEOUT, throwable.message)
ConnectException::class.java -> return ErrorBody(ApiErrorCode.NETWORK_UNREACHABLE, throwable.message)
when (throwable) {
is HttpException -> return handApiError(throwable)
is SocketTimeoutException -> return ErrorBody(ApiErrorCode.SOCKET_TIMEOUT, throwable.message)
is ConnectException -> return ErrorBody(ApiErrorCode.NETWORK_UNREACHABLE, throwable.message)
else -> return ErrorBody(ApiErrorCode.UNKNOW, throwable.message)
}
return ErrorBody(ApiErrorCode.UNKNOW, throwable.message)
}

private fun handApiError(throwable: HttpException): ErrorBody? {
Expand Down
93 changes: 57 additions & 36 deletions resume/src/main/java/com/oo/resume/repository/AccountRepo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.oo.platform.repo.IRepository
import com.oo.resume.net.BaseObserver
import com.oo.resume.net.ResposeResult
import com.oo.resume.net.RetrofitClient
import com.oo.resume.data.request.LoginRequest
import com.oo.resume.data.request.RegistRequest
import com.oo.resume.data.request.ResetPasswordRequest
import com.oo.resume.data.response.AccountDTO
import com.oo.resume.data.response.ErrorBody
import com.oo.resume.net.BaseObserver
import com.oo.resume.net.ResposeResult
import com.oo.resume.net.RetrofitClient
import com.oo.resume.service.AccountService
import com.oo.resume.util.SpUtil

Expand Down Expand Up @@ -55,62 +56,82 @@ class AccountRepo : IRepository {
val observable = MutableLiveData<ResposeResult<AccountDTO>>()
observable.setValue(ResposeResult.loading(null))
RetrofitClient
.getService(AccountService::class.java)
.login(request)
.subscribe(object : BaseObserver<AccountDTO>() {
.getService(AccountService::class.java)
.login(request)
.subscribe(object : BaseObserver<AccountDTO>() {

override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}

override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}

})
return observable
}

fun resetPassword(request: ResetPasswordRequest): LiveData<ResposeResult<Boolean>> {
val observable = MutableLiveData<ResposeResult<Boolean>>()
observable.value = ResposeResult.loading(null)
RetrofitClient
.getService(AccountService::class.java)
.resetPassword(request)
.subscribe(object : BaseObserver<Boolean>() {

override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}
override fun onNext(it: Boolean) {
observable.postValue(ResposeResult.success(it))
}

override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}
override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}

})
})
return observable
}

fun update(request: AccountDTO): LiveData<ResposeResult<AccountDTO>> {
val observable = MutableLiveData<ResposeResult<AccountDTO>>()
observable.value = ResposeResult.loading(null)
RetrofitClient
.getService(AccountService::class.java)
.update(request)
.subscribe(object : BaseObserver<AccountDTO>() {
.getService(AccountService::class.java)
.update(request)
.subscribe(object : BaseObserver<AccountDTO>() {

override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}
override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}

override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}
override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}

})
})
return observable
}

fun regist(request: RegistRequest): LiveData<ResposeResult<AccountDTO>> {
val observable = MutableLiveData<ResposeResult<AccountDTO>>()
observable.setValue(ResposeResult.loading(null))
RetrofitClient
.getService(AccountService::class.java)
.regist(request)
.subscribe(object : BaseObserver<AccountDTO>() {
.getService(AccountService::class.java)
.regist(request)
.subscribe(object : BaseObserver<AccountDTO>() {

override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}
override fun onNext(it: AccountDTO) {
storeAccount(it)
observable.postValue(ResposeResult.success(it))
}

override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}
override fun onError(errors: ErrorBody?) {
observable.postValue(ResposeResult.failure(errors))
}

})
})
return observable
}

Expand Down
4 changes: 4 additions & 0 deletions resume/src/main/java/com/oo/resume/service/AccountService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.oo.resume.service
import com.oo.resume.data.path.AccountUrl
import com.oo.resume.data.request.LoginRequest
import com.oo.resume.data.request.RegistRequest
import com.oo.resume.data.request.ResetPasswordRequest
import com.oo.resume.data.response.AccountDTO
import io.reactivex.Observable
import retrofit2.http.Body
Expand All @@ -20,4 +21,7 @@ interface AccountService {
@PUT(AccountUrl.PREFIX + AccountUrl.PATH_UPDATE)
fun update(@Body params: AccountDTO): Observable<AccountDTO>

@PUT(AccountUrl.PREFIX + AccountUrl.PATH_RESET_PASSWORD)
fun resetPassword(@Body params: ResetPasswordRequest): Observable<Boolean>

}
Loading

0 comments on commit a0d9c18

Please sign in to comment.