diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityApi.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityApi.kt index 40ea926..43ca47a 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityApi.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityApi.kt @@ -26,6 +26,14 @@ interface CreatorCommunityApi { @Header("Authorization") authHeader: String ): Single> + @PUT("/creator-community") + @Multipart + fun modifyCommunityPost( + @Part postImage: MultipartBody.Part?, + @Part("request") request: RequestBody, + @Header("Authorization") authHeader: String + ): Single> + @GET("/creator-community") fun getCommunityPostList( @Query("creatorId") creatorId: Long, diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityRepository.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityRepository.kt index e192173..50f30c8 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityRepository.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/CreatorCommunityRepository.kt @@ -82,4 +82,14 @@ class CreatorCommunityRepository(private val api: CreatorCommunityApi) { request = request, authHeader = token ) + + fun modifyCommunityPost( + postImage: MultipartBody.Part?, + request: RequestBody, + token: String + ) = api.modifyCommunityPost( + postImage = postImage, + request = request, + authHeader = token + ) } diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllActivity.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllActivity.kt index d0bcb62..c319983 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllActivity.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllActivity.kt @@ -8,6 +8,7 @@ import android.widget.Toast import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView 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.LoadingDialog import kr.co.vividnext.sodalive.databinding.ActivityCreatorCommunityAllBinding @@ -63,6 +64,26 @@ class CreatorCommunityAllActivity : BaseActivity + 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 0 && lastVisiblePosition == itemTotalCount) { + viewModel.getCommunityPostList() + } + } + }) + recyclerView.adapter = adapter } diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt index 2e3d4c8..2cad479 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllAdapter.kt @@ -1,9 +1,11 @@ package kr.co.vividnext.sodalive.explorer.profile.creator_community.all import android.annotation.SuppressLint +import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.PopupMenu import androidx.recyclerview.widget.RecyclerView import coil.load import coil.transform.CircleCropTransformation @@ -16,16 +18,21 @@ import kr.co.vividnext.sodalive.extensions.loadUrl class CreatorCommunityAllAdapter( private val onClickLike: (Long) -> 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() { val items = mutableListOf() inner class ViewHolder( + private val context: Context, private val binding: ItemCreatorCommunityAllBinding ) : RecyclerView.ViewHolder(binding.root) { @SuppressLint("NotifyDataSetChanged") fun bind(item: GetCommunityPostListResponse, index: Int) { + binding.tvDate.text = item.date binding.tvNickname.text = item.creatorNickname binding.ivCreatorProfile.loadUrl(item.creatorProfileUrl) { crossfade(true) @@ -35,6 +42,15 @@ class CreatorCommunityAllAdapter( binding.tvContent.text = item.content + binding.ivSeeMore.setOnClickListener { + showOptionMenu( + context = context, + v = binding.ivSeeMore, + postId = item.postId, + creatorId = item.creatorId + ) + } + binding.ivLike.setImageResource( if (item.isLike) { R.drawable.ic_audio_content_heart_pressed @@ -105,6 +121,7 @@ class CreatorCommunityAllAdapter( } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = ViewHolder( + parent.context, ItemCreatorCommunityAllBinding.inflate( LayoutInflater.from(parent.context), parent, @@ -117,4 +134,40 @@ class CreatorCommunityAllAdapter( override fun onBindViewHolder(holder: ViewHolder, position: Int) { 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() + } } diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllViewModel.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllViewModel.kt index 9732da6..823a351 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllViewModel.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/CreatorCommunityAllViewModel.kt @@ -2,6 +2,7 @@ package kr.co.vividnext.sodalive.explorer.profile.creator_community.all import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData +import com.google.gson.Gson import com.orhanobut.logger.Logger import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers 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.explorer.profile.creator_community.CreatorCommunityRepository import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse +import okhttp3.MediaType.Companion.toMediaType +import okhttp3.RequestBody.Companion.toRequestBody class CreatorCommunityAllViewModel( 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) { compositeDisposable.add( repository.communityPostLike( diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/ModifyCommunityPostRequest.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/ModifyCommunityPostRequest.kt new file mode 100644 index 0000000..857b31f --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/ModifyCommunityPostRequest.kt @@ -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 +) diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/comment/CreatorCommunityCommentListFragment.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/comment/CreatorCommunityCommentListFragment.kt index 3e09c41..52e18d5 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/comment/CreatorCommunityCommentListFragment.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/creator_community/all/comment/CreatorCommunityCommentListFragment.kt @@ -14,7 +14,6 @@ import androidx.recyclerview.widget.RecyclerView import coil.load import coil.transform.CircleCropTransformation 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.SodaDialog import kr.co.vividnext.sodalive.common.Constants diff --git a/app/src/main/res/layout/activity_creator_community_all.xml b/app/src/main/res/layout/activity_creator_community_all.xml index 7f4605d..0946f37 100644 --- a/app/src/main/res/layout/activity_creator_community_all.xml +++ b/app/src/main/res/layout/activity_creator_community_all.xml @@ -2,6 +2,7 @@ + + + + + + diff --git a/app/src/main/res/menu/community_post_option_menu.xml b/app/src/main/res/menu/community_post_option_menu.xml new file mode 100644 index 0000000..f2fce9d --- /dev/null +++ b/app/src/main/res/menu/community_post_option_menu.xml @@ -0,0 +1,9 @@ + + + + +