응원글 삭제 기능 추가

This commit is contained in:
klaus 2023-09-05 12:46:53 +09:00
parent e371fd2ac2
commit 8a4ad41212
10 changed files with 139 additions and 28 deletions

View File

@ -56,14 +56,10 @@ class ExplorerRepository(
) )
fun modifyCheers( fun modifyCheers(
cheersId: Long, request: PutModifyCheersRequest,
content: String,
token: String token: String
) = api.modifyCheers( ) = api.modifyCheers(
request = PutModifyCheersRequest( request = request,
cheersId = cheersId,
content = content
),
authHeader = token authHeader = token
) )

View File

@ -9,6 +9,7 @@ data class GetCheersResponse(
data class GetCheersResponseItem( data class GetCheersResponseItem(
@SerializedName("cheersId") val cheersId: Long, @SerializedName("cheersId") val cheersId: Long,
@SerializedName("memberId") val memberId: Long,
@SerializedName("nickname") val nickname: String, @SerializedName("nickname") val nickname: String,
@SerializedName("profileUrl") val profileUrl: String, @SerializedName("profileUrl") val profileUrl: String,
@SerializedName("content") val content: String, @SerializedName("content") val content: String,

View File

@ -28,6 +28,7 @@ import kr.co.vividnext.sodalive.audio_content.AudioContentAdapter
import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity import kr.co.vividnext.sodalive.audio_content.detail.AudioContentDetailActivity
import kr.co.vividnext.sodalive.audio_content.upload.AudioContentUploadActivity import kr.co.vividnext.sodalive.audio_content.upload.AudioContentUploadActivity
import kr.co.vividnext.sodalive.base.BaseActivity import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.base.SodaDialog
import kr.co.vividnext.sodalive.common.Constants import kr.co.vividnext.sodalive.common.Constants
import kr.co.vividnext.sodalive.common.LoadingDialog import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.common.SharedPreferenceManager import kr.co.vividnext.sodalive.common.SharedPreferenceManager
@ -389,16 +390,35 @@ class UserProfileActivity : BaseActivity<ActivityUserProfileBinding>(
) )
} }
}, },
modifyReply = { cheersId, content -> modifyReply = { cheersId, content, isActive ->
hideKeyboard { hideKeyboard {
viewModel.modifyCheers( viewModel.modifyCheers(
cheersId = cheersId, cheersId = cheersId,
creatorId = userId, creatorId = userId,
cheersContent = content cheersContent = content,
isActive = isActive
) )
} }
}, },
onClickReport = { showCheersReportPopup(it) } onClickReport = { showCheersReportPopup(it) },
onClickDelete = {
SodaDialog(
activity = this@UserProfileActivity,
layoutInflater = layoutInflater,
title = "응원글 삭제",
desc = "삭제하시겠습니까?",
confirmButtonTitle = "삭제",
confirmButtonClick = {
viewModel.modifyCheers(
cheersId = it,
creatorId = userId,
isActive = false
)
},
cancelButtonTitle = "취소",
cancelButtonClick = {}
).show(screenWidth)
}
) )
rvCheers.layoutManager = LinearLayoutManager( rvCheers.layoutManager = LinearLayoutManager(

View File

@ -15,6 +15,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.base.BaseViewModel import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.explorer.ExplorerRepository import kr.co.vividnext.sodalive.explorer.ExplorerRepository
import kr.co.vividnext.sodalive.explorer.profile.cheers.PutModifyCheersRequest
import kr.co.vividnext.sodalive.report.ReportRepository import kr.co.vividnext.sodalive.report.ReportRepository
import kr.co.vividnext.sodalive.report.ReportRequest import kr.co.vividnext.sodalive.report.ReportRequest
import kr.co.vividnext.sodalive.report.ReportType import kr.co.vividnext.sodalive.report.ReportType
@ -256,18 +257,37 @@ class UserProfileViewModel(
) )
} }
fun modifyCheers(cheersId: Long, creatorId: Long, cheersContent: String) { fun modifyCheers(
if (cheersContent.isBlank()) { cheersId: Long,
creatorId: Long,
cheersContent: String? = null,
isActive: Boolean? = null
) {
if (cheersContent == null && isActive == null) {
_toastLiveData.postValue("변경사항이 없습니다.")
return
}
if (cheersContent != null && cheersContent.isBlank()) {
_toastLiveData.postValue("내용을 입력하세요") _toastLiveData.postValue("내용을 입력하세요")
return return
} }
_isLoading.value = true _isLoading.value = true
val request = PutModifyCheersRequest(cheersId = cheersId)
if (cheersContent != null) {
request.content = cheersContent
}
if (isActive != null) {
request.isActive = isActive
}
compositeDisposable.add( compositeDisposable.add(
repository.modifyCheers( repository.modifyCheers(
cheersId = cheersId, request = request,
content = cheersContent,
token = "Bearer ${SharedPreferenceManager.token}" token = "Bearer ${SharedPreferenceManager.token}"
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())

View File

@ -4,5 +4,6 @@ import com.google.gson.annotations.SerializedName
data class PutModifyCheersRequest( data class PutModifyCheersRequest(
@SerializedName("cheersId") val cheersId: Long, @SerializedName("cheersId") val cheersId: Long,
@SerializedName("content") val content: String @SerializedName("content") var content: String? = null,
@SerializedName("isActive") var isActive: Boolean? = null,
) )

View File

@ -17,8 +17,9 @@ import kr.co.vividnext.sodalive.extensions.dpToPx
class UserProfileCheersAdapter( class UserProfileCheersAdapter(
private val userId: Long, private val userId: Long,
private val enterReply: (Long, String) -> Unit, private val enterReply: (Long, String) -> Unit,
private val modifyReply: (Long, String) -> Unit, private val modifyReply: (Long, String?, Boolean?) -> Unit,
private val onClickReport: (Long) -> Unit private val onClickReport: (Long) -> Unit,
private val onClickDelete: (Long) -> Unit
) : RecyclerView.Adapter<UserProfileCheersAdapter.ViewHolder>() { ) : RecyclerView.Adapter<UserProfileCheersAdapter.ViewHolder>() {
val items = mutableListOf<GetCheersResponseItem>() val items = mutableListOf<GetCheersResponseItem>()
@ -46,7 +47,9 @@ class UserProfileCheersAdapter(
showOptionMenu( showOptionMenu(
context, context,
binding.ivMenu, binding.ivMenu,
cheersId = cheers.cheersId cheersId = cheers.cheersId,
memberId = cheers.memberId,
creatorId = userId
) )
} }
@ -63,7 +66,7 @@ class UserProfileCheersAdapter(
binding.rlCheerReply.visibility = View.VISIBLE binding.rlCheerReply.visibility = View.VISIBLE
binding.tvSend.setOnClickListener { binding.tvSend.setOnClickListener {
val content = binding.etCheerReply.text.toString() val content = binding.etCheerReply.text.toString()
modifyReply(reply.cheersId, content) modifyReply(reply.cheersId, content, null)
} }
} }
} else { } else {
@ -106,16 +109,34 @@ class UserProfileCheersAdapter(
override fun getItemCount() = items.count() override fun getItemCount() = items.count()
private fun showOptionMenu(context: Context, v: View, cheersId: Long) { private fun showOptionMenu(
context: Context,
v: View,
cheersId: Long,
memberId: Long,
creatorId: Long
) {
val popup = PopupMenu(context, v) val popup = PopupMenu(context, v)
val inflater = popup.menuInflater val inflater = popup.menuInflater
inflater.inflate(R.menu.review_option_menu, popup.menu)
if (
memberId == SharedPreferenceManager.userId ||
creatorId == SharedPreferenceManager.userId
) {
inflater.inflate(R.menu.review_option_menu2, popup.menu)
} else {
inflater.inflate(R.menu.review_option_menu, popup.menu)
}
popup.setOnMenuItemClickListener { popup.setOnMenuItemClickListener {
when (it.itemId) { when (it.itemId) {
R.id.menu_review_report -> { R.id.menu_review_report -> {
onClickReport(cheersId) onClickReport(cheersId)
} }
R.id.menu_review_delete -> {
onClickDelete(cheersId)
}
} }
true true

View File

@ -12,6 +12,7 @@ import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import kr.co.vividnext.sodalive.base.BaseActivity import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.base.SodaDialog
import kr.co.vividnext.sodalive.common.Constants import kr.co.vividnext.sodalive.common.Constants
import kr.co.vividnext.sodalive.common.LoadingDialog import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.databinding.ActivityUserProfileFantalkAllBinding import kr.co.vividnext.sodalive.databinding.ActivityUserProfileFantalkAllBinding
@ -79,16 +80,35 @@ class UserProfileFantalkAllViewActivity : BaseActivity<ActivityUserProfileFantal
) )
} }
}, },
modifyReply = { cheersId, content -> modifyReply = { cheersId, content, isActive ->
hideKeyboard { hideKeyboard {
viewModel.modifyCheers( viewModel.modifyCheers(
cheersId = cheersId, cheersId = cheersId,
creatorId = userId, creatorId = userId,
cheersContent = content cheersContent = content,
isActive = isActive
) )
} }
}, },
onClickReport = { showCheersReportPopup(it) } onClickReport = { showCheersReportPopup(it) },
onClickDelete = {
SodaDialog(
activity = this@UserProfileFantalkAllViewActivity,
layoutInflater = layoutInflater,
title = "응원글 삭제",
desc = "삭제하시겠습니까?",
confirmButtonTitle = "삭제",
confirmButtonClick = {
viewModel.modifyCheers(
cheersId = it,
creatorId = userId,
isActive = false
)
},
cancelButtonTitle = "취소",
cancelButtonClick = {}
).show(screenWidth)
}
) )
rvCheers.layoutManager = LinearLayoutManager( rvCheers.layoutManager = LinearLayoutManager(

View File

@ -9,6 +9,7 @@ import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.explorer.ExplorerRepository import kr.co.vividnext.sodalive.explorer.ExplorerRepository
import kr.co.vividnext.sodalive.explorer.profile.GetCheersResponse import kr.co.vividnext.sodalive.explorer.profile.GetCheersResponse
import kr.co.vividnext.sodalive.explorer.profile.cheers.PutModifyCheersRequest
import kr.co.vividnext.sodalive.report.ReportRepository import kr.co.vividnext.sodalive.report.ReportRepository
import kr.co.vividnext.sodalive.report.ReportRequest import kr.co.vividnext.sodalive.report.ReportRequest
import kr.co.vividnext.sodalive.report.ReportType import kr.co.vividnext.sodalive.report.ReportType
@ -146,18 +147,37 @@ class UserProfileFantalkAllViewModel(
) )
} }
fun modifyCheers(cheersId: Long, creatorId: Long, cheersContent: String) { fun modifyCheers(
if (cheersContent.isBlank()) { cheersId: Long,
creatorId: Long,
cheersContent: String? = null,
isActive: Boolean? = null
) {
if (cheersContent == null && isActive == null) {
_toastLiveData.postValue("변경사항이 없습니다.")
return
}
if (cheersContent != null && cheersContent.isBlank()) {
_toastLiveData.postValue("내용을 입력하세요") _toastLiveData.postValue("내용을 입력하세요")
return return
} }
_isLoading.value = true _isLoading.value = true
val request = PutModifyCheersRequest(cheersId = cheersId)
if (cheersContent != null) {
request.content = cheersContent
}
if (isActive != null) {
request.isActive = isActive
}
compositeDisposable.add( compositeDisposable.add(
repository.modifyCheers( repository.modifyCheers(
cheersId = cheersId, request = request,
content = cheersContent,
token = "Bearer ${SharedPreferenceManager.token}" token = "Bearer ${SharedPreferenceManager.token}"
) )
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())

View File

@ -119,7 +119,6 @@
android:visibility="gone" android:visibility="gone"
tools:ignore="SmallSp" /> tools:ignore="SmallSp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_review_report"
android:title="신고하기"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_review_delete"
android:title="삭제"
app:showAsAction="ifRoom" />
</menu>