Skip to content

Commit

Permalink
refactor : 텍스트 클리어 버튼의 기능에 맞는 네이밍 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
m6z1 committed Feb 5, 2024
1 parent f10fee0 commit cf670bf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,18 @@ class SearchFragment : BaseFragment<FragmentSearchBinding, SearchViewModel>() {
}

override fun afterTextChanged(s: Editable?) {
viewModel.validateSearchContent()
viewModel.validateSearchClearButtonVisibility()
}
})

viewModel.searchValidation.observe(viewLifecycleOwner) { isValid ->
binding.ivSearchCancel.visibility = if (isValid) View.VISIBLE else View.GONE
viewModel.searchClearVisibility.observe(viewLifecycleOwner) { isValid ->
binding.ivSearchClear.visibility = if (isValid) View.VISIBLE else View.GONE
}
}

private fun setTextClearButtonClickListener() {
with(binding) {
ivSearchCancel.setOnClickListener {
ivSearchClear.setOnClickListener {
etSearchBar.text.clear()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ class SearchViewModel : BaseViewModel() {
private val _searchContent: MutableLiveData<String> = MutableLiveData()
val searchContent: MutableLiveData<String> = _searchContent

private val _searchValidation: MutableLiveData<Boolean> = MutableLiveData()
val searchValidation: LiveData<Boolean> = _searchValidation
private val _searchClearVisibility: MutableLiveData<Boolean> = MutableLiveData()
val searchClearVisibility: LiveData<Boolean> = _searchClearVisibility

fun validateSearchContent() {
_searchValidation.value = !_searchContent.value.isNullOrEmpty()
fun validateSearchClearButtonVisibility() {
_searchClearVisibility.value = !_searchContent.value.isNullOrEmpty()
}
}
6 changes: 3 additions & 3 deletions app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@
android:textColor="@color/blue300"
android:textColorHint="@color/gray300"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@id/iv_search_cancel"
app:layout_constraintEnd_toEndOf="@id/iv_search_clear"
app:layout_constraintStart_toEndOf="@id/iv_search_icon"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/iv_search_cancel"
android:id="@+id/iv_search_clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
android:padding="12dp"
android:src="@drawable/ic_search_cancel"
android:src="@drawable/ic_search_clear"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down

0 comments on commit cf670bf

Please sign in to comment.