커뮤니티 게시물 삭제 추가

This commit is contained in:
klaus 2023-12-25 05:15:50 +09:00
parent 481cad1a46
commit 6b2e59c09d
10 changed files with 194 additions and 2 deletions

View File

@ -26,6 +26,14 @@ interface CreatorCommunityApi {
@Header("Authorization") authHeader: String @Header("Authorization") authHeader: String
): Single<ApiResponse<Any>> ): Single<ApiResponse<Any>>
@PUT("/creator-community")
@Multipart
fun modifyCommunityPost(
@Part postImage: MultipartBody.Part?,
@Part("request") request: RequestBody,
@Header("Authorization") authHeader: String
): Single<ApiResponse<Any>>
@GET("/creator-community") @GET("/creator-community")
fun getCommunityPostList( fun getCommunityPostList(
@Query("creatorId") creatorId: Long, @Query("creatorId") creatorId: Long,

View File

@ -82,4 +82,14 @@ class CreatorCommunityRepository(private val api: CreatorCommunityApi) {
request = request, request = request,
authHeader = token authHeader = token
) )
fun modifyCommunityPost(
postImage: MultipartBody.Part?,
request: RequestBody,
token: String
) = api.modifyCommunityPost(
postImage = postImage,
request = request,
authHeader = token
)
} }

View File

@ -8,6 +8,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.ActivityCreatorCommunityAllBinding import kr.co.vividnext.sodalive.databinding.ActivityCreatorCommunityAllBinding
@ -63,6 +64,26 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
supportFragmentManager, supportFragmentManager,
dialog.tag dialog.tag
) )
},
onClickModify = {
},
onClickDelete = { postId ->
SodaDialog(
activity = this@CreatorCommunityAllActivity,
layoutInflater = layoutInflater,
title = "게시물 삭제",
desc = "삭제하시겠습니까?",
confirmButtonTitle = "삭제",
confirmButtonClick = {
viewModel.deleteCommunityPostList(postId = postId)
},
cancelButtonTitle = "취소",
cancelButtonClick = {}
).show(screenWidth)
},
onClickReport = {
} }
) )
@ -103,6 +124,21 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
} }
} }
}) })
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val lastVisiblePosition = (recyclerView.layoutManager as LinearLayoutManager)
.findLastVisibleItemPosition()
val itemTotalCount = adapter.itemCount - 1
if (itemTotalCount > 0 && lastVisiblePosition == itemTotalCount) {
viewModel.getCommunityPostList()
}
}
})
recyclerView.adapter = adapter recyclerView.adapter = adapter
} }

View File

@ -1,9 +1,11 @@
package kr.co.vividnext.sodalive.explorer.profile.creator_community.all package kr.co.vividnext.sodalive.explorer.profile.creator_community.all
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.appcompat.widget.PopupMenu
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import coil.load import coil.load
import coil.transform.CircleCropTransformation import coil.transform.CircleCropTransformation
@ -16,16 +18,21 @@ import kr.co.vividnext.sodalive.extensions.loadUrl
class CreatorCommunityAllAdapter( class CreatorCommunityAllAdapter(
private val onClickLike: (Long) -> Unit, private val onClickLike: (Long) -> Unit,
private val writeComment: (Long, Long?, String) -> Unit, private val writeComment: (Long, Long?, String) -> Unit,
private val showCommentBottomSheetDialog: (Long) -> Unit private val showCommentBottomSheetDialog: (Long) -> Unit,
private val onClickModify: (Long) -> Unit,
private val onClickDelete: (Long) -> Unit,
private val onClickReport: (Long) -> Unit
) : RecyclerView.Adapter<CreatorCommunityAllAdapter.ViewHolder>() { ) : RecyclerView.Adapter<CreatorCommunityAllAdapter.ViewHolder>() {
val items = mutableListOf<GetCommunityPostListResponse>() val items = mutableListOf<GetCommunityPostListResponse>()
inner class ViewHolder( inner class ViewHolder(
private val context: Context,
private val binding: ItemCreatorCommunityAllBinding private val binding: ItemCreatorCommunityAllBinding
) : RecyclerView.ViewHolder(binding.root) { ) : RecyclerView.ViewHolder(binding.root) {
@SuppressLint("NotifyDataSetChanged") @SuppressLint("NotifyDataSetChanged")
fun bind(item: GetCommunityPostListResponse, index: Int) { fun bind(item: GetCommunityPostListResponse, index: Int) {
binding.tvDate.text = item.date
binding.tvNickname.text = item.creatorNickname binding.tvNickname.text = item.creatorNickname
binding.ivCreatorProfile.loadUrl(item.creatorProfileUrl) { binding.ivCreatorProfile.loadUrl(item.creatorProfileUrl) {
crossfade(true) crossfade(true)
@ -35,6 +42,15 @@ class CreatorCommunityAllAdapter(
binding.tvContent.text = item.content binding.tvContent.text = item.content
binding.ivSeeMore.setOnClickListener {
showOptionMenu(
context = context,
v = binding.ivSeeMore,
postId = item.postId,
creatorId = item.creatorId
)
}
binding.ivLike.setImageResource( binding.ivLike.setImageResource(
if (item.isLike) { if (item.isLike) {
R.drawable.ic_audio_content_heart_pressed R.drawable.ic_audio_content_heart_pressed
@ -105,6 +121,7 @@ class CreatorCommunityAllAdapter(
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder(
parent.context,
ItemCreatorCommunityAllBinding.inflate( ItemCreatorCommunityAllBinding.inflate(
LayoutInflater.from(parent.context), LayoutInflater.from(parent.context),
parent, parent,
@ -117,4 +134,40 @@ class CreatorCommunityAllAdapter(
override fun onBindViewHolder(holder: ViewHolder, position: Int) { override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(items[position], position) holder.bind(items[position], position)
} }
private fun showOptionMenu(
context: Context,
v: View,
postId: Long,
creatorId: Long
) {
val popup = PopupMenu(context, v)
val inflater = popup.menuInflater
if (creatorId == SharedPreferenceManager.userId) {
inflater.inflate(R.menu.community_post_creator_option_menu, popup.menu)
} else {
inflater.inflate(R.menu.community_post_option_menu, popup.menu)
}
popup.setOnMenuItemClickListener {
when (it.itemId) {
R.id.menu_modify -> {
onClickModify(postId)
}
R.id.menu_delete -> {
onClickDelete(postId)
}
R.id.menu_report -> {
onClickReport(postId)
}
}
true
}
popup.show()
}
} }

View File

@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.explorer.profile.creator_community.all
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.google.gson.Gson
import com.orhanobut.logger.Logger import com.orhanobut.logger.Logger
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers import io.reactivex.rxjava3.schedulers.Schedulers
@ -9,6 +10,8 @@ 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.profile.creator_community.CreatorCommunityRepository import kr.co.vividnext.sodalive.explorer.profile.creator_community.CreatorCommunityRepository
import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.RequestBody.Companion.toRequestBody
class CreatorCommunityAllViewModel( class CreatorCommunityAllViewModel(
private val repository: CreatorCommunityRepository private val repository: CreatorCommunityRepository
@ -75,6 +78,54 @@ class CreatorCommunityAllViewModel(
} }
} }
fun deleteCommunityPostList(postId: Long) {
if (!_isLoading.value!!) {
_isLoading.value = true
val request = ModifyCommunityPostRequest(
creatorCommunityId = postId,
isActive = false
)
val requestJson = Gson().toJson(request)
compositeDisposable.add(
repository.modifyCommunityPost(
null,
request = requestJson.toRequestBody("text/plain".toMediaType()),
token = "Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
_isLoading.value = false
if (it.success) {
page = 1
isLast = false
getCommunityPostList()
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
}
},
{
_isLoading.value = false
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
)
)
}
}
fun communityPostLike(postId: Long) { fun communityPostLike(postId: Long) {
compositeDisposable.add( compositeDisposable.add(
repository.communityPostLike( repository.communityPostLike(

View File

@ -0,0 +1,11 @@
package kr.co.vividnext.sodalive.explorer.profile.creator_community.all
import com.google.gson.annotations.SerializedName
data class ModifyCommunityPostRequest(
@SerializedName("creatorCommunityId") val creatorCommunityId: Long,
@SerializedName("content") val content: String? = null,
@SerializedName("isCommentAvailable") val isCommentAvailable: Boolean? = null,
@SerializedName("isAdult") val isAdult: Boolean? = null,
@SerializedName("isActive") val isActive: Boolean? = null
)

View File

@ -14,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView
import coil.load import coil.load
import coil.transform.CircleCropTransformation import coil.transform.CircleCropTransformation
import kr.co.vividnext.sodalive.R import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.audio_content.comment.AudioContentCommentFragment
import kr.co.vividnext.sodalive.base.BaseFragment import kr.co.vividnext.sodalive.base.BaseFragment
import kr.co.vividnext.sodalive.base.SodaDialog import kr.co.vividnext.sodalive.base.SodaDialog
import kr.co.vividnext.sodalive.common.Constants import kr.co.vividnext.sodalive.common.Constants

View File

@ -2,6 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical"> android:orientation="vertical">
<include <include

View File

@ -0,0 +1,14 @@
<?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_modify"
android:title="수정"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_delete"
android:title="삭제"
app:showAsAction="ifRoom" />
</menu>

View File

@ -0,0 +1,9 @@
<?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_report"
android:title="신고하기"
app:showAsAction="ifRoom" />
</menu>