From a2362a2da8655dbd4d019eb12a2634c0b53ae350 Mon Sep 17 00:00:00 2001 From: BeomBeom2 Date: Sat, 23 Nov 2024 15:04:04 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[Refactor]=20=EB=BD=91=EA=B8=B0=20=EA=B2=B0?= =?UTF-8?q?=EA=B3=BC=20=EC=95=A0=EB=8B=88=EB=A9=94=EC=9D=B4=EC=85=98=20UI?= =?UTF-8?q?=20=EC=88=98=EC=A0=95=20=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No Related Issue --- .idea/deploymentTargetSelector.xml | 8 ++ ...esultFragment.kt => DrawResultFragment.kt} | 77 ++++++++++++++----- .../ui/draw/DrawSelectCategoryFragment.kt | 5 +- .../ui/draw/DrawSelectResultAdapter.kt | 33 +------- .../presentation/ui/draw/DrawViewModel.kt | 10 +-- ...none.xml => all_radius_30_signature_1.xml} | 5 +- ...ct_result.xml => fragment_draw_result.xml} | 47 ++++++++--- .../layout/item_draw_select_result_img.xml | 18 ++--- app/src/main/res/values/dimens.xml | 1 - 9 files changed, 120 insertions(+), 84 deletions(-) rename app/src/main/java/com/kust/kustaurant/presentation/ui/draw/{DrawSelectResultFragment.kt => DrawResultFragment.kt} (75%) rename app/src/main/res/drawable/{all_radius_30_none.xml => all_radius_30_signature_1.xml} (51%) rename app/src/main/res/layout/{fragment_draw_select_result.xml => fragment_draw_result.xml} (86%) diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..de580ed 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -4,6 +4,14 @@ diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt similarity index 75% rename from app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultFragment.kt rename to app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt index 4a92f43..7cffe33 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultFragment.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt @@ -3,9 +3,9 @@ package com.kust.kustaurant.presentation.ui.draw import android.animation.ObjectAnimator import android.annotation.SuppressLint import android.content.Intent +import android.content.res.Resources import android.graphics.drawable.GradientDrawable import android.os.Bundle -import android.os.Handler import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -15,31 +15,31 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 +import com.bumptech.glide.Glide +import com.bumptech.glide.load.resource.bitmap.CenterCrop +import com.bumptech.glide.load.resource.bitmap.RoundedCorners import com.kust.kustaurant.R import com.kust.kustaurant.data.model.DrawRestaurantData -import com.kust.kustaurant.databinding.FragmentDrawSelectResultBinding +import com.kust.kustaurant.databinding.FragmentDrawResultBinding import com.kust.kustaurant.presentation.ui.detail.DetailActivity import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.cancel import kotlinx.coroutines.delay import kotlinx.coroutines.launch -import kotlin.math.abs import kotlin.math.floor -class DrawSelectResultFragment : Fragment() { - private var _binding: FragmentDrawSelectResultBinding? = null +class DrawResultFragment : Fragment() { + private var _binding: FragmentDrawResultBinding? = null private lateinit var viewPager: ViewPager2 private lateinit var adapter: DrawSelectResultAdapter private var restaurantList = mutableListOf() private val viewModel: DrawViewModel by activityViewModels() - private var handler: Handler? = null - private var runnable: Runnable? = null val binding get() = _binding!! private val animationScope = CoroutineScope(Dispatchers.Main) override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { - _binding = FragmentDrawSelectResultBinding.inflate(inflater, container, false) + _binding = FragmentDrawResultBinding.inflate(inflater, container, false) setupViewPager() loadRestaurants() setupButton() @@ -57,33 +57,37 @@ class DrawSelectResultFragment : Fragment() { viewModel.selectedRestaurant.observe(viewLifecycleOwner) { selected -> if (_binding == null) { - _binding = FragmentDrawSelectResultBinding.inflate(layoutInflater) + _binding = FragmentDrawResultBinding.inflate(layoutInflater) } displaySelectedRestaurantInfo(selected) } } - @SuppressLint("SetTextI18n") private fun displaySelectedRestaurantInfo(restaurant: DrawRestaurantData) { binding.drawTvRestaurantName.text = restaurant.restaurantName binding.drawTvRestaurantMenu.text = restaurant.restaurantCuisine - } private fun setupViewPager() { + val viewPagerHeight = calculateViewHeight(267f) // 동적 높이 계산 + viewPager = binding.drawViewPager adapter = DrawSelectResultAdapter(restaurantList) viewPager.adapter = adapter viewPager.isUserInputEnabled = false // 스크롤 비활성화 viewPager.offscreenPageLimit = 1 + + // ViewPager의 높이를 동적으로 설정 + viewPager.layoutParams = viewPager.layoutParams.apply { + height = viewPagerHeight + } + + // 페이지 전환 애니메이션 설정 val pageTransformer = ViewPager2.PageTransformer { page, position -> - val absPosition = abs(position) page.apply { - rotationY = -30 * position - scaleX = 0.8f + (1 - absPosition) * 0.2f - scaleY = scaleX + translationX = 30 * position } } viewPager.setPageTransformer(pageTransformer) @@ -118,7 +122,7 @@ class DrawSelectResultFragment : Fragment() { binding.drawTvRestaurantScore.text = "" binding.drawTvRestaurantPartnershipInfo.text = "" binding.drawLlScoreImgGroup.visibility = View.GONE - + binding.drawIvSelect.visibility = View.INVISIBLE loadRestaurants() } @@ -129,6 +133,7 @@ class DrawSelectResultFragment : Fragment() { .commit() } } + private fun loadRestaurants() { viewModel.drawRestaurants() @@ -145,7 +150,6 @@ class DrawSelectResultFragment : Fragment() { private fun highlightCenterImage() { val centerPosition = viewPager.currentItem adapter.highlightItem(centerPosition) - } private fun startAnimation() = animationScope.launch { @@ -155,7 +159,7 @@ class DrawSelectResultFragment : Fragment() { var currentPage = adapter.itemCount - 1 while (currentPage >= 0) { - if (!isAdded) return@launch // Fragment가 아직 활성 상태인지 확인 + if (!isAdded) return@launch // Fragment가 아직 활성 상태인지 확인 viewPager.setCurrentItem(currentPage, true) delay(1700L / adapter.itemCount) @@ -163,18 +167,22 @@ class DrawSelectResultFragment : Fragment() { currentPage-- } - // 애니메이션 종료 후, 중앙에 선택된 음식점 배치 + // 애니메이션 종료 후, 중앙에 선택된 음식점 배치 및 이미지 표시 viewModel.selectedRestaurant.value?.let { selected -> val selectedIndex = restaurantList.indexOf(selected) viewPager.setCurrentItem(selectedIndex, true) displaySelectedRestaurantInfo(selected) + // 선택된 음식점 정보 표시 val roundedScore = selected.restaurantScore?.let { floor(it * 2) / 2 } ?: "평가 없음" binding.drawTvRestaurantScore.text = roundedScore.toString() binding.drawTvRestaurantPartnershipInfo.text = selected.partnershipInfo ?: "제휴 해당사항 없음" updateStarRating(selected.restaurantScore ?: 0.0) binding.drawLlScoreImgGroup.visibility = View.VISIBLE + // 선택된 이미지 표시 + displaySelectedRestaurantImage(selected) + highlightCenterImage() enableButtons() @@ -184,6 +192,30 @@ class DrawSelectResultFragment : Fragment() { } } + private fun displaySelectedRestaurantImage(restaurant: DrawRestaurantData) { + val calculateHeight = calculateViewHeight(297f) + + // gl_start와 gl_end의 위치를 기준으로 너비 계산 + val startX = binding.glStart.x + val endX = binding.glEnd.x + val calculatedWidth = (endX - startX).toInt() + + // 선택된 이미지의 크기를 설정 + binding.drawIvSelect.layoutParams = binding.drawIvSelect.layoutParams.apply { + width = calculatedWidth + height = calculateHeight + } + + // Glide를 사용하여 이미지 로드 및 둥근 모서리 처리 + Glide.with(this) + .load(restaurant.restaurantImgUrl) + .transform(CenterCrop(), RoundedCorners(78)) // RoundedCorners와 CenterCrop을 조합 + .into(binding.drawIvSelect) + + binding.drawIvSelect.visibility = View.VISIBLE + } + + private fun disableButtons() { binding.drawBtnCategoryReset.isClickable = false binding.drawBtnRetry.isClickable = false @@ -208,7 +240,12 @@ class DrawSelectResultFragment : Fragment() { override fun onDestroyView() { super.onDestroyView() - animationScope.cancel() // 코루틴 취소 + animationScope.cancel() _binding = null } + + private fun calculateViewHeight(height : Float): Int { + val screenDensity = Resources.getSystem().displayMetrics.density + return (height * screenDensity).toInt() + } } \ No newline at end of file diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt index a78d0a1..ca4b346 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt @@ -7,7 +7,6 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.LinearLayout import android.widget.TextView import android.widget.ToggleButton import androidx.constraintlayout.widget.ConstraintLayout @@ -22,7 +21,7 @@ class DrawSelectCategoryFragment : Fragment() { private var _binding : FragmentDrawSelectCategoryBinding? = null private val binding get() = _binding!! private val viewModel : DrawViewModel by activityViewModels() - private var selectedMenus = mutableSetOf("전체") + private var selectedMenus = mutableSetOf("전체") private lateinit var allMenuViews: List override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, @@ -65,7 +64,7 @@ class DrawSelectCategoryFragment : Fragment() { viewModel.applyFilters(selectedMenus,selectedLocation) parentFragmentManager.beginTransaction() - .replace(R.id.draw_fragment_container, DrawSelectResultFragment()) + .replace(R.id.draw_fragment_container, DrawResultFragment()) .addToBackStack(null) .commit() } diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt index 544c7dc..7890cb7 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt @@ -1,23 +1,16 @@ package com.kust.kustaurant.presentation.ui.draw import android.content.Context -import android.graphics.drawable.GradientDrawable -import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView -import androidx.core.content.ContextCompat -import androidx.core.view.setPadding import androidx.recyclerview.widget.RecyclerView import com.bumptech.glide.Glide -import com.bumptech.glide.load.resource.bitmap.CenterCrop -import com.bumptech.glide.load.resource.bitmap.RoundedCorners -import com.bumptech.glide.request.RequestOptions import com.kust.kustaurant.R import com.kust.kustaurant.data.model.DrawRestaurantData -class DrawSelectResultAdapter(private val restaurants: MutableList) : +class DrawSelectResultAdapter(val restaurants: MutableList) : RecyclerView.Adapter() { private var highlightedPosition: Int = RecyclerView.NO_POSITION @@ -30,31 +23,8 @@ class DrawSelectResultAdapter(private val restaurants: MutableList>() val drawList: LiveData> = _drawList private var sameDrawList = 3 - // LiveData for storing selected filters - private val _selectedMenus = MutableLiveData>(setOf("전체")) + private val _selectedMenus = MutableLiveData(setOf("전체")) val selectedMenus: LiveData> = _selectedMenus - private val _selectedLocations = MutableLiveData>(setOf("전체")) + private val _selectedLocations = MutableLiveData(setOf("전체")) val selectedLocations: LiveData> = _selectedLocations private var _initialSelectedMenus = setOf("전체") @@ -38,7 +37,6 @@ class DrawViewModel @Inject constructor( (selectedLocations.value == _initialSelectedLocations) if (checkSameCategory && sameDrawList < 2) { - Log.d("DrawViewModel", "just random algorithm") sameDrawList++ _drawList.value?.let { currentList -> if (currentList.isNotEmpty()) { @@ -48,7 +46,6 @@ class DrawViewModel @Inject constructor( } } } else { - Log.d("DrawViewModel", "draw Restaurants from Backend") sameDrawList = 0 val mappedMenus = selectedMenus.value?.let { CategoryIdMapper.mapMenus(it) } @@ -65,9 +62,6 @@ class DrawViewModel @Inject constructor( val selected = getRandomRestaurants(drawRestaurantsListData) _selectedRestaurant.value = selected updateSelectedIndex(drawRestaurantsListData, selected) - - Log.d("DrawViewModel", "Draw restaurant data: $drawRestaurantsListData") - Log.d("DrawViewModel", "Draw selected restaurant data: $selectedRestaurant") } else { Log.e("DrawViewModel", "Menus or Locations mapping failed. Menus: $mappedMenus, Locations: $mappedLocations") } diff --git a/app/src/main/res/drawable/all_radius_30_none.xml b/app/src/main/res/drawable/all_radius_30_signature_1.xml similarity index 51% rename from app/src/main/res/drawable/all_radius_30_none.xml rename to app/src/main/res/drawable/all_radius_30_signature_1.xml index 160bc52..2e8cfb7 100644 --- a/app/src/main/res/drawable/all_radius_30_none.xml +++ b/app/src/main/res/drawable/all_radius_30_signature_1.xml @@ -1,4 +1,7 @@ - + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_draw_select_result.xml b/app/src/main/res/layout/fragment_draw_result.xml similarity index 86% rename from app/src/main/res/layout/fragment_draw_select_result.xml rename to app/src/main/res/layout/fragment_draw_result.xml index 0644d52..0cb4444 100644 --- a/app/src/main/res/layout/fragment_draw_select_result.xml +++ b/app/src/main/res/layout/fragment_draw_result.xml @@ -3,8 +3,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" + android:layout_marginTop="40dp" android:layout_height="match_parent" - tools:context=".presentation.ui.draw.DrawSelectResultFragment"> + tools:context=".presentation.ui.draw.DrawResultFragment"> + + + + + app:layout_constraintBottom_toBottomOf="@id/draw_iv_select" + app:layout_constraintTop_toTopOf="@id/draw_iv_select" + tools:layout_height="267dp" /> + + + + - + android:layout_height="match_parent" + android:scaleType="centerCrop" + android:contentDescription="@string/draw_selected_restaurant_img_info" /> diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 89ac66f..f80f6fb 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -5,5 +5,4 @@ 13sp 11sp - \ No newline at end of file From 91efbd596f152785c0a2671aeca3059e9ab55e1c Mon Sep 17 00:00:00 2001 From: BeomBeom2 Date: Mon, 25 Nov 2024 13:32:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[Refector]=20=EB=BD=91=EA=B8=B0(DrawResultF?= =?UTF-8?q?ragment)=20=ED=9A=8C=EC=A0=84=20=EB=AA=A8=EC=85=98=20=EC=9B=B9,?= =?UTF-8?q?=20IOS=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No Related Issue --- .idea/runConfigurations.xml | 4 ++ .../ui/draw/DrawResultFragment.kt | 51 ++++++------------- .../ui/draw/DrawSelectCategoryFragment.kt | 47 ++++++++--------- .../ui/draw/DrawSelectResultAdapter.kt | 9 ---- .../presentation/ui/draw/DrawViewModel.kt | 35 ++++++------- .../main/res/layout/fragment_draw_result.xml | 20 ++++---- .../layout/fragment_draw_select_category.xml | 2 +- 7 files changed, 72 insertions(+), 96 deletions(-) diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml index 931b96c..16660f1 100644 --- a/.idea/runConfigurations.xml +++ b/.idea/runConfigurations.xml @@ -5,8 +5,12 @@ diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt index 7cffe33..230a873 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawResultFragment.kt @@ -13,7 +13,6 @@ import android.widget.ImageView import androidx.core.content.ContextCompat import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels -import androidx.recyclerview.widget.RecyclerView import androidx.viewpager2.widget.ViewPager2 import com.bumptech.glide.Glide import com.bumptech.glide.load.resource.bitmap.CenterCrop @@ -48,13 +47,6 @@ class DrawResultFragment : Fragment() { } private fun setupObservers() { - viewModel.selectedIndex.observe(viewLifecycleOwner) { index -> - if (index != null && index != RecyclerView.NO_POSITION) { - viewPager.setCurrentItem(index, true) - adapter.highlightItem(index) - } - } - viewModel.selectedRestaurant.observe(viewLifecycleOwner) { selected -> if (_binding == null) { _binding = FragmentDrawResultBinding.inflate(layoutInflater) @@ -87,7 +79,7 @@ class DrawResultFragment : Fragment() { // 페이지 전환 애니메이션 설정 val pageTransformer = ViewPager2.PageTransformer { page, position -> page.apply { - translationX = 30 * position + translationX = 20 * position } } viewPager.setPageTransformer(pageTransformer) @@ -140,20 +132,14 @@ class DrawResultFragment : Fragment() { viewModel.drawList.observe(viewLifecycleOwner) { list -> restaurantList.clear() restaurantList.addAll(list) - adapter.notifyDataSetChanged() + adapter.notifyItemRangeInserted(0, list.size) - // 애니메이션 시작 startAnimation() } } - private fun highlightCenterImage() { - val centerPosition = viewPager.currentItem - adapter.highlightItem(centerPosition) - } - private fun startAnimation() = animationScope.launch { - disableButtons() // 애니메이션 시작 시 버튼 비활성화 + disableButtons() val textView = binding.drawSelectedTvClickableInfo textView.alpha = 0f @@ -171,51 +157,44 @@ class DrawResultFragment : Fragment() { viewModel.selectedRestaurant.value?.let { selected -> val selectedIndex = restaurantList.indexOf(selected) viewPager.setCurrentItem(selectedIndex, true) - displaySelectedRestaurantInfo(selected) - // 선택된 음식점 정보 표시 + delay(500L) + displaySelectedRestaurantInfo(selected) val roundedScore = selected.restaurantScore?.let { floor(it * 2) / 2 } ?: "평가 없음" binding.drawTvRestaurantScore.text = roundedScore.toString() binding.drawTvRestaurantPartnershipInfo.text = selected.partnershipInfo ?: "제휴 해당사항 없음" updateStarRating(selected.restaurantScore ?: 0.0) binding.drawLlScoreImgGroup.visibility = View.VISIBLE - // 선택된 이미지 표시 displaySelectedRestaurantImage(selected) - - highlightCenterImage() enableButtons() val fadeIn = ObjectAnimator.ofFloat(textView, "alpha", 0f, 1f) - fadeIn.duration = 500 + fadeIn.duration = 1000 fadeIn.start() } } private fun displaySelectedRestaurantImage(restaurant: DrawRestaurantData) { - val calculateHeight = calculateViewHeight(297f) - - // gl_start와 gl_end의 위치를 기준으로 너비 계산 - val startX = binding.glStart.x - val endX = binding.glEnd.x - val calculatedWidth = (endX - startX).toInt() - // 선택된 이미지의 크기를 설정 - binding.drawIvSelect.layoutParams = binding.drawIvSelect.layoutParams.apply { - width = calculatedWidth - height = calculateHeight - } - // Glide를 사용하여 이미지 로드 및 둥근 모서리 처리 Glide.with(this) .load(restaurant.restaurantImgUrl) - .transform(CenterCrop(), RoundedCorners(78)) // RoundedCorners와 CenterCrop을 조합 + .transform(CenterCrop(), RoundedCorners(78)) .into(binding.drawIvSelect) + binding.drawIvSelect.alpha = 0f binding.drawIvSelect.visibility = View.VISIBLE + + binding.drawIvSelect.animate() + .alpha(1f) + .setDuration(1000) + .setListener(null) + .start() } + private fun disableButtons() { binding.drawBtnCategoryReset.isClickable = false binding.drawBtnRetry.isClickable = false diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt index ca4b346..d0b426f 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectCategoryFragment.kt @@ -35,33 +35,15 @@ class DrawSelectCategoryFragment : Fragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - allMenuViews= listOf( - binding.homeBtnAll, - binding.homeBtnKorea, - binding.homeBtnJapan, - binding.homeBtnChina, - binding.homeBtnWestern, - binding.homeBtnAsian, - binding.homeBtnMeat, - binding.homeBtnSeafood, - binding.homeBtnChicken, - binding.homeBtnHamburgerPizza, - binding.homeBtnTteokbokki, - binding.homeBtnBeer, - binding.homeBtnCafe, - binding.homeBtnBakery, - binding.homeBtnSalad, - binding.homeBtnBenefit - ) - + allMenuViews = getMenuList() setupToggleGroups() observeViewModel() - binding.drawBtnDrawRandomRestaurants.setOnClickListener { + binding.drawBtnDrawResult.setOnClickListener { //val selectedSituation = getSelectedTogglesText(binding.tierToggleSituationGroup) val selectedLocation = getSelectedTogglesText(binding.tierToggleLocationGroup) - viewModel.applyFilters(selectedMenus,selectedLocation) + viewModel.applyFilters(selectedMenus, selectedLocation) parentFragmentManager.beginTransaction() .replace(R.id.draw_fragment_container, DrawResultFragment()) @@ -94,14 +76,12 @@ class DrawSelectCategoryFragment : Fragment() { toggleButton.isChecked = true } else { if (isChecked) { - // Change the text color to active toggleButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.signature_1)) if (toggleButton.text.toString() == "전체" || toggleButton.text.toString() == "제휴업체") { clearOtherToggles(toggleGroup, toggleButton) } } else { - // Change the text color to inactive toggleButton.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4)) } @@ -260,4 +240,25 @@ class DrawSelectCategoryFragment : Fragment() { view.setBackgroundResource(R.drawable.all_radius_15_none) } } + + private fun getMenuList(): List { + return listOf( + binding.homeBtnAll, + binding.homeBtnKorea, + binding.homeBtnJapan, + binding.homeBtnChina, + binding.homeBtnWestern, + binding.homeBtnAsian, + binding.homeBtnMeat, + binding.homeBtnSeafood, + binding.homeBtnChicken, + binding.homeBtnHamburgerPizza, + binding.homeBtnTteokbokki, + binding.homeBtnBeer, + binding.homeBtnCafe, + binding.homeBtnBakery, + binding.homeBtnSalad, + binding.homeBtnBenefit + ) + } } diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt index 7890cb7..00d4fc4 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawSelectResultAdapter.kt @@ -13,8 +13,6 @@ import com.kust.kustaurant.data.model.DrawRestaurantData class DrawSelectResultAdapter(val restaurants: MutableList) : RecyclerView.Adapter() { - private var highlightedPosition: Int = RecyclerView.NO_POSITION - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RestaurantViewHolder { val view = LayoutInflater.from(parent.context) .inflate(R.layout.item_draw_select_result_img, parent, false) @@ -26,13 +24,6 @@ class DrawSelectResultAdapter(val restaurants: MutableList) holder.imageView.background = null holder.imageView.setPadding(0, 0, 0, 0) } - - fun highlightItem(position: Int) { - val previousHighlightedPosition = highlightedPosition - highlightedPosition = position - notifyItemChanged(previousHighlightedPosition) - notifyItemChanged(position) - } override fun getItemCount() = restaurants.size diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawViewModel.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawViewModel.kt index d4912db..b1f888a 100644 --- a/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawViewModel.kt +++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/draw/DrawViewModel.kt @@ -18,26 +18,25 @@ class DrawViewModel @Inject constructor( ) : ViewModel() { private val _drawList = MutableLiveData>() val drawList: LiveData> = _drawList - private var sameDrawList = 3 + private var _sameDrawList = 0 // limit 3 times + manage first draw private val _selectedMenus = MutableLiveData(setOf("전체")) val selectedMenus: LiveData> = _selectedMenus private val _selectedLocations = MutableLiveData(setOf("전체")) val selectedLocations: LiveData> = _selectedLocations - private var _initialSelectedMenus = setOf("전체") - private var _initialSelectedLocations = setOf("전체") + private var _previousSelectedMenus = setOf("") + private var _previousSelectedLocations = setOf("") private val _selectedRestaurant = MutableLiveData() val selectedRestaurant: LiveData = _selectedRestaurant fun drawRestaurants() { viewModelScope.launch { - val checkSameCategory = (selectedMenus.value == _initialSelectedMenus) && - (selectedLocations.value == _initialSelectedLocations) + isResetFilter() - if (checkSameCategory && sameDrawList < 2) { - sameDrawList++ + if (_sameDrawList < 2) { + _sameDrawList++ _drawList.value?.let { currentList -> if (currentList.isNotEmpty()) { val selected = getRandomRestaurants(currentList) @@ -46,24 +45,23 @@ class DrawViewModel @Inject constructor( } } } else { - sameDrawList = 0 + _sameDrawList = 0 val mappedMenus = selectedMenus.value?.let { CategoryIdMapper.mapMenus(it) } val mappedLocations = selectedLocations.value?.let { CategoryIdMapper.mapLocations(it) } if (mappedMenus != null && mappedLocations != null) { - Log.d("DrawViewModel", "$mappedMenus $mappedLocations") val drawRestaurantsListData = getDrawRestaurantUseCase( mappedMenus, mappedLocations ) - _drawList.value = drawRestaurantsListData + _drawList.value = drawRestaurantsListData.shuffled().take(20) - val selected = getRandomRestaurants(drawRestaurantsListData) + val selected = getRandomRestaurants(_drawList.value!!) _selectedRestaurant.value = selected updateSelectedIndex(drawRestaurantsListData, selected) } else { - Log.e("DrawViewModel", "Menus or Locations mapping failed. Menus: $mappedMenus, Locations: $mappedLocations") + Log.e("DrawViewModel", "Menus or Locations mapping failed. Menus: $mappedMenus, Locations: $mappedLocations") } } } @@ -91,12 +89,15 @@ class DrawViewModel @Inject constructor( fun applyFilters(types: Set, locations: Set) { setSelectedTypes(types) setSelectedLocations(locations) + } - // 현재 선택된 값들을 새로운 "초기" 값으로 설정 - _initialSelectedMenus = types - _initialSelectedLocations = locations - - sameDrawList = 3 + private fun isResetFilter() { + if(!((selectedMenus.value == _previousSelectedMenus) && + (selectedLocations.value == _previousSelectedLocations))) { + _sameDrawList = 3 + _previousSelectedMenus = selectedMenus.value!! + _previousSelectedLocations = selectedLocations.value!! + } } } diff --git a/app/src/main/res/layout/fragment_draw_result.xml b/app/src/main/res/layout/fragment_draw_result.xml index 0cb4444..6c956fc 100644 --- a/app/src/main/res/layout/fragment_draw_result.xml +++ b/app/src/main/res/layout/fragment_draw_result.xml @@ -3,8 +3,8 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_marginTop="40dp" android:layout_height="match_parent" + android:layout_marginTop="10dp" tools:context=".presentation.ui.draw.DrawResultFragment"> @@ -62,16 +62,16 @@ android:id="@+id/draw_iv_select" android:layout_width="0dp" android:layout_height="0dp" + android:background="@drawable/all_radius_30_signature_1" + android:padding="1dp" + android:scaleType="centerCrop" android:visibility="invisible" app:layout_constraintBottom_toTopOf="@id/draw_tv_restaurant_menu" - tools:visibility="visible" - android:scaleType="centerCrop" - android:padding="1dp" - app:layout_constraintEnd_toEndOf="@id/gl_end" app:layout_constraintDimensionRatio="289:296" - android:background="@drawable/all_radius_30_signature_1" + app:layout_constraintEnd_toEndOf="@id/gl_end" app:layout_constraintStart_toStartOf="@id/gl_start" - app:layout_constraintTop_toBottomOf="@id/draw_selected_tv_clickable_info"/> + app:layout_constraintTop_toBottomOf="@id/draw_selected_tv_clickable_info" + tools:visibility="visible" />