라이브 방 룰렛
- 리스너용 룰렛 버튼 추가 - 룰렛 설정 시 룰렛 버튼 토글 메시지를 발송하여 리스너 화면에서 룰렛이 (비)활성화 되도록 수정
This commit is contained in:
parent
4a4940f04d
commit
91db6caec9
|
@ -166,7 +166,7 @@ class AppDI(private val context: Context, isDebugMode: Boolean) {
|
||||||
viewModel { LiveRoomCreateViewModel(get()) }
|
viewModel { LiveRoomCreateViewModel(get()) }
|
||||||
viewModel { LiveTagViewModel(get()) }
|
viewModel { LiveTagViewModel(get()) }
|
||||||
viewModel { LiveRoomEditViewModel(get()) }
|
viewModel { LiveRoomEditViewModel(get()) }
|
||||||
viewModel { LiveRoomViewModel(get(), get(), get()) }
|
viewModel { LiveRoomViewModel(get(), get(), get(), get()) }
|
||||||
viewModel { LiveRoomDonationMessageViewModel(get()) }
|
viewModel { LiveRoomDonationMessageViewModel(get()) }
|
||||||
viewModel { ExplorerViewModel(get()) }
|
viewModel { ExplorerViewModel(get()) }
|
||||||
viewModel { UserProfileViewModel(get(), get(), get()) }
|
viewModel { UserProfileViewModel(get(), get(), get()) }
|
||||||
|
|
|
@ -72,6 +72,7 @@ import kr.co.vividnext.sodalive.live.room.profile.LiveRoomProfileDialog
|
||||||
import kr.co.vividnext.sodalive.live.room.profile.LiveRoomProfileListAdapter
|
import kr.co.vividnext.sodalive.live.room.profile.LiveRoomProfileListAdapter
|
||||||
import kr.co.vividnext.sodalive.live.room.profile.LiveRoomUserProfileDialog
|
import kr.co.vividnext.sodalive.live.room.profile.LiveRoomUserProfileDialog
|
||||||
import kr.co.vividnext.sodalive.live.room.update.LiveRoomInfoEditDialog
|
import kr.co.vividnext.sodalive.live.room.update.LiveRoomInfoEditDialog
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewDialog
|
||||||
import kr.co.vividnext.sodalive.live.roulette.config.RouletteConfigActivity
|
import kr.co.vividnext.sodalive.live.roulette.config.RouletteConfigActivity
|
||||||
import kr.co.vividnext.sodalive.report.ProfileReportDialog
|
import kr.co.vividnext.sodalive.report.ProfileReportDialog
|
||||||
import kr.co.vividnext.sodalive.report.ReportType
|
import kr.co.vividnext.sodalive.report.ReportType
|
||||||
|
@ -187,7 +188,17 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
|
||||||
val isActiveRoulette = result.data?.getBooleanExtra(Constants.EXTRA_RESULT_ROULETTE, false)
|
val isActiveRoulette = result.data?.getBooleanExtra(Constants.EXTRA_RESULT_ROULETTE, false)
|
||||||
|
|
||||||
if (resultCode == RESULT_OK && isActiveRoulette != null) {
|
if (resultCode == RESULT_OK && isActiveRoulette != null) {
|
||||||
// TODO 룰렛 활성화 / 비활성화 설정 리스너에게 알림
|
agora.sendRawMessageToGroup(
|
||||||
|
rawMessage = Gson().toJson(
|
||||||
|
LiveRoomChatRawMessage(
|
||||||
|
type = LiveRoomChatRawMessageType.TOGGLE_ROULETTE,
|
||||||
|
message = "",
|
||||||
|
can = 0,
|
||||||
|
donationMessage = "",
|
||||||
|
isActiveRoulette = isActiveRoulette
|
||||||
|
)
|
||||||
|
).toByteArray()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -672,16 +683,6 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
|
||||||
response.creatorId == SharedPreferenceManager.userId &&
|
response.creatorId == SharedPreferenceManager.userId &&
|
||||||
SharedPreferenceManager.role == MemberRole.CREATOR.name
|
SharedPreferenceManager.role == MemberRole.CREATOR.name
|
||||||
) {
|
) {
|
||||||
binding.flRoulette.visibility = View.GONE
|
|
||||||
binding.flRouletteSettings.visibility = View.VISIBLE
|
|
||||||
binding.flRouletteSettings.setOnClickListener {
|
|
||||||
rouletteConfigResult.launch(
|
|
||||||
Intent(
|
|
||||||
applicationContext,
|
|
||||||
RouletteConfigActivity::class.java
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
binding.flDonationMessageList.visibility = View.VISIBLE
|
binding.flDonationMessageList.visibility = View.VISIBLE
|
||||||
binding.flDonationMessageList.setOnClickListener {
|
binding.flDonationMessageList.setOnClickListener {
|
||||||
LiveRoomDonationMessageDialog(
|
LiveRoomDonationMessageDialog(
|
||||||
|
@ -821,6 +822,12 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
|
||||||
binding.ivCreatorFollow.visibility = View.GONE
|
binding.ivCreatorFollow.visibility = View.GONE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initRouletteSettingButton(isHost = response.creatorId == SharedPreferenceManager.userId)
|
||||||
|
activatingRouletteButton(
|
||||||
|
isHost = response.creatorId == SharedPreferenceManager.userId,
|
||||||
|
isActiveRoulette = response.isActiveRoulette
|
||||||
|
)
|
||||||
|
|
||||||
if (agora.rtmChannelIsNull()) {
|
if (agora.rtmChannelIsNull()) {
|
||||||
joinChannel(response)
|
joinChannel(response)
|
||||||
}
|
}
|
||||||
|
@ -849,6 +856,41 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun initRouletteSettingButton(isHost: Boolean) {
|
||||||
|
if (isHost) {
|
||||||
|
binding.flRouletteSettings.visibility = View.VISIBLE
|
||||||
|
binding.flRouletteSettings.setOnClickListener {
|
||||||
|
rouletteConfigResult.launch(
|
||||||
|
Intent(
|
||||||
|
applicationContext,
|
||||||
|
RouletteConfigActivity::class.java
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
binding.flRouletteSettings.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun activatingRouletteButton(isHost: Boolean, isActiveRoulette: Boolean) {
|
||||||
|
if (!isHost && isActiveRoulette) {
|
||||||
|
binding.flRoulette.visibility = View.VISIBLE
|
||||||
|
binding.flRoulette.setOnClickListener {
|
||||||
|
viewModel.showRoulette {
|
||||||
|
RoulettePreviewDialog(
|
||||||
|
activity = this,
|
||||||
|
preview = it,
|
||||||
|
onClickSpin = {},
|
||||||
|
layoutInflater = layoutInflater
|
||||||
|
).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
binding.flRoulette.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setNoticeAndClickableUrl(textView: TextView, text: String) {
|
private fun setNoticeAndClickableUrl(textView: TextView, text: String) {
|
||||||
textView.text = text
|
textView.text = text
|
||||||
|
|
||||||
|
@ -1277,6 +1319,17 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
|
||||||
invalidateChat()
|
invalidateChat()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LiveRoomChatRawMessageType.TOGGLE_ROULETTE -> {
|
||||||
|
handler.post {
|
||||||
|
activatingRouletteButton(
|
||||||
|
isHost = viewModel
|
||||||
|
.roomInfoResponse
|
||||||
|
.creatorId == SharedPreferenceManager.userId,
|
||||||
|
isActiveRoulette = rawMessage.isActiveRoulette ?: false
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val chat = message.text
|
val chat = message.text
|
||||||
|
|
|
@ -20,6 +20,10 @@ import kr.co.vividnext.sodalive.live.room.donation.GetLiveRoomDonationStatusResp
|
||||||
import kr.co.vividnext.sodalive.live.room.info.GetRoomInfoResponse
|
import kr.co.vividnext.sodalive.live.room.info.GetRoomInfoResponse
|
||||||
import kr.co.vividnext.sodalive.live.room.profile.GetLiveRoomUserProfileResponse
|
import kr.co.vividnext.sodalive.live.room.profile.GetLiveRoomUserProfileResponse
|
||||||
import kr.co.vividnext.sodalive.live.room.update.EditLiveRoomInfoRequest
|
import kr.co.vividnext.sodalive.live.room.update.EditLiveRoomInfoRequest
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RouletteItem
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RoulettePreview
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RoulettePreviewItem
|
||||||
|
import kr.co.vividnext.sodalive.live.roulette.RouletteRepository
|
||||||
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
|
||||||
|
@ -33,7 +37,8 @@ import java.io.File
|
||||||
class LiveRoomViewModel(
|
class LiveRoomViewModel(
|
||||||
private val repository: LiveRepository,
|
private val repository: LiveRepository,
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
private val reportRepository: ReportRepository
|
private val reportRepository: ReportRepository,
|
||||||
|
private val rouletteRepository: RouletteRepository
|
||||||
) : BaseViewModel() {
|
) : BaseViewModel() {
|
||||||
private val _roomInfoLiveData = MutableLiveData<GetRoomInfoResponse>()
|
private val _roomInfoLiveData = MutableLiveData<GetRoomInfoResponse>()
|
||||||
val roomInfoLiveData: LiveData<GetRoomInfoResponse>
|
val roomInfoLiveData: LiveData<GetRoomInfoResponse>
|
||||||
|
@ -775,4 +780,58 @@ class LiveRoomViewModel(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun showRoulette(complete: (RoulettePreview) -> Unit) {
|
||||||
|
if (!_isLoading.value!!) {
|
||||||
|
_isLoading.value = true
|
||||||
|
compositeDisposable.add(
|
||||||
|
rouletteRepository.getRoulette(
|
||||||
|
creatorId = roomInfoResponse.creatorId,
|
||||||
|
token = "Bearer ${SharedPreferenceManager.token}"
|
||||||
|
)
|
||||||
|
.subscribeOn(Schedulers.io())
|
||||||
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
|
.subscribe(
|
||||||
|
{
|
||||||
|
_isLoading.value = false
|
||||||
|
|
||||||
|
val data = it.data
|
||||||
|
if (
|
||||||
|
it.success &&
|
||||||
|
data != null &&
|
||||||
|
data.isActive &&
|
||||||
|
data.items.isNotEmpty()
|
||||||
|
) {
|
||||||
|
complete(
|
||||||
|
RoulettePreview(
|
||||||
|
data.can,
|
||||||
|
items = calculatePercentages(data.items)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val message = it.message ?: "룰렛을 사용할 수 없습니다. 다시 시도해 주세요."
|
||||||
|
_toastLiveData.postValue(message)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
_isLoading.value = false
|
||||||
|
it.message?.let { message -> Logger.e(message) }
|
||||||
|
_toastLiveData.postValue("룰렛을 사용할 수 없습니다. 다시 시도해 주세요.")
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun calculatePercentages(options: List<RouletteItem>): List<RoulettePreviewItem> {
|
||||||
|
val totalWeight = options.sumOf { it.weight }
|
||||||
|
val updatedOptions = options.asSequence().map { option ->
|
||||||
|
RoulettePreviewItem(
|
||||||
|
title = option.title,
|
||||||
|
percent = "${(option.weight.toDouble() / totalWeight * 100).toInt()}%"
|
||||||
|
)
|
||||||
|
}.toList()
|
||||||
|
|
||||||
|
return updatedOptions
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,19 @@ data class LiveRoomChatRawMessage(
|
||||||
@SerializedName("type") val type: LiveRoomChatRawMessageType,
|
@SerializedName("type") val type: LiveRoomChatRawMessageType,
|
||||||
@SerializedName("message") val message: String,
|
@SerializedName("message") val message: String,
|
||||||
@SerializedName("can") val can: Int,
|
@SerializedName("can") val can: Int,
|
||||||
@SerializedName("donationMessage") val donationMessage: String?
|
@SerializedName("donationMessage") val donationMessage: String?,
|
||||||
|
@SerializedName("isActiveRoulette") val isActiveRoulette: Boolean? = null
|
||||||
)
|
)
|
||||||
|
|
||||||
enum class LiveRoomChatRawMessageType {
|
enum class LiveRoomChatRawMessageType {
|
||||||
@SerializedName("DONATION") DONATION,
|
@SerializedName("DONATION")
|
||||||
@SerializedName("SET_MANAGER") SET_MANAGER,
|
DONATION,
|
||||||
@SerializedName("EDIT_ROOM_INFO") EDIT_ROOM_INFO,
|
@SerializedName("SET_MANAGER")
|
||||||
@SerializedName("DONATION_STATUS") DONATION_STATUS
|
SET_MANAGER,
|
||||||
|
@SerializedName("EDIT_ROOM_INFO")
|
||||||
|
EDIT_ROOM_INFO,
|
||||||
|
@SerializedName("DONATION_STATUS")
|
||||||
|
DONATION_STATUS,
|
||||||
|
@SerializedName("TOGGLE_ROULETTE")
|
||||||
|
TOGGLE_ROULETTE
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ data class GetRoomInfoResponse(
|
||||||
@SerializedName("listenerList") val listenerList: List<LiveRoomMember>,
|
@SerializedName("listenerList") val listenerList: List<LiveRoomMember>,
|
||||||
@SerializedName("managerList") val managerList: List<LiveRoomMember>,
|
@SerializedName("managerList") val managerList: List<LiveRoomMember>,
|
||||||
@SerializedName("donationRankingTop3UserIds") val donationRankingTop3UserIds: List<Long>,
|
@SerializedName("donationRankingTop3UserIds") val donationRankingTop3UserIds: List<Long>,
|
||||||
|
@SerializedName("isActiveRoulette") val isActiveRoulette: Boolean,
|
||||||
@SerializedName("isPrivateRoom") val isPrivateRoom: Boolean,
|
@SerializedName("isPrivateRoom") val isPrivateRoom: Boolean,
|
||||||
@SerializedName("password") val password: String? = null
|
@SerializedName("password") val password: String? = null
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package kr.co.vividnext.sodalive.live.roulette
|
package kr.co.vividnext.sodalive.live.roulette
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
|
@ -11,8 +12,12 @@ import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import kr.co.vividnext.sodalive.R
|
import kr.co.vividnext.sodalive.R
|
||||||
|
import kr.co.vividnext.sodalive.common.Constants
|
||||||
|
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
|
||||||
import kr.co.vividnext.sodalive.databinding.DialogRoulettePreviewBinding
|
import kr.co.vividnext.sodalive.databinding.DialogRoulettePreviewBinding
|
||||||
import kr.co.vividnext.sodalive.extensions.dpToPx
|
import kr.co.vividnext.sodalive.extensions.dpToPx
|
||||||
|
import kr.co.vividnext.sodalive.extensions.moneyFormat
|
||||||
|
import kr.co.vividnext.sodalive.mypage.can.charge.CanChargeActivity
|
||||||
|
|
||||||
class RoulettePreviewDialog(
|
class RoulettePreviewDialog(
|
||||||
private val activity: FragmentActivity,
|
private val activity: FragmentActivity,
|
||||||
|
@ -61,6 +66,19 @@ class RoulettePreviewDialog(
|
||||||
}
|
}
|
||||||
|
|
||||||
dialogView.tvTitle.text = title.ifBlank { "룰렛" }
|
dialogView.tvTitle.text = title.ifBlank { "룰렛" }
|
||||||
|
if (onClickSpin != null) {
|
||||||
|
dialogView.tvCan.visibility = View.VISIBLE
|
||||||
|
dialogView.tvCan.text = SharedPreferenceManager.can.moneyFormat()
|
||||||
|
dialogView.tvCan.setOnClickListener {
|
||||||
|
alertDialog.dismiss()
|
||||||
|
|
||||||
|
val intent = Intent(activity, CanChargeActivity::class.java)
|
||||||
|
intent.putExtra(Constants.EXTRA_GO_TO_PREV_PAGE, true)
|
||||||
|
activity.startActivity(intent)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
dialogView.tvCan.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
preview.items.forEachIndexed { index, item ->
|
preview.items.forEachIndexed { index, item ->
|
||||||
dialogView.llRouletteOptionContainer.addView(createOptionView(index, item))
|
dialogView.llRouletteOptionContainer.addView(createOptionView(index, item))
|
||||||
|
|
Loading…
Reference in New Issue