Skip to content

BasicArchitecture задание 1#33

Open
Gbdr73 wants to merge 5 commits intoAndroid-Developer-Basic:masterfrom
Gbdr73:master
Open

BasicArchitecture задание 1#33
Gbdr73 wants to merge 5 commits intoAndroid-Developer-Basic:masterfrom
Gbdr73:master

Conversation

@Gbdr73
Copy link

@Gbdr73 Gbdr73 commented Dec 11, 2025

No description provided.

}

fun searchAddress(query: String) {
viewModelScope.launch {

Choose a reason for hiding this comment

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

Давайте попробуем предусмотреть отмену корутин. Сохраняйте Job текущего запроса и отменяйте его перед запуском нового, чтобы избежать лишних запросов и race conditions, когда результаты могут прийти в неправильном порядке


if (!response.isSuccessful){
val errorResponse = response.errorBody()?.string()
Log.e("API Error", "Error response: $errorResponse")

Choose a reason for hiding this comment

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

Лучше еще пробрасывать исключение при неуспешном ответе, чтобы ВМ могла корректно обработать ошибку и показать пользователю сообщение.

}

binding.addressInput.setOnItemClickListener { _, _, position, _ ->
val selectedItem = binding.addressInput.adapter.getItem(position) as? UserAddress

Choose a reason for hiding this comment

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

Адаптер хранит строки, но вы пытаетесь получить UserAddress. Это приведет к ClassCastException при выборе элемента из списка. Можно использовать кастомный ArrayAdapter для UserAddress или храните маппинг между строками и объектами UserAddress, чтобы при выборе можно было получить полный объект адреса.

Copy link
Author

Choose a reason for hiding this comment

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

Странно. Попробовал выбирать элемент списка - в Logcat никакого Exception нет.


private fun checkEmptyFields(): Boolean{
var successful = true
if (wizardCache.userAddress.fullAddress == ""){

Choose a reason for hiding this comment

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

isBlank учитывает строки, состоящие только из пробелов, что делает валидацию более надежной

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

Comments