From 4f2a8ef7323f8ecce10b2538e341de0a404e3b3e Mon Sep 17 00:00:00 2001 From: easyhz Date: Tue, 9 Apr 2024 17:25:06 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20swipe=20=EC=8B=9C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=B0=BD=20=EB=A6=AC=EC=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/easyhz/picly/view/MainFragment.kt | 15 +++++++++++++++ .../com/easyhz/picly/view/album/AlbumFragment.kt | 1 + .../com/easyhz/picly/view/album/AlbumViewModel.kt | 8 ++++++++ 3 files changed, 24 insertions(+) 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