diff --git a/app/src/main/kotlin/com/meloda/fast/api/network/ResultCallFactory.kt b/app/src/main/kotlin/com/meloda/fast/api/network/ResultCallFactory.kt index 1950b7b9..70c5a758 100644 --- a/app/src/main/kotlin/com/meloda/fast/api/network/ResultCallFactory.kt +++ b/app/src/main/kotlin/com/meloda/fast/api/network/ResultCallFactory.kt @@ -1,6 +1,7 @@ package com.meloda.fast.api.network import com.meloda.fast.api.VKException +import com.meloda.fast.api.base.ApiError import com.meloda.fast.api.base.ApiResponse import okhttp3.Request import okio.IOException @@ -93,7 +94,6 @@ internal class ResultCall(proxy: Call) : CallDelegate>(proxy) if (result is Answer.Error && isVkException) if (checkErrors(call, result)) return - callback.onResponse(proxy, Response.success(result)) } @@ -105,6 +105,11 @@ internal class ResultCall(proxy: Call) : CallDelegate>(proxy) } private fun checkErrors(call: Call, result: Answer.Error): Boolean { + if (result.throwable is ApiError) { + onFailure(call, result.throwable) + return true + } + val json = JSONObject(result.throwable.message ?: "{}") return if (json.has("error")) { diff --git a/app/src/main/kotlin/com/meloda/fast/base/viewmodel/BaseViewModel.kt b/app/src/main/kotlin/com/meloda/fast/base/viewmodel/BaseViewModel.kt index 4892ca01..97c3220b 100644 --- a/app/src/main/kotlin/com/meloda/fast/base/viewmodel/BaseViewModel.kt +++ b/app/src/main/kotlin/com/meloda/fast/base/viewmodel/BaseViewModel.kt @@ -30,13 +30,12 @@ abstract class BaseViewModel : ViewModel() { is Answer.Success -> onAnswer(response.data) is Answer.Error -> { checkErrors(response.throwable) - onError?.invoke(response.throwable) - ?: sendEvent( - ErrorEvent( - response.throwable.message - ?: unknownErrorDefaultText - ) + onError?.invoke(response.throwable) ?: sendEvent( + ErrorEvent( + response.throwable.message + ?: unknownErrorDefaultText ) + ) } } }.also { it.invokeOnCompletion { viewModelScope.launch { onEnd?.invoke() } } } diff --git a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginFragment.kt b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginFragment.kt index 7893cec7..1f27553b 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginFragment.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginFragment.kt @@ -63,7 +63,7 @@ class LoginFragment : BaseViewModelFragment(R.layout.fragment_lo super.onEvent(event) when (event) { - is ShowError -> showErrorSnackbar(event.errorDescription) + is ErrorEvent -> showErrorSnackbar(event.errorText) is CaptchaEvent -> showCaptchaDialog(event.sid, event.image) is ValidationEvent -> showValidationRequired(event.sid) is SuccessAuth -> goToMain(event.haveAuthorized) diff --git a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt index c4a613e1..93530186 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/login/LoginViewModel.kt @@ -53,6 +53,7 @@ class LoginViewModel @Inject constructor( onError = { if (it !is VKException) return@makeJob + // TODO: 9/27/2021 use `delay` parameter twoFaCode?.let { sendEvent(CodeSent) } }, onStart = { sendEvent(StartProgressEvent) }, @@ -70,8 +71,6 @@ class LoginViewModel @Inject constructor( } -data class ShowError(val errorDescription: String) : VKEvent() - object CodeSent : VKEvent() data class SuccessAuth(val haveAuthorized: Boolean = true) : VKEvent() \ No newline at end of file diff --git a/app/src/main/kotlin/com/meloda/fast/screens/messages/AttachmentInflater.kt b/app/src/main/kotlin/com/meloda/fast/screens/messages/AttachmentInflater.kt index 581ec9a3..36e81833 100644 --- a/app/src/main/kotlin/com/meloda/fast/screens/messages/AttachmentInflater.kt +++ b/app/src/main/kotlin/com/meloda/fast/screens/messages/AttachmentInflater.kt @@ -223,7 +223,7 @@ class AttachmentInflater constructor( binding.caption.isVisible = !link.caption.isNullOrBlank() binding.preview.shapeAppearanceModel.toBuilder() - .setAllCornerSizes(40f) + .setAllCornerSizes(AndroidUtils.px(20)) .build() .let { binding.preview.shapeAppearanceModel = it @@ -282,7 +282,7 @@ class AttachmentInflater constructor( binding.avatar.isVisible = group != null || user != null binding.avatar.shapeAppearanceModel.toBuilder() - .setAllCornerSizes(40f) + .setAllCornerSizes(AndroidUtils.px(20)) .build() .let { binding.avatar.shapeAppearanceModel = it