Skip to content

BasicArchitecture homevork1#27

Open
SpiritualAdviser wants to merge 28 commits intoAndroid-Developer-Basic:masterfrom
SpiritualAdviser:master
Open

BasicArchitecture homevork1#27
SpiritualAdviser wants to merge 28 commits intoAndroid-Developer-Basic:masterfrom
SpiritualAdviser:master

Conversation

@SpiritualAdviser
Copy link

I made a user registration. I decided to write my own validation for 18+, there may be standard solutions, but I didn't have time to look for them. I divided the hobby cards into groups, maybe increased the code, but I'll leave it that way, I'll play with the visual design in the future. I also made them display using androidx.constraintlayout.helper.widget.Flow and CardView have been wanting to try these components for a long time. I didn't quite understand the place where I could use LiveData or StateFlow and decided to make only the button visible. I also didn't use viewBinding, I wanted to work with the ID search.

@SpiritualAdviser
Copy link
Author

I added the AutoCompleteTextView component to the address entry page with the autocomplete field. After entering the 4th character, we show a list of options. I used Retrofit. I save the key using the secrets-gradle-plugin. Perhaps the adapter for AutoCompleteTextView could be made more elegant.

count: Int
) {

if (s.length > 3) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

То есть, насколько я понял, у вас список предложений, который сейчас в модели находится, устанавливается в список предложений? Мне кажется, это предложения от прошлого изменения строки поиска (см ниже)

Copy link
Author

Choose a reason for hiding this comment

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

Тут, возможно и прошлое цепанулось гляну по возможности. Тоже не совсем понял вопроса)

Copy link
Author

Choose a reason for hiding this comment

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

Тут логика такая, при вводе больше 3х букв в поле мы кидаем запрос серверу при ответе мы результат пишем в вью модель, наверное смутило то что я использую доп переменную во вью модели для этого, можно и сразу в адаптер написать. После 4х букв мы начинаем показывать подсказки.

if (result.isSuccessful) {
result.body()?.let {
it.suggestions.forEach { address ->
addressDataArray.add(address.value)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Вы пишите найденные значения в список. А как UI узнает, что список поменялся?

Copy link
Author

Choose a reason for hiding this comment

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

На сколько я понял, адаптер принимает готовый список строк, потому я просто использую во вью модели список адресов чисто для адаптера. Возможно адаптер может и цеплять лайвдату какую ни будь и менять на лету. Но у меня он не обновлял подсказки, я пофиксил таким образом. Если так, задам вопрос на разборе.

Copy link
Author

@SpiritualAdviser SpiritualAdviser Mar 3, 2025

Choose a reason for hiding this comment

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

В момент когда компонент начнёт показывать подсказки, список уже будет получен от сервера. И так далее по шагам при добавлении по одной букве. Если не будет ответа от сервера ничего страшного, мы либо не покажем подсказку или через 2-3 буквы при успешном запросе показываем подсказки. Для такой логики лайвдаты или флоу не нужны. Да и с адаптером у меня не получилось подружить их.

import javax.inject.Inject
import javax.inject.Singleton

@Singleton
Copy link
Collaborator

Choose a reason for hiding this comment

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

Зачем тут синглтон?

Copy link
Author

@SpiritualAdviser SpiritualAdviser Mar 3, 2025

Choose a reason for hiding this comment

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

Действительно не нужен там синглтон, надо убрать пусть пересоздается каждый раз. Хоть и ничего страшного вроде он не сделает)

@SpiritualAdviser
Copy link
Author

I wrote unit tests for an input validation function or model on the first screen.
I have covered the ViewModel with unit tests, which makes a request to the network and processes the response. I used mockwebserver to replace the server operation.

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