From cddc490684e0c7d9f3fb2250e0a196780c9ba1b5 Mon Sep 17 00:00:00 2001 From: easyhz Date: Mon, 8 Apr 2024 23:47:13 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EB=8B=A4=EC=8B=9C=20=EC=BD=9C=EB=B0=B1?= =?UTF-8?q?=EC=9C=BC=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ㅠㅠ --- .../java/com/easyhz/picly/view/MainFragment.kt | 1 + .../com/easyhz/picly/view/album/AlbumAdapter.kt | 15 ++------------- .../com/easyhz/picly/view/album/AlbumFragment.kt | 11 ++++------- 3 files changed, 7 insertions(+), 20 deletions(-) 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 4e3c1aa..375c95f 100644 --- a/app/src/main/java/com/easyhz/picly/view/MainFragment.kt +++ b/app/src/main/java/com/easyhz/picly/view/MainFragment.kt @@ -116,6 +116,7 @@ class MainFragment:Fragment() { private fun resetSearchBar() { binding.toolbar.apply { searchEditText.setText("") + viewModel.setSearchText("") searchEditText.clearFocus() val layoutParams = ConstraintLayout.LayoutParams(112.toPx(requireContext()), searchEditText.height) layoutParams.apply { diff --git a/app/src/main/java/com/easyhz/picly/view/album/AlbumAdapter.kt b/app/src/main/java/com/easyhz/picly/view/album/AlbumAdapter.kt index ce452c7..5058248 100644 --- a/app/src/main/java/com/easyhz/picly/view/album/AlbumAdapter.kt +++ b/app/src/main/java/com/easyhz/picly/view/album/AlbumAdapter.kt @@ -9,17 +9,14 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.easyhz.picly.databinding.ItemAlbumBinding import com.easyhz.picly.domain.model.album.AlbumItem -import com.easyhz.picly.domain.model.album.SearchData -import kotlin.coroutines.resume -import kotlin.coroutines.suspendCoroutine class AlbumAdapter( + private val noResult: (Boolean , String) -> Unit, private val onClickLinkButton: (AlbumItem) -> Unit, private val onClickListener: (AlbumItem) -> Unit, ):RecyclerView.Adapter(), Filterable { var originalList: List = listOf() private val postFiler = PostFilter() - private var searchData = SearchData() inner class AlbumViewHolder(val binding: ItemAlbumBinding) : RecyclerView.ViewHolder(binding.root) @@ -82,16 +79,8 @@ class AlbumAdapter( override fun publishResults(constraint: CharSequence?, results: FilterResults?) { val filteredList = results?.values as? List ?: emptyList() - searchData.apply { - this.isEmpty = filteredList.isEmpty() - this.string = constraint.toString() - } + noResult(filteredList.isEmpty(), constraint.toString()) differ.submitList(filteredList) } } - suspend fun getSearchData(): SearchData { - return suspendCoroutine { continuation -> - continuation.resume(searchData) - } - } } \ No newline at end of file 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 0c0a483..1de18f0 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 @@ -63,6 +63,7 @@ class AlbumFragment: Fragment() { private fun setRecyclerView() { albumAdapter = AlbumAdapter( + noResult = { isEmpty, s -> setNoResult(isEmpty, s) }, onClickLinkButton = { onClickLinkButton(it) } ) { NavControllerManager.navigateMainToDetail(it) @@ -90,9 +91,6 @@ class AlbumFragment: Fragment() { private fun observeSearchText() { viewModel.searchText.observe(viewLifecycleOwner) { albumAdapter.filter.filter(it) - CoroutineScope(Dispatchers.Main).launch { - setNoResult() - } } } @@ -107,10 +105,9 @@ class AlbumFragment: Fragment() { clipboardManager.setPrimaryClip(clipData) BlueSnackBar.make(binding.root, getString(R.string.link_copy)).show() } - private suspend fun setNoResult() { - val searchData = albumAdapter.getSearchData() - if (searchData.string.isEmpty() && albumAdapter.originalList.isEmpty()) updateNoResultMessage(true, getString(R.string.no_data_text)) - else updateNoResultMessage(searchData.isEmpty, getString(R.string.no_search_text)) + private fun setNoResult(isEmpty: Boolean, s: String) { + if (s.isEmpty() && albumAdapter.originalList.isEmpty()) updateNoResultMessage(true, getString(R.string.no_data_text)) + else updateNoResultMessage(isEmpty, getString(R.string.no_search_text)) } private fun updateNoResultMessage(isEmpty: Boolean, message: String) {