Skip to content

Commit

Permalink
fix: 다시 콜백으로 변경
Browse files Browse the repository at this point in the history
ㅠㅠ
  • Loading branch information
easyhz committed Apr 8, 2024
1 parent c58b2b9 commit cddc490
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 20 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/com/easyhz/picly/view/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 2 additions & 13 deletions app/src/main/java/com/easyhz/picly/view/album/AlbumAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<AlbumAdapter.AlbumViewHolder>(), Filterable {
var originalList: List<AlbumItem> = listOf()
private val postFiler = PostFilter()
private var searchData = SearchData()

inner class AlbumViewHolder(val binding: ItemAlbumBinding) : RecyclerView.ViewHolder(binding.root)

Expand Down Expand Up @@ -82,16 +79,8 @@ class AlbumAdapter(

override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
val filteredList = results?.values as? List<AlbumItem> ?: 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<SearchData> { continuation ->
continuation.resume(searchData)
}
}
}
11 changes: 4 additions & 7 deletions app/src/main/java/com/easyhz/picly/view/album/AlbumFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class AlbumFragment: Fragment() {

private fun setRecyclerView() {
albumAdapter = AlbumAdapter(
noResult = { isEmpty, s -> setNoResult(isEmpty, s) },
onClickLinkButton = { onClickLinkButton(it) }
) {
NavControllerManager.navigateMainToDetail(it)
Expand Down Expand Up @@ -90,9 +91,6 @@ class AlbumFragment: Fragment() {
private fun observeSearchText() {
viewModel.searchText.observe(viewLifecycleOwner) {
albumAdapter.filter.filter(it)
CoroutineScope(Dispatchers.Main).launch {
setNoResult()
}
}
}

Expand All @@ -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) {
Expand Down

0 comments on commit cddc490

Please sign in to comment.