Skip to content

Реализовано вторая часть ДЗ по сетям.#35

Open
uatilman wants to merge 22 commits intoAndroid-Developer-Basic:masterfrom
uatilman:task2
Open

Реализовано вторая часть ДЗ по сетям.#35
uatilman wants to merge 22 commits intoAndroid-Developer-Basic:masterfrom
uatilman:task2

Conversation

@uatilman
Copy link

Добрый день!
Что касается сетей, все реализовано. Однако скорее всего проблемы с Hilt. Все работает, но не понял как сделать addressSuggestUseCase unscope, как написано в лекции.

_state.emit(LoadAddressesViewState.AddressSelected)
}

fun loadAddressVariants(rawAddress: String) {
Copy link

@Lufavetskaya Lufavetskaya Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

При быстром вводе запускаются множественные запросы, предыдущие не отменяются. Это создает лишнюю нагрузку, и может привести к страшной и ужасной гонки. Добавьте переменную searchJob и отменяйте предыдущий запрос через searchJob?.cancel() перед запуском нового. И можно уменьшить количество запросов через delay

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил отмену job, а задержку вынес в property файл


is LoadAddressesViewState.LoadAddresses -> {
addressVariants.isVisible = false
loadIndicator.isVisible = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше обработать тут наш it и вывести пользователю информацию если ошибка

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил поле для вывода ошибки.

println("addressVariants: \n${addressVariants.joinToString("\n")}")
_state.emit(LoadAddressesViewState.Content(addressVariants))
}.getOrElse {
_state.emit(LoadAddressesViewState.LoadAddresses(it as Exception))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать безопасно as? Exception

Copy link
Author

@uatilman uatilman Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено.

private fun setupRecyclerView() = binding.withBinding { addressVariants.adapter = adapter }

private fun collectToSelectedFlow() {
viewModel.state.onEach {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Создает новую подписку на addressFlow при каждом изменении state. Подпишитесь на addressFlow отдельно, без вложености

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Исправлено.

import jakarta.inject.Inject
import ru.otus.basicarchitecture.service.DaDataService

@ViewModelScoped

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

аннотация области видимости на интерфейсе не влияет на создание экземпляров. Область видимости задается на методе @BINDS в модуле.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Удалил.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants