Skip to content

Commit

Permalink
fix: swipe 시 검색창 리셋
Browse files Browse the repository at this point in the history
  • Loading branch information
easyhz committed Apr 9, 2024
1 parent a07d3a2 commit 4f2a8ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/src/main/java/com/easyhz/picly/view/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,15 @@ class MainFragment:Fragment() {
super.onViewCreated(view, savedInstanceState)
setUp()
}

override fun onPause() {
super.onPause()
resetSearchBar()
}

private fun setUp() {
fetchAlbums()
observeIsSwipe()
}

private fun setNavigation() {
Expand Down Expand Up @@ -85,6 +92,14 @@ class MainFragment:Fragment() {
viewModel.fetchAlbums()
}

private fun observeIsSwipe() {
viewModel.isSwipe.observe(viewLifecycleOwner) {
if (it) {
resetSearchBar()
viewModel.setSwipe(false)
}
}
}
private fun setSearchBar() {
binding.toolbar.apply {
searchCancelButton.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AlbumFragment: Fragment() {
private fun refresh() {
binding.swipeRefresh.setOnRefreshListener {
viewModel.fetchAlbums()
viewModel.setSwipe(true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class AlbumViewModel
val searchText : LiveData<String>
get() = _searchText

private val _isSwipe = MutableLiveData<Boolean>(false)
val isSwipe : LiveData<Boolean>
get() = _isSwipe

fun fetchAlbums() = viewModelScope.launch {
albumUseCase().distinctUntilChanged().collectLatest {
albumsLiveData.value = it.toAlbumItem()
Expand All @@ -35,4 +39,8 @@ class AlbumViewModel
fun setSearchText(value: String) {
_searchText.value = value
}

fun setSwipe(value: Boolean) {
_isSwipe.value = value
}
}

0 comments on commit 4f2a8ef

Please sign in to comment.