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/.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/community/CommunityBlankFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityBlankFragment.kt
deleted file mode 100644
index 472ff47..0000000
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityBlankFragment.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package com.kust.kustaurant.presentation.ui.community
-
-import android.content.Intent
-import android.os.Bundle
-import androidx.fragment.app.Fragment
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import com.kust.kustaurant.R
-import com.kust.kustaurant.databinding.FragmentCommunityBinding
-import com.kust.kustaurant.databinding.FragmentCommunityBlankBinding
-import com.kust.kustaurant.presentation.ui.search.SearchActivity
-
-class CommunityBlankFragment : Fragment() {
- lateinit var binding : FragmentCommunityBlankBinding
-
- override fun onCreateView(
- inflater: LayoutInflater, container: ViewGroup?,
- savedInstanceState: Bundle?
- ): View? {
- binding = FragmentCommunityBlankBinding.inflate(layoutInflater)
-
- initSearch()
- return binding.root
- }
-
- private fun initSearch() {
- binding.communityFlIvSearch.setOnClickListener {
- val intent = Intent(requireContext(), SearchActivity::class.java)
- startActivity(intent)
- }
- }
-
-}
\ No newline at end of file
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailFragment.kt
index 47ab11b..a217e9b 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailFragment.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailFragment.kt
@@ -58,14 +58,9 @@ class CommunityPostDetailFragment : Fragment() {
setupButton()
setupObservers()
-
- binding.communityLlBtnPostLike.background = GradientDrawable().apply {
- shape = GradientDrawable.RECTANGLE
- cornerRadius = 100f
- setStroke(1, ContextCompat.getColor(requireContext(), R.color.signature_1))
- }
}
+ @SuppressLint("SetTextI18n")
private fun setupObservers() {
parentViewModel.selectedPostDetailId.observe(viewLifecycleOwner) { postId ->
postId?.let {
@@ -109,7 +104,6 @@ class CommunityPostDetailFragment : Fragment() {
viewModel.postDelete.observe(viewLifecycleOwner) { result ->
if (result) {
Toast.makeText(requireContext(), "게시글이 삭제되었습니다.", Toast.LENGTH_SHORT).show()
-
viewModel.resetPostDelete()
requireActivity().supportFragmentManager.popBackStack()
}
@@ -142,8 +136,6 @@ class CommunityPostDetailFragment : Fragment() {
private fun loadPostBodyToWebView(postBody: String) {
val webView = binding.communityWvMiddleContent
webView.settings.javaScriptEnabled = false
-
- // CSS를 추가하여 WebView 내용이 화면 너비에 맞게 조정되도록 함
val htmlContent = """
@@ -172,6 +164,12 @@ class CommunityPostDetailFragment : Fragment() {
binding.communityIvPostDetailDots.isVisible = viewModel.postMine.value!!
}
+ binding.communityLlBtnPostLike.background = GradientDrawable().apply {
+ shape = GradientDrawable.RECTANGLE
+ cornerRadius = 100f
+ setStroke(1, ContextCompat.getColor(requireContext(), R.color.signature_1))
+ }
+
binding.btnBack.setOnClickListener {
(requireActivity() as? MainActivity)?.supportFragmentManager?.popBackStack()
}
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailViewModel.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailViewModel.kt
index 238d294..03c2dd5 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailViewModel.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostDetailViewModel.kt
@@ -35,10 +35,10 @@ class CommunityPostDetailViewModel @Inject constructor(
private val _communityPostDetail = MutableLiveData()
val communityPostDetail: LiveData = _communityPostDetail
- private val _postMine = MutableLiveData(true)
+ private val _postMine = MutableLiveData(true)
val postMine: LiveData = _postMine
- private val _postDelete = MutableLiveData(false)
+ private val _postDelete = MutableLiveData(false)
val postDelete: LiveData = _postDelete
private val _postScrapInfo = MutableLiveData()
@@ -48,7 +48,6 @@ class CommunityPostDetailViewModel @Inject constructor(
val postLikeInfo: LiveData = _postLikeInfo
private val _commentReply = MutableLiveData()
- val commentReply: LiveData = _commentReply
private val _uiState = MutableLiveData(UiState.Idle)
val uiState: LiveData = _uiState
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListAdapter.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListAdapter.kt
index 90e7d26..fe91775 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListAdapter.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListAdapter.kt
@@ -1,5 +1,6 @@
package com.kust.kustaurant.presentation.ui.community
+import android.annotation.SuppressLint
import android.text.Html
import android.view.LayoutInflater
import android.view.View
@@ -30,13 +31,14 @@ class CommunityPostListAdapter() :
init {
itemView.setOnClickListener {
- val position = adapterPosition
+ val position = bindingAdapterPosition
if (position != RecyclerView.NO_POSITION) {
- itemClickListener?.onItemClicked(getItem(position))
+ itemClickListener.onItemClicked(getItem(position))
}
}
}
+ @SuppressLint("SetTextI18n")
fun bind(item: CommunityPost) {
viewBinding.communityTvCategory.text = item.postCategory
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListFragment.kt
index b54fba0..5cda489 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListFragment.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostListFragment.kt
@@ -6,6 +6,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
+import android.widget.CompoundButton
import android.widget.LinearLayout
import android.widget.PopupWindow
import androidx.core.content.ContextCompat
@@ -38,81 +39,43 @@ class CommunityPostListFragment : Fragment() {
binding.lifecycleOwner = viewLifecycleOwner
binding.viewModel = viewModel
- commuAdapter = CommunityPostListAdapter()
+ setupRecyclerView()
+ setupUI()
+
+ return binding.root
+ }
+
+ private fun setupRecyclerView() {
+ commuAdapter = CommunityPostListAdapter().apply {
+ setOnItemClickListener(object : CommunityPostListAdapter.OnItemClickListener {
+ override fun onItemClicked(data: CommunityPost) {
+ navigateToPostDetail(data.postId)
+ }
+ })
+ }
+
binding.communityRecyclerView.apply {
layoutManager = LinearLayoutManager(context)
adapter = commuAdapter
}
+ }
- setupUI()
-
- return binding.root
+ private fun navigateToPostDetail(postId: Int) {
+ viewModel.selectPost(postId)
+ requireActivity().supportFragmentManager.beginTransaction()
+ .replace(R.id.main_frm, CommunityPostDetailFragment())
+ .addToBackStack(null)
+ .commit()
}
private fun setupUI() {
setupFloatingWriteBtn()
- commuAdapter.setOnItemClickListener(object : CommunityPostListAdapter.OnItemClickListener {
- override fun onItemClicked(data: CommunityPost) {
- viewModel.selectPost(data.postId)
-
- requireActivity().supportFragmentManager.beginTransaction()
- .replace(R.id.main_frm, CommunityPostDetailFragment())
- .addToBackStack(null)
- .commit()
- }
- })
-
binding.communityToggleLastestSort.setOnCheckedChangeListener { buttonView, isChecked ->
- if (isChecked) {
- viewModel.updateSortAndLoadPosts("recent")
- binding.communityRecyclerView.scrollToPosition(0)
- binding.communityTogglePopularSort.isChecked = false
- buttonView.setTextColor(
- ContextCompat.getColor(
- requireContext(),
- R.color.signature_1
- )
- )
- } else {
- // 이미 체크된 버튼을 다시 누를 경우 체크를 유지
- if (!binding.communityTogglePopularSort.isChecked) {
- buttonView.isChecked = true
- } else {
- buttonView.setTextColor(
- ContextCompat.getColor(
- requireContext(),
- R.color.cement_4
- )
- )
- }
- }
+ handleSortToggle(buttonView, isChecked, "recent", binding.communityTogglePopularSort)
}
-
binding.communityTogglePopularSort.setOnCheckedChangeListener { buttonView, isChecked ->
- if (isChecked) {
- viewModel.updateSortAndLoadPosts("popular")
- binding.communityRecyclerView.scrollToPosition(0)
- binding.communityToggleLastestSort.isChecked = false
- buttonView.setTextColor(
- ContextCompat.getColor(
- requireContext(),
- R.color.signature_1
- )
- )
- } else {
- // 이미 체크된 버튼을 다시 누를 경우 체크를 유지
- if (!binding.communityToggleLastestSort.isChecked) {
- buttonView.isChecked = true
- } else {
- buttonView.setTextColor(
- ContextCompat.getColor(
- requireContext(),
- R.color.cement_4
- )
- )
- }
- }
+ handleSortToggle(buttonView, isChecked, "popular", binding.communityToggleLastestSort)
}
binding.commuBtnWritePost.setOnClickListener {
@@ -151,6 +114,27 @@ class CommunityPostListFragment : Fragment() {
}
}
+ private fun handleSortToggle(
+ buttonView: CompoundButton,
+ isChecked: Boolean,
+ sortType: String,
+ otherToggle: CompoundButton
+ ) {
+ if (isChecked) {
+ viewModel.updateSortAndLoadPosts(sortType)
+ binding.communityRecyclerView.scrollToPosition(0)
+ otherToggle.isChecked = false
+ buttonView.setTextColor(ContextCompat.getColor(requireContext(), R.color.signature_1))
+ } else {
+ // 유지 조건
+ if (!otherToggle.isChecked) {
+ buttonView.isChecked = true
+ } else {
+ buttonView.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
+ }
+ }
+ }
+
private fun showPopupWindow() {
val popupBinding = PopupCommuPostListSortBinding.inflate(layoutInflater)
val popupWindow = PopupWindow(
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostRankingFragment.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostRankingFragment.kt
index b26dd13..4618c54 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostRankingFragment.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityPostRankingFragment.kt
@@ -26,7 +26,6 @@ class CommunityPostRankingFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
- // ViewModel의 랭킹 데이터를 관찰하여 UI 업데이트
viewModel.communityRanking.observe(viewLifecycleOwner) { rankings ->
val (topRankers, remainingRankings) = viewModel.onRankingDataChanged(rankings)
bindTopRankers(topRankers)
@@ -77,7 +76,6 @@ class CommunityPostRankingFragment : Fragment() {
binding.communityToggleQuarterly.isChecked = true
binding.communityTogglePopularSort.isChecked = false
- // 초기 상태에 맞게 텍스트 색상 설정
binding.communityToggleQuarterly.setTextColor(ContextCompat.getColor(requireContext(), R.color.signature_1))
binding.communityTogglePopularSort.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
@@ -87,28 +85,21 @@ class CommunityPostRankingFragment : Fragment() {
binding.communityTogglePopularSort.isChecked = false
viewModel.onSortTypeChanged("quarterly")
- // 분기순 버튼 텍스트 색상 변경
binding.communityToggleQuarterly.setTextColor(ContextCompat.getColor(requireContext(), R.color.signature_1))
- // 누적순 버튼 텍스트 색상 기본으로 변경
binding.communityTogglePopularSort.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
} else {
- // 분기순 버튼이 체크 해제되었을 때 (옵션)
binding.communityToggleQuarterly.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
}
}
- // 누적순 버튼 클릭 이벤트 처리
binding.communityTogglePopularSort.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
binding.communityToggleQuarterly.isChecked = false
viewModel.onSortTypeChanged("cumulative")
- // 누적순 버튼 텍스트 색상 변경
binding.communityTogglePopularSort.setTextColor(ContextCompat.getColor(requireContext(), R.color.signature_1))
- // 분기순 버튼 텍스트 색상 기본으로 변경
binding.communityToggleQuarterly.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
} else {
- // 누적순 버튼이 체크 해제되었을 때 (옵션)
binding.communityTogglePopularSort.setTextColor(ContextCompat.getColor(requireContext(), R.color.cement_4))
}
}
diff --git a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityViewModel.kt b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityViewModel.kt
index 569980c..4548afb 100644
--- a/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityViewModel.kt
+++ b/app/src/main/java/com/kust/kustaurant/presentation/ui/community/CommunityViewModel.kt
@@ -60,7 +60,7 @@ class CommunityViewModel @Inject constructor(
_communityPosts.postValue(currentPosts)
}
} catch (e: Exception) {
- Log.e("CommunityViewModel", "loadCommunityPosts Error", e)
+ Log.e("CommunityViewModel", "From loadCommunityPosts Err is ", e)
} finally { }
}
}
@@ -124,7 +124,7 @@ class CommunityViewModel @Inject constructor(
val rankings = getCommunityRankingListUseCase(sort)
_communityRanking.value = rankings
} catch (e: Exception) {
- Log.e("CommunityViewModel", "loadCommunityRanking Error", e)
+ Log.e("CommunityViewModel", "From loadCommunityRanking Err is ", e)
}
}
}
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 77%
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..230a873 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
@@ -13,33 +13,32 @@ 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
+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()
@@ -48,42 +47,39 @@ class DrawSelectResultFragment : 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 = 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 = 20 * position
}
}
viewPager.setPageTransformer(pageTransformer)
@@ -118,7 +114,7 @@ class DrawSelectResultFragment : Fragment() {
binding.drawTvRestaurantScore.text = ""
binding.drawTvRestaurantPartnershipInfo.text = ""
binding.drawLlScoreImgGroup.visibility = View.GONE
-
+ binding.drawIvSelect.visibility = View.INVISIBLE
loadRestaurants()
}
@@ -129,33 +125,27 @@ class DrawSelectResultFragment : Fragment() {
.commit()
}
}
+
private fun loadRestaurants() {
viewModel.drawRestaurants()
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
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,27 +153,48 @@ class DrawSelectResultFragment : Fragment() {
currentPage--
}
- // 애니메이션 종료 후, 중앙에 선택된 음식점 배치
+ // 애니메이션 종료 후, 중앙에 선택된 음식점 배치 및 이미지 표시
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
- highlightCenterImage()
+ displaySelectedRestaurantImage(selected)
enableButtons()
val fadeIn = ObjectAnimator.ofFloat(textView, "alpha", 0f, 1f)
- fadeIn.duration = 500
+ fadeIn.duration = 1000
fadeIn.start()
}
}
+ private fun displaySelectedRestaurantImage(restaurant: DrawRestaurantData) {
+
+
+ Glide.with(this)
+ .load(restaurant.restaurantImgUrl)
+ .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
@@ -208,7 +219,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..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
@@ -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?,
@@ -36,36 +35,18 @@ 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, DrawSelectResultFragment())
+ .replace(R.id.draw_fragment_container, DrawResultFragment())
.addToBackStack(null)
.commit()
}
@@ -95,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))
}
@@ -261,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 544c7dc..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
@@ -1,27 +1,18 @@
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
-
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RestaurantViewHolder {
val view = LayoutInflater.from(parent.context)
.inflate(R.layout.item_draw_select_result_img, parent, false)
@@ -30,38 +21,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 var _sameDrawList = 0 // limit 3 times + manage first draw
+ 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("전체")
- 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) {
- Log.d("DrawViewModel", "just random algorithm")
- sameDrawList++
+ if (_sameDrawList < 2) {
+ _sameDrawList++
_drawList.value?.let { currentList ->
if (currentList.isNotEmpty()) {
val selected = getRandomRestaurants(currentList)
@@ -48,28 +45,23 @@ class DrawViewModel @Inject constructor(
}
}
} else {
- Log.d("DrawViewModel", "draw Restaurants from Backend")
- 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)
-
- 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")
+ Log.e("DrawViewModel", "Menus or Locations mapping failed. Menus: $mappedMenus, Locations: $mappedLocations")
}
}
}
@@ -97,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/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_community_blank.xml b/app/src/main/res/layout/fragment_community_blank.xml
deleted file mode 100644
index 320f6f5..0000000
--- a/app/src/main/res/layout/fragment_community_blank.xml
+++ /dev/null
@@ -1,98 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ 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..6c956fc 100644
--- a/app/src/main/res/layout/fragment_draw_select_result.xml
+++ b/app/src/main/res/layout/fragment_draw_result.xml
@@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
- tools:context=".presentation.ui.draw.DrawSelectResultFragment">
+ android:layout_marginTop="10dp"
+ tools:context=".presentation.ui.draw.DrawResultFragment">
+
+
+
+
+
+
+ tools:visibility="visible" />