Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 검색 뷰 상품열 조정 기능 구현 #32

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import androidx.fragment.app.viewModels
import androidx.lifecycle.flowWithLifecycle
import androidx.lifecycle.lifecycleScope
import androidx.navigation.fragment.findNavController
import androidx.recyclerview.widget.ConcatAdapter
import androidx.recyclerview.widget.GridLayoutManager
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.sopt.kream.R
Expand All @@ -41,46 +41,48 @@ import org.sopt.kream.util.view.UiState
class SearchFragment : BindingFragment<FragmentSearchBinding>({ FragmentSearchBinding.inflate(it) }) {
private val searchViewModel: SearchViewModel by viewModels { ViewModelFactory() }
private lateinit var findName: String
private lateinit var searchTopBarAdapter: SearchTopBarAdapter
private lateinit var searchRelatedSearchWordListAdapter: SearchRelatedSearchWordListAdapter
private lateinit var searchRelateRecommendProductListAdapter: SearchRelateRecommendProductListAdapter
private lateinit var firstSearchSearchFindProductListAdapter: SearchSearchFindProductListAdapter
private lateinit var secondSearchSearchFindProductListAdapter: SearchSearchFindProductListAdapter
private lateinit var searchRelatedSearchWordAdapter: SearchRelatedSearchWordAdapter
private lateinit var searchRelateRecommendProductAdapter: SearchRelateRecommendProductAdapter
private lateinit var searchSearchFindProductAdapter: SearchSearchFindProductAdapter
private lateinit var rvSearchSearchFindProductListLayoutManager: GridLayoutManager
private lateinit var rvSearchSearchFindProductListSecondLayoutManager: GridLayoutManager

override fun onViewCreated(
view: View,
savedInstanceState: Bundle?,
) {
super.onViewCreated(view, savedInstanceState)

initTop()
initAdapter()
findName = getSearchWord()
rvSearchSearchFindProductListLayoutManager = GridLayoutManager(requireContext(), SPAN_COUNT_2)
rvSearchSearchFindProductListSecondLayoutManager = GridLayoutManager(requireContext(), SPAN_COUNT_2)
searchViewModel.getSearchProduct(findName = findName)
initLayout()
initAdapter()
collectSearchProductState()
setIvSearchTopBarProductSortingClickListener()
}

private fun initTop() {
private fun initLayout() {
binding.cvSearchTop.setContent {
TopLayout()
}
binding.tvSearchRelateRecommendProductListSearchWord.text = findName
}

private fun initAdapter() {
searchTopBarAdapter = SearchTopBarAdapter()
searchRelatedSearchWordListAdapter = SearchRelatedSearchWordListAdapter()
searchRelateRecommendProductListAdapter = SearchRelateRecommendProductListAdapter(::navigateToProductDetail)
firstSearchSearchFindProductListAdapter = SearchSearchFindProductListAdapter(::navigateToProductDetail)
secondSearchSearchFindProductListAdapter = SearchSearchFindProductListAdapter(::navigateToProductDetail)

binding.rvSearch.adapter =
ConcatAdapter(
searchTopBarAdapter,
firstSearchSearchFindProductListAdapter,
searchRelatedSearchWordListAdapter,
secondSearchSearchFindProductListAdapter,
searchRelateRecommendProductListAdapter,
)
searchRelatedSearchWordAdapter = SearchRelatedSearchWordAdapter()
searchRelateRecommendProductAdapter = SearchRelateRecommendProductAdapter(::navigateToProductDetail)
searchSearchFindProductAdapter = SearchSearchFindProductAdapter(::navigateToProductDetail)

with(binding) {
rvSearchRelatedSearchWordList.adapter = searchRelatedSearchWordAdapter
rvSearchRelatedProductList.adapter = searchRelateRecommendProductAdapter
rvSearchSearchFindProductList.adapter = searchSearchFindProductAdapter
rvSearchSearchFindProductListSecond.adapter = searchSearchFindProductAdapter
}

searchRelatedSearchWordAdapter.submitList(searchViewModel.relatedSearchWordList)
}

private fun collectSearchProductState() {
Expand All @@ -89,11 +91,8 @@ class SearchFragment : BindingFragment<FragmentSearchBinding>({ FragmentSearchBi
when (searchProductState) {
is UiState.Success -> {
with(searchProductState.data) {
searchTopBarAdapter.submitList(listOf(Unit))
searchRelatedSearchWordListAdapter.submitList(listOf(searchViewModel.relatedSearchWordList))
firstSearchSearchFindProductListAdapter.submitList(listOf(searchFindProducts))
secondSearchSearchFindProductListAdapter.submitList(listOf(searchFindProducts))
searchRelateRecommendProductListAdapter.submitList(listOf(Pair(relateRecommendProducts, findName)))
searchRelateRecommendProductAdapter.submitList(relateRecommendProducts)
searchSearchFindProductAdapter.submitList(searchFindProducts)
}
}

Expand All @@ -102,6 +101,23 @@ class SearchFragment : BindingFragment<FragmentSearchBinding>({ FragmentSearchBi
}.launchIn(viewLifecycleOwner.lifecycleScope)
}

private fun setIvSearchTopBarProductSortingClickListener() {
binding.ivSearchTopBarProductSorting.setOnClickListener {
rvSearchSearchFindProductListLayoutManager.run {
spanCount = if (spanCount == SPAN_COUNT_2) SPAN_COUNT_3 else SPAN_COUNT_2
}

rvSearchSearchFindProductListSecondLayoutManager.run {
spanCount = if (spanCount == SPAN_COUNT_2) SPAN_COUNT_3 else SPAN_COUNT_2
}

with(binding) {
rvSearchSearchFindProductList.layoutManager = rvSearchSearchFindProductListLayoutManager
rvSearchSearchFindProductListSecond.layoutManager = rvSearchSearchFindProductListSecondLayoutManager
}
}
}

@Composable
private fun TopLayout() {
var selectedTabPosition by remember { mutableIntStateOf(DEFAULT_SELECTED_TAB_POSITION) }
Expand Down Expand Up @@ -151,5 +167,7 @@ class SearchFragment : BindingFragment<FragmentSearchBinding>({ FragmentSearchBi
companion object {
const val DEFAULT_SELECTED_TAB_POSITION = 0
const val PRODUCT_ID = "productId"
const val SPAN_COUNT_2 = 2
const val SPAN_COUNT_3 = 3
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading
Loading