forked from melod1n/fast-messenger
code saving
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package com.meloda.fast.api.network
|
package com.meloda.fast.api.network
|
||||||
|
|
||||||
import com.meloda.fast.api.VKException
|
import com.meloda.fast.api.VKException
|
||||||
|
import com.meloda.fast.api.base.ApiError
|
||||||
import com.meloda.fast.api.base.ApiResponse
|
import com.meloda.fast.api.base.ApiResponse
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
import okio.IOException
|
import okio.IOException
|
||||||
@@ -93,7 +94,6 @@ internal class ResultCall<T>(proxy: Call<T>) : CallDelegate<T, Answer<T>>(proxy)
|
|||||||
|
|
||||||
if (result is Answer.Error && isVkException) if (checkErrors(call, result)) return
|
if (result is Answer.Error && isVkException) if (checkErrors(call, result)) return
|
||||||
|
|
||||||
|
|
||||||
callback.onResponse(proxy, Response.success(result))
|
callback.onResponse(proxy, Response.success(result))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,6 +105,11 @@ internal class ResultCall<T>(proxy: Call<T>) : CallDelegate<T, Answer<T>>(proxy)
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun checkErrors(call: Call<T>, result: Answer.Error): Boolean {
|
private fun checkErrors(call: Call<T>, result: Answer.Error): Boolean {
|
||||||
|
if (result.throwable is ApiError) {
|
||||||
|
onFailure(call, result.throwable)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
val json = JSONObject(result.throwable.message ?: "{}")
|
val json = JSONObject(result.throwable.message ?: "{}")
|
||||||
|
|
||||||
return if (json.has("error")) {
|
return if (json.has("error")) {
|
||||||
|
|||||||
@@ -30,8 +30,7 @@ abstract class BaseViewModel : ViewModel() {
|
|||||||
is Answer.Success -> onAnswer(response.data)
|
is Answer.Success -> onAnswer(response.data)
|
||||||
is Answer.Error -> {
|
is Answer.Error -> {
|
||||||
checkErrors(response.throwable)
|
checkErrors(response.throwable)
|
||||||
onError?.invoke(response.throwable)
|
onError?.invoke(response.throwable) ?: sendEvent(
|
||||||
?: sendEvent(
|
|
||||||
ErrorEvent(
|
ErrorEvent(
|
||||||
response.throwable.message
|
response.throwable.message
|
||||||
?: unknownErrorDefaultText
|
?: unknownErrorDefaultText
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class LoginFragment : BaseViewModelFragment<LoginViewModel>(R.layout.fragment_lo
|
|||||||
super.onEvent(event)
|
super.onEvent(event)
|
||||||
|
|
||||||
when (event) {
|
when (event) {
|
||||||
is ShowError -> showErrorSnackbar(event.errorDescription)
|
is ErrorEvent -> showErrorSnackbar(event.errorText)
|
||||||
is CaptchaEvent -> showCaptchaDialog(event.sid, event.image)
|
is CaptchaEvent -> showCaptchaDialog(event.sid, event.image)
|
||||||
is ValidationEvent -> showValidationRequired(event.sid)
|
is ValidationEvent -> showValidationRequired(event.sid)
|
||||||
is SuccessAuth -> goToMain(event.haveAuthorized)
|
is SuccessAuth -> goToMain(event.haveAuthorized)
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class LoginViewModel @Inject constructor(
|
|||||||
onError = {
|
onError = {
|
||||||
if (it !is VKException) return@makeJob
|
if (it !is VKException) return@makeJob
|
||||||
|
|
||||||
|
// TODO: 9/27/2021 use `delay` parameter
|
||||||
twoFaCode?.let { sendEvent(CodeSent) }
|
twoFaCode?.let { sendEvent(CodeSent) }
|
||||||
},
|
},
|
||||||
onStart = { sendEvent(StartProgressEvent) },
|
onStart = { sendEvent(StartProgressEvent) },
|
||||||
@@ -70,8 +71,6 @@ class LoginViewModel @Inject constructor(
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ShowError(val errorDescription: String) : VKEvent()
|
|
||||||
|
|
||||||
object CodeSent : VKEvent()
|
object CodeSent : VKEvent()
|
||||||
|
|
||||||
data class SuccessAuth(val haveAuthorized: Boolean = true) : VKEvent()
|
data class SuccessAuth(val haveAuthorized: Boolean = true) : VKEvent()
|
||||||
@@ -223,7 +223,7 @@ class AttachmentInflater constructor(
|
|||||||
binding.caption.isVisible = !link.caption.isNullOrBlank()
|
binding.caption.isVisible = !link.caption.isNullOrBlank()
|
||||||
|
|
||||||
binding.preview.shapeAppearanceModel.toBuilder()
|
binding.preview.shapeAppearanceModel.toBuilder()
|
||||||
.setAllCornerSizes(40f)
|
.setAllCornerSizes(AndroidUtils.px(20))
|
||||||
.build()
|
.build()
|
||||||
.let {
|
.let {
|
||||||
binding.preview.shapeAppearanceModel = it
|
binding.preview.shapeAppearanceModel = it
|
||||||
@@ -282,7 +282,7 @@ class AttachmentInflater constructor(
|
|||||||
|
|
||||||
binding.avatar.isVisible = group != null || user != null
|
binding.avatar.isVisible = group != null || user != null
|
||||||
binding.avatar.shapeAppearanceModel.toBuilder()
|
binding.avatar.shapeAppearanceModel.toBuilder()
|
||||||
.setAllCornerSizes(40f)
|
.setAllCornerSizes(AndroidUtils.px(20))
|
||||||
.build()
|
.build()
|
||||||
.let {
|
.let {
|
||||||
binding.avatar.shapeAppearanceModel = it
|
binding.avatar.shapeAppearanceModel = it
|
||||||
|
|||||||
Reference in New Issue
Block a user