diff --git a/app/src/main/java/com/easyhz/picly/view/MainFragment.kt b/app/src/main/java/com/easyhz/picly/view/MainFragment.kt index 375c95f..3a8f8c0 100644 --- a/app/src/main/java/com/easyhz/picly/view/MainFragment.kt +++ b/app/src/main/java/com/easyhz/picly/view/MainFragment.kt @@ -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() { @@ -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 { diff --git a/app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt b/app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt index 1de18f0..a63f069 100644 --- a/app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt +++ b/app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt @@ -128,6 +128,7 @@ class AlbumFragment: Fragment() { private fun refresh() { binding.swipeRefresh.setOnRefreshListener { viewModel.fetchAlbums() + viewModel.setSwipe(true) } } } \ No newline at end of file diff --git a/app/src/main/java/com/easyhz/picly/view/album/AlbumViewModel.kt b/app/src/main/java/com/easyhz/picly/view/album/AlbumViewModel.kt index 10ab76c..af102fd 100644 --- a/app/src/main/java/com/easyhz/picly/view/album/AlbumViewModel.kt +++ b/app/src/main/java/com/easyhz/picly/view/album/AlbumViewModel.kt @@ -26,6 +26,10 @@ class AlbumViewModel val searchText : LiveData get() = _searchText + private val _isSwipe = MutableLiveData(false) + val isSwipe : LiveData + get() = _isSwipe + fun fetchAlbums() = viewModelScope.launch { albumUseCase().distinctUntilChanged().collectLatest { albumsLiveData.value = it.toAlbumItem() @@ -35,4 +39,8 @@ class AlbumViewModel fun setSearchText(value: String) { _searchText.value = value } + + fun setSwipe(value: Boolean) { + _isSwipe.value = value + } } \ No newline at end of file