크리에이터 커뮤니티 게시글 전체리스트
- 오디오 콘텐츠 재생기능 추가
This commit is contained in:
@@ -8,6 +8,7 @@ data class GetCommunityPostListResponse(
|
||||
@SerializedName("creatorNickname") val creatorNickname: String,
|
||||
@SerializedName("creatorProfileUrl") val creatorProfileUrl: String,
|
||||
@SerializedName("imageUrl") val imageUrl: String?,
|
||||
@SerializedName("audioUrl") val audioUrl: String?,
|
||||
@SerializedName("content") val content: String,
|
||||
@SerializedName("price") val price: Int,
|
||||
@SerializedName("date") val date: String,
|
||||
|
||||
@@ -15,6 +15,7 @@ import kr.co.vividnext.sodalive.common.Constants
|
||||
import kr.co.vividnext.sodalive.common.LoadingDialog
|
||||
import kr.co.vividnext.sodalive.databinding.ActivityCreatorCommunityAllBinding
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.comment.CreatorCommunityCommentFragment
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.player.CreatorCommunityMediaPlayerManager
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.modify.CreatorCommunityModifyActivity
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import org.koin.android.ext.android.inject
|
||||
@@ -27,6 +28,7 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
|
||||
|
||||
private lateinit var loadingDialog: LoadingDialog
|
||||
private lateinit var adapter: CreatorCommunityAllAdapter
|
||||
private lateinit var mediaPlayerManager: CreatorCommunityMediaPlayerManager
|
||||
|
||||
private var creatorId: Long = 0
|
||||
|
||||
@@ -45,6 +47,10 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
mediaPlayerManager = CreatorCommunityMediaPlayerManager(this) {
|
||||
adapter.updateUI()
|
||||
}
|
||||
|
||||
creatorId = intent.getLongExtra(Constants.EXTRA_COMMUNITY_CREATOR_ID, 0)
|
||||
if (creatorId <= 0) {
|
||||
Toast.makeText(applicationContext, "잘못된 요청입니다.", Toast.LENGTH_LONG).show()
|
||||
@@ -56,6 +62,16 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
|
||||
viewModel.getCommunityPostList()
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
mediaPlayerManager.pauseContent()
|
||||
super.onPause()
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
mediaPlayerManager.stopContent()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
override fun setupView() {
|
||||
loadingDialog = LoadingDialog(this, layoutInflater)
|
||||
binding.toolbar.tvBack.text = "커뮤니티"
|
||||
@@ -113,6 +129,8 @@ class CreatorCommunityAllActivity : BaseActivity<ActivityCreatorCommunityAllBind
|
||||
)
|
||||
}.show(screenWidth)
|
||||
},
|
||||
onClickAudioContentPlayOrPause = { mediaPlayerManager.toggleContent(it) },
|
||||
isAudioContentPlaying = { mediaPlayerManager.isPlayingContent(it) },
|
||||
onClickPurchaseContent = { postId, can, onSuccess ->
|
||||
PurchaseCommunityPostDialog(
|
||||
activity = this@CreatorCommunityAllActivity,
|
||||
|
||||
@@ -23,6 +23,7 @@ import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||
import kr.co.vividnext.sodalive.databinding.ItemCreatorCommunityAllBinding
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostCommentListItem
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.GetCommunityPostListResponse
|
||||
import kr.co.vividnext.sodalive.explorer.profile.creator_community.all.player.CreatorCommunityContentItem
|
||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||
import kr.co.vividnext.sodalive.extensions.loadUrl
|
||||
import java.util.regex.Pattern
|
||||
@@ -35,6 +36,8 @@ class CreatorCommunityAllAdapter(
|
||||
private val onClickModify: (Long) -> Unit,
|
||||
private val onClickDelete: (Long) -> Unit,
|
||||
private val onClickReport: (Long) -> Unit,
|
||||
private val onClickAudioContentPlayOrPause: (CreatorCommunityContentItem) -> Unit,
|
||||
private val isAudioContentPlaying: (Long) -> Boolean,
|
||||
private val onClickPurchaseContent:
|
||||
(Long, Int, onSuccess: (GetCommunityPostListResponse) -> Unit) -> Unit
|
||||
) : RecyclerView.Adapter<CreatorCommunityAllAdapter.ViewHolder>() {
|
||||
@@ -63,6 +66,7 @@ class CreatorCommunityAllAdapter(
|
||||
binding.ivContent.visibility = View.GONE
|
||||
binding.llComment.visibility = View.GONE
|
||||
binding.ivSeeMore.visibility = View.GONE
|
||||
binding.ivPlayOrPause.visibility = View.GONE
|
||||
binding.llLockPost.visibility = View.VISIBLE
|
||||
|
||||
val lockPostWidth = (screenWidth - 42f.dpToPx()).toInt()
|
||||
@@ -100,6 +104,28 @@ class CreatorCommunityAllAdapter(
|
||||
)
|
||||
}
|
||||
|
||||
if (item.audioUrl != null && item.imageUrl != null) {
|
||||
binding.ivPlayOrPause.visibility = View.VISIBLE
|
||||
binding.ivPlayOrPause.setImageResource(
|
||||
if (isAudioContentPlaying(item.postId)) {
|
||||
R.drawable.btn_audio_content_pause
|
||||
} else {
|
||||
R.drawable.btn_audio_content_play
|
||||
}
|
||||
)
|
||||
binding.ivPlayOrPause.setOnClickListener {
|
||||
onClickAudioContentPlayOrPause(
|
||||
CreatorCommunityContentItem(
|
||||
item.postId,
|
||||
item.audioUrl
|
||||
)
|
||||
)
|
||||
}
|
||||
} else {
|
||||
binding.ivPlayOrPause.visibility = View.GONE
|
||||
binding.ivPlayOrPause.setOnClickListener {}
|
||||
}
|
||||
|
||||
setImageContent(binding.ivContent, item.imageUrl)
|
||||
setContentLike(item.isLike, item.likeCount, item.postId, index)
|
||||
setNoticeAndClickableUrl(binding.tvContent, item.content, item.isExpand, index)
|
||||
@@ -283,4 +309,9 @@ class CreatorCommunityAllAdapter(
|
||||
|
||||
popup.show()
|
||||
}
|
||||
|
||||
@SuppressLint("NotifyDataSetChanged")
|
||||
fun updateUI() {
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
package kr.co.vividnext.sodalive.explorer.profile.creator_community.all.player
|
||||
|
||||
import android.content.Context
|
||||
import android.media.AudioAttributes
|
||||
import android.media.MediaPlayer
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
import java.io.IOException
|
||||
|
||||
data class CreatorCommunityContentItem(val contentId: Long, val url: String)
|
||||
|
||||
class CreatorCommunityMediaPlayerManager(
|
||||
private val context: Context,
|
||||
private val updateUI: () -> Unit
|
||||
) {
|
||||
private var mediaPlayer: MediaPlayer? = null
|
||||
private var currentPlayingContentId: Long? = null
|
||||
private var isPaused: Boolean = false
|
||||
|
||||
private fun playContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
||||
if (currentPlayingContentId == creatorCommunityContentItem.contentId && isPaused) {
|
||||
resumeContent()
|
||||
return
|
||||
}
|
||||
|
||||
stopContent()
|
||||
|
||||
mediaPlayer = MediaPlayer().apply {
|
||||
setAudioAttributes(
|
||||
AudioAttributes.Builder()
|
||||
.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC)
|
||||
.setUsage(AudioAttributes.USAGE_MEDIA)
|
||||
.build()
|
||||
)
|
||||
|
||||
try {
|
||||
setDataSource(context, Uri.parse(creatorCommunityContentItem.url))
|
||||
prepareAsync() // 비동기적으로 준비
|
||||
setOnPreparedListener {
|
||||
start()
|
||||
updateUI() // 준비 완료 후 UI 업데이트
|
||||
}
|
||||
} catch (e: IOException) {
|
||||
e.printStackTrace()
|
||||
Toast.makeText(context, "콘텐츠를 재생하지 못했습니다.\n다시 시도해 주세요", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
setOnCompletionListener {
|
||||
currentPlayingContentId = null
|
||||
updateUI() // 재생 완료 후 UI 업데이트
|
||||
}
|
||||
}
|
||||
|
||||
currentPlayingContentId = creatorCommunityContentItem.contentId
|
||||
isPaused = false
|
||||
updateUI()
|
||||
}
|
||||
|
||||
fun pauseContent() {
|
||||
mediaPlayer?.pause()
|
||||
isPaused = true
|
||||
updateUI()
|
||||
}
|
||||
|
||||
private fun resumeContent() {
|
||||
mediaPlayer?.start()
|
||||
isPaused = false
|
||||
updateUI()
|
||||
}
|
||||
|
||||
fun stopContent() {
|
||||
mediaPlayer?.let {
|
||||
it.stop()
|
||||
it.release()
|
||||
mediaPlayer = null
|
||||
}
|
||||
currentPlayingContentId = null
|
||||
isPaused = false
|
||||
updateUI()
|
||||
}
|
||||
|
||||
fun toggleContent(creatorCommunityContentItem: CreatorCommunityContentItem) {
|
||||
if (currentPlayingContentId == creatorCommunityContentItem.contentId) {
|
||||
if (mediaPlayer?.isPlaying == true) {
|
||||
pauseContent()
|
||||
} else {
|
||||
resumeContent()
|
||||
}
|
||||
} else {
|
||||
playContent(creatorCommunityContentItem)
|
||||
}
|
||||
}
|
||||
|
||||
fun isPlayingContent(contentId: Long): Boolean {
|
||||
return currentPlayingContentId == contentId && mediaPlayer?.isPlaying == true
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user