Skip to content

Commit

Permalink
Merge pull request #320 from lzaytseva/GTJ-319
Browse files Browse the repository at this point in the history
добавлены иконки сброса текста в edit text'ах места работы и индустрии
  • Loading branch information
lzaytseva authored Dec 26, 2023
2 parents fef0c5a + 0beaa6a commit d8798b2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,28 @@ class FiltersViewModel @Inject constructor(
currentFilters = updatedFilters
}
}

fun clearPlace() {
viewModelScope.launch {
val updatedFilters = currentFilters?.copy(
countryId = null,
countryName = null,
regionId = null,
regionName = null
)
saveFiltersRepository.save(updatedFilters)
currentFilters = updatedFilters
}
}

fun clearIndustry() {
viewModelScope.launch {
val updatedFilters = currentFilters?.copy(
industryId = null,
industryName = null
)
saveFiltersRepository.save(updatedFilters)
currentFilters = updatedFilters
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class FiltersFragment : BindingFragment<FragmentFiltersBinding>() {
override fun onResume() {
super.onResume()
(requireActivity() as RootActivity).toolbar.setNavigationIcon(R.drawable.ic_arrow_back)
setFilterFieldsEndIcon()
}

private fun observeViewModel() {
Expand Down Expand Up @@ -185,6 +186,7 @@ class FiltersFragment : BindingFragment<FragmentFiltersBinding>() {
textInputEditText.doOnTextChanged { _, _, _, _ ->
setFilterEndIcon(textInputLayout, textInputEditText)
setFilterHintColor(textInputLayout, textInputEditText)
updateButtonsVisibility()
}
}

Expand All @@ -211,17 +213,38 @@ class FiltersFragment : BindingFragment<FragmentFiltersBinding>() {
}

private fun setFilterEndIcon(textInputLayout: TextInputLayout, textInputEditText: TextInputEditText) {
val isTextFieldEmpty = textInputEditText.text.isNullOrBlank()
textInputLayout.endIconDrawable = TextInputLayoutUtils.getEndIconDrawable(
context = requireContext(),
iconResId = getEndIconId(isTextFieldEmpty = textInputEditText.text.isNullOrBlank())
iconResId = getEndIconId(isTextFieldEmpty = isTextFieldEmpty)
)
if (!isTextFieldEmpty) {
textInputLayout.setEndIconOnClickListener {
textInputEditText.text?.clear()
if (textInputEditText.id == R.id.et_place) {
viewModel.clearPlace()
}
if (textInputEditText.id == R.id.et_industry) {
viewModel.clearIndustry()
}
}
} else {
textInputLayout.setEndIconOnClickListener {
if (textInputEditText.id == R.id.et_place) {
findNavController().navigate(R.id.action_filtersFragment_to_choiceWorkplaceFragment2)
}
if (textInputEditText.id == R.id.et_industry) {
findNavController().navigate(R.id.action_filtersFragment_to_choiceIndustryFragment)
}
}
}
}

private fun getEndIconId(isTextFieldEmpty: Boolean): Int? {
private fun getEndIconId(isTextFieldEmpty: Boolean): Int {
return if (isTextFieldEmpty) {
R.drawable.ic_arrow_forward
} else {
null
R.drawable.ic_clear
}
}

Expand Down

0 comments on commit d8798b2

Please sign in to comment.