-
Notifications
You must be signed in to change notification settings - Fork 239
Homework Baturina #164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Homework Baturina #164
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Оставил пару замечаний
override fun onFailure(call: Call<Fact>, t: Throwable) { | ||
CrashMonitor.trackWarning() | ||
outerScope.launch { | ||
innerScope = CoroutineScope(Dispatchers.IO) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А иннер скоуп ты зачем делаешь?
_catsView?.populate(CatModel(catFact.await().fact, catImage.await().url)) | ||
} catch (exc: SocketTimeoutException) { | ||
_catsView?.makeToast("Не удалось получить ответ от сервером") | ||
} catch (exc: Exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь будет также пойман CancellationException, через который работает механизм отмены. Нужно его пробросить дальше, либо не ловить такой общий тип исключений
private val serviceCatImage: CatsService | ||
): ViewModel() { | ||
|
||
var result: MutableLiveData<CatsResult> = MutableLiveData() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Наружу нужно показывать иммутабельную версию лайвдаты/стейтфлоу
viewModelScope.launch(exceptionHandler) { | ||
val catFact = async { serviceCatFact.getCatFact() } | ||
val catImage = async { serviceCatImage.getCatImage() } | ||
result.postValue(CatsResult.Success(CatModel(catFact.await().fact, catImage.await().url))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
А зачем тут postValue, ты же уже на главный поток вернулась
} | ||
|
||
fun onInitComplete() { | ||
viewModelScope.launch(exceptionHandler) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Добавь обработку исключений через try/catch
No description provided.