-
Notifications
You must be signed in to change notification settings - Fork 237
HW Sokolova_coroutines #156
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?
HW Sokolova_coroutines #156
Conversation
2d783f3
to
9d47eed
Compare
9d47eed
to
fcdfbfb
Compare
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.
В целом - нормально. Ещё чуть поправить и будет хорошо.
68f873a
to
b074ef4
Compare
b074ef4
to
796be51
Compare
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.
всё хорошо
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.
всё хорошо
private val factService: CatsFactService, | ||
private val imageService: CatsImageService | ||
) : ViewModel() { | ||
val catModel = MutableLiveData<Result>() |
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.
Мутабельные стримы: лайвдата, стейтфлоу и тп делают приватными(обычно). Это для того чтобы у тебя в стрим мог эмитить только 1 класс, а не все у кого есть ссылка на CatViewModel.
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.
d
is SocketTimeoutException -> { | ||
catModel.value = Result.Error(Throwable(Resources.getSystem().getString(R.string.error_connection))) | ||
} | ||
is CancellationException -> { |
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.
в CoroutineExceptionHandler
этого можно не делать, справедливо только для обычного catch
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.
d, унесла в try/catch
|
||
private val handler = CoroutineExceptionHandler { _, throwable -> | ||
when (throwable) { | ||
is SocketTimeoutException -> { |
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. Тут оставил только необработанные
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.
d
|
||
override fun onCleared() { | ||
super.onCleared() | ||
viewModelScope.cancel() |
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 сам будет очищен в onCleared
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.
d
interface CatsFactService { | ||
|
||
@GET("fact") | ||
suspend fun getCatFact() : Response<Fact> |
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.
Я бы просто Fact оставил
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.
d, для картинок сделала аналогично
override fun onResponse(call: Call<Fact>, response: Response<Fact>) { | ||
if (response.isSuccessful && response.body() != null) { | ||
_catsView?.populate(response.body()!!) | ||
runBlocking(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.
Зачем здесь runBlocking
? Его вообще кроме как в тестах использовать нигде не нужно
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.
d
|
||
fun onStop(){ | ||
catsScope.cancel() |
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.
А почему это не перенести в detachView, ты же onStop вызываешь в onStop ЖЦ
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.
d
No description provided.