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

[Design] 뽑기 결과 애니메이션 UI를 웹, IOS와 통일 #108

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 8 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -142,8 +136,6 @@ class CommunityPostDetailFragment : Fragment() {
private fun loadPostBodyToWebView(postBody: String) {
val webView = binding.communityWvMiddleContent
webView.settings.javaScriptEnabled = false

// CSS를 추가하여 WebView 내용이 화면 너비에 맞게 조정되도록 함
val htmlContent = """
<html>
<head>
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ class CommunityPostDetailViewModel @Inject constructor(
private val _communityPostDetail = MutableLiveData<CommunityPost>()
val communityPostDetail: LiveData<CommunityPost> = _communityPostDetail

private val _postMine = MutableLiveData<Boolean>(true)
private val _postMine = MutableLiveData(true)
val postMine: LiveData<Boolean> = _postMine

private val _postDelete = MutableLiveData<Boolean>(false)
private val _postDelete = MutableLiveData(false)
val postDelete: LiveData<Boolean> = _postDelete

private val _postScrapInfo = MutableLiveData<CommunityPostScrapResponse>()
Expand All @@ -48,7 +48,6 @@ class CommunityPostDetailViewModel @Inject constructor(
val postLikeInfo: LiveData<CommunityPostLikeResponse> = _postLikeInfo

private val _commentReply = MutableLiveData<CommunityPostComment>()
val commentReply: LiveData<CommunityPostComment> = _commentReply

private val _uiState = MutableLiveData<UiState>(UiState.Idle)
val uiState: LiveData<UiState> = _uiState
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))

Expand All @@ -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))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 { }
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Loading