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: 활동 관련 뷰 더보기 팝업메뉴 구현 #412

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 12 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 @@ -3,16 +3,29 @@ package com.teamwss.websoso.ui.activityDetail
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import android.widget.PopupWindow
import android.widget.TextView
import androidx.activity.viewModels
import androidx.databinding.ViewDataBinding
import com.teamwss.websoso.R
import com.teamwss.websoso.R.string.my_activity_detail_title
import com.teamwss.websoso.R.string.other_user_page_activity
import com.teamwss.websoso.common.ui.base.BaseActivity
import com.teamwss.websoso.databinding.ActivityActivityDetailBinding
import com.teamwss.websoso.databinding.MenuMyActivityPopupBinding
import com.teamwss.websoso.databinding.MenuOtherUserActivityPopupBinding
import com.teamwss.websoso.ui.activityDetail.adapter.ActivityDetailAdapter
import com.teamwss.websoso.ui.createFeed.CreateFeedActivity
import com.teamwss.websoso.ui.feedDetail.FeedDetailActivity
import com.teamwss.websoso.ui.feedDetail.model.EditFeedModel
import com.teamwss.websoso.ui.main.feed.dialog.FeedRemoveDialogFragment
import com.teamwss.websoso.ui.main.feed.dialog.FeedReportDialogFragment
import com.teamwss.websoso.ui.main.feed.dialog.FeedReportDoneDialogFragment
import com.teamwss.websoso.ui.main.feed.dialog.RemoveMenuType
import com.teamwss.websoso.ui.main.feed.dialog.ReportMenuType
import com.teamwss.websoso.ui.main.myPage.MyPageViewModel
import com.teamwss.websoso.ui.main.myPage.myActivity.ActivityItemClickListener
import com.teamwss.websoso.ui.main.myPage.myActivity.MyActivityFragment
Expand All @@ -23,11 +36,10 @@ import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class ActivityDetailActivity :
BaseActivity<ActivityActivityDetailBinding>(R.layout.activity_activity_detail),
ActivityItemClickListener {
BaseActivity<ActivityActivityDetailBinding>(R.layout.activity_activity_detail) {
private val activityDetailViewModel: ActivityDetailViewModel by viewModels()
private val activityDetailAdapter: ActivityDetailAdapter by lazy {
ActivityDetailAdapter(this)
ActivityDetailAdapter(onClickFeedItem())
}
private val myPageViewModel: MyPageViewModel by viewModels()
private val otherUserPageViewModel: OtherUserPageViewModel by viewModels()
Expand All @@ -37,12 +49,14 @@ class ActivityDetailActivity :
}
private val userId: Long by lazy { intent.getLongExtra(USER_ID_KEY, DEFAULT_USER_ID) }

private var _popupWindow: PopupWindow? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setupUserIDAndSource()
setActivityTitle()
setupMyActivitiesDetailAdapter()
setUpObserver()
setupObserver()
onBackButtonClick()
}

Expand Down Expand Up @@ -71,9 +85,9 @@ class ActivityDetailActivity :
}
}

private fun setUpObserver() {
activityDetailViewModel.userActivity.observe(this) { activities ->
activityDetailAdapter.submitList(activities)
private fun setupObserver() {
activityDetailViewModel.activityDetailUiState.observe(this) { uiState ->
activityDetailAdapter.submitList(uiState.activities)
}

when (activityDetailViewModel.source) {
Expand All @@ -84,7 +98,6 @@ class ActivityDetailActivity :
}
}
}

SOURCE_OTHER_USER_ACTIVITY -> {
otherUserPageViewModel.otherUserProfile.observe(this) { otherUserProfile ->
otherUserProfile?.let {
Expand All @@ -101,32 +114,134 @@ class ActivityDetailActivity :
}
}

override fun onContentClick(feedId: Long) {
startActivity(FeedDetailActivity.getIntent(this, feedId))
private fun onClickFeedItem() = object : ActivityItemClickListener {
override fun onContentClick(feedId: Long) {
startActivity(FeedDetailActivity.getIntent(this@ActivityDetailActivity, feedId))
}

override fun onNovelInfoClick(novelId: Long) {
startActivity(NovelDetailActivity.getIntent(this@ActivityDetailActivity, novelId))
}

override fun onLikeButtonClick(view: View, feedId: Long) {
val likeCountTextView: TextView = view.findViewById(R.id.tv_my_activity_thumb_up_count)
val currentLikeCount = likeCountTextView.text.toString().toInt()

val updatedLikeCount: Int = if (view.isSelected) {
if (currentLikeCount > 0) currentLikeCount - 1 else 0
} else {
currentLikeCount + 1
}

likeCountTextView.text = updatedLikeCount.toString()
view.isSelected = !view.isSelected

activityDetailViewModel.updateActivityLike(view.isSelected, feedId, updatedLikeCount)
}

override fun onMoreButtonClick(view: View, feedId: Long) {
showPopupMenu(view, feedId)
}
}

override fun onNovelInfoClick(novelId: Long) {
startActivity(NovelDetailActivity.getIntent(this, novelId))
private fun showPopupMenu(view: View, feedId: Long) {
val inflater = LayoutInflater.from(this)
val binding = when (source) {
SOURCE_MY_ACTIVITY -> MenuMyActivityPopupBinding.inflate(inflater)
SOURCE_OTHER_USER_ACTIVITY -> MenuOtherUserActivityPopupBinding.inflate(inflater)
else -> return
}

_popupWindow?.dismiss()
_popupWindow = PopupWindow(
binding.root,
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
true
).apply {
elevation = 2f
showAsDropDown(view)
}

setupPopupMenuClickListeners(binding, feedId)
}

override fun onLikeButtonClick(view: View, feedId: Long) {
val likeCountTextView: TextView = view.findViewById(R.id.tv_my_activity_thumb_up_count)
val currentLikeCount = likeCountTextView.text.toString().toInt()
private fun setupPopupMenuClickListeners(binding: ViewDataBinding, feedId: Long) {
when (binding) {
is MenuMyActivityPopupBinding -> {
binding.tvMyActivityModification.setOnClickListener {
navigateToFeedEdit(feedId)
_popupWindow?.dismiss()
}
binding.tvMyActivityPopupDeletion.setOnClickListener {
showRemoveDialog(feedId)
_popupWindow?.dismiss()
}
}

val updatedLikeCount: Int = if (view.isSelected) {
if (currentLikeCount > 0) currentLikeCount - 1 else 0
} else {
currentLikeCount + 1
is MenuOtherUserActivityPopupBinding -> {
binding.tvOtherUserActivityReportSpoiler.setOnClickListener {
showReportDialog(feedId, ReportMenuType.SPOILER_FEED.name)
_popupWindow?.dismiss()
}
binding.tvOtherUserActivityReportExpression.setOnClickListener {
showReportDialog(feedId, ReportMenuType.IMPERTINENCE_FEED.name)
_popupWindow?.dismiss()
}
}
}
}

likeCountTextView.text = updatedLikeCount.toString()
view.isSelected = !view.isSelected
private fun navigateToFeedEdit(feedId: Long) {
val activityModel =
activityDetailViewModel.activityDetailUiState.value?.activities?.find { it.feedId == feedId }
activityModel?.let { feed ->
val editFeedModel = EditFeedModel(
feedId = feed.feedId,
novelId = feed.novelId ?: 0L,
novelTitle = feed.title ?: "",
feedContent = feed.feedContent,
feedCategory = feed.relevantCategories?.split(", ") ?: emptyList()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r: 트콤

)
startActivity(CreateFeedActivity.getIntent(this, editFeedModel))
} ?: throw IllegalArgumentException("Feed not found")
}

private fun showRemoveDialog(feedId: Long) {
val dialogFragment = FeedRemoveDialogFragment.newInstance(
menuType = RemoveMenuType.REMOVE_FEED.name,
event = {
activityDetailViewModel.updateRemovedFeed(feedId)
}
)
dialogFragment.show(supportFragmentManager, FeedRemoveDialogFragment.TAG)
}

activityDetailViewModel.updateActivityLike(view.isSelected, feedId, updatedLikeCount)
private fun showReportDialog(feedId: Long, menuType: String) {
val dialogFragment = FeedReportDialogFragment.newInstance(
menuType = menuType,
event = {
when (menuType) {
ReportMenuType.SPOILER_FEED.name -> activityDetailViewModel.updateReportedSpoilerFeed(
feedId
)

ReportMenuType.IMPERTINENCE_FEED.name -> activityDetailViewModel.updateReportedImpertinenceFeed(
feedId
)
}
showReportDoneDialog(menuType)
}
)
dialogFragment.show(supportFragmentManager, FeedReportDialogFragment.TAG)
}

override fun onMoreButtonClick(view: View, feedId: Long) {
// TODO 팝업메뉴 수정 및 차단
private fun showReportDoneDialog(menuType: String) {
val doneDialogFragment = FeedReportDoneDialogFragment.newInstance(
menuType = menuType,
event = {}
)
doneDialogFragment.show(supportFragmentManager, FeedReportDoneDialogFragment.TAG)
}

companion object {
Expand Down
Loading