From deda8322d5689753ee90794652c464ffe39e46af Mon Sep 17 00:00:00 2001 From: klaus Date: Wed, 17 Jun 2026 10:58:19 +0900 Subject: [PATCH] =?UTF-8?q?feat(creator):=20=EB=9D=BC=EC=9D=B4=EB=B8=8C=20?= =?UTF-8?q?coordinator=EB=A5=BC=20=EC=B6=94=EA=B0=80=ED=95=9C=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/CreatorChannelLiveCoordinator.kt | 249 ++++++++++++++++++ 1 file changed, 249 insertions(+) create mode 100644 app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelLiveCoordinator.kt diff --git a/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelLiveCoordinator.kt b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelLiveCoordinator.kt new file mode 100644 index 00000000..4de3c76a --- /dev/null +++ b/app/src/main/java/kr/co/vividnext/sodalive/v2/creator/channel/CreatorChannelLiveCoordinator.kt @@ -0,0 +1,249 @@ +package kr.co.vividnext.sodalive.v2.creator.channel + +import android.content.Intent +import android.view.LayoutInflater +import android.widget.Toast +import androidx.fragment.app.FragmentManager +import kr.co.vividnext.sodalive.R +import kr.co.vividnext.sodalive.audio_content.AudioContentPlayService +import kr.co.vividnext.sodalive.audio_content.player.AudioContentPlayerService +import kr.co.vividnext.sodalive.common.Constants +import kr.co.vividnext.sodalive.common.SharedPreferenceManager +import kr.co.vividnext.sodalive.extensions.moneyFormat +import kr.co.vividnext.sodalive.live.LiveViewModel +import kr.co.vividnext.sodalive.live.reservation.complete.LiveReservationCompleteActivity +import kr.co.vividnext.sodalive.live.room.LiveRoomActivity +import kr.co.vividnext.sodalive.live.room.detail.GetRoomDetailResponse +import kr.co.vividnext.sodalive.live.room.detail.LiveRoomDetailFragment +import kr.co.vividnext.sodalive.live.room.dialog.LiveCancelDialog +import kr.co.vividnext.sodalive.live.room.dialog.LivePaymentDialog +import kr.co.vividnext.sodalive.live.room.dialog.LiveRoomPasswordDialog +import kr.co.vividnext.sodalive.live.room.update.LiveRoomEditActivity +import kr.co.vividnext.sodalive.settings.language.LanguageManager +import kr.co.vividnext.sodalive.settings.language.LocaleHelper +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale +import java.util.TimeZone + +class CreatorChannelLiveCoordinator( + private val activity: CreatorChannelActivity, + private val layoutInflater: LayoutInflater, + private val fragmentManager: FragmentManager, + private val liveViewModel: LiveViewModel, + private val screenWidthProvider: () -> Int, + private val refreshHome: () -> Unit +) { + fun showLiveRoomDetail(roomId: Long) { + val detailFragment = LiveRoomDetailFragment( + roomId, + onClickParticipant = {}, + onClickReservation = { reservationRoom(roomId) }, + onClickModify = { roomDetailResponse -> modifyLive(roomDetailResponse) }, + onClickStart = { startLive(roomId) }, + onClickCancel = { cancelLive(roomId) } + ) + if (detailFragment.isAdded) return + + detailFragment.show(fragmentManager, detailFragment.tag) + } + + fun enterLiveRoom(roomId: Long) { + activity.startService( + Intent(activity, AudioContentPlayService::class.java).apply { + action = AudioContentPlayService.MusicAction.STOP.name + } + ) + activity.startService( + Intent(activity, AudioContentPlayerService::class.java).apply { + action = "STOP_SERVICE" + } + ) + + val onEnterRoomSuccess = { + activity.runOnUiThread { openLiveRoom(roomId) } + } + + liveViewModel.getRoomDetail(roomId) { + if (!it.channelName.isNullOrBlank()) { + if (it.manager.id == SharedPreferenceManager.userId) { + liveViewModel.enterRoom(roomId, onEnterRoomSuccess) + } else if (it.price == 0 || it.isPaid) { + if (it.isPrivateRoom) { + LiveRoomPasswordDialog( + activity = activity, + layoutInflater = layoutInflater, + can = 0, + confirmButtonClick = { password -> + liveViewModel.enterRoom( + roomId = roomId, + onSuccess = onEnterRoomSuccess, + password = password + ) + } + ).show(screenWidthProvider()) + } else { + liveViewModel.enterRoom(roomId, onEnterRoomSuccess) + } + } else { + showPaidLiveEntryDialog( + roomId = roomId, + beginDateTimeUtc = it.beginDateTimeUtc, + price = it.price, + isPrivateRoom = it.isPrivateRoom, + onEnterRoomSuccess = onEnterRoomSuccess + ) + } + } else { + showLiveRoomDetail(roomId) + } + } + } + + private fun reservationRoom(roomId: Long) { + liveViewModel.getRoomDetail(roomId) { + if (it.manager.id == SharedPreferenceManager.userId) { + Toast.makeText( + activity, + activity.getString(R.string.screen_live_reservation_self_block), + Toast.LENGTH_LONG + ).show() + return@getRoomDetail + } + + if (it.isPrivateRoom) { + LiveRoomPasswordDialog( + activity = activity, + layoutInflater = layoutInflater, + can = if (it.isPaid) 0 else it.price, + confirmButtonClick = { password -> processLiveReservation(roomId, password) } + ).show(screenWidthProvider()) + } else if (it.price == 0 || it.isPaid) { + processLiveReservation(roomId) + } else { + LivePaymentDialog( + activity = activity, + layoutInflater = layoutInflater, + title = activity.getString( + R.string.screen_live_reservation_pay_title, + it.price.moneyFormat() + ), + desc = activity.getString(R.string.screen_live_reservation_pay_desc, it.title), + confirmButtonTitle = activity.getString(R.string.screen_live_reservation_confirm), + confirmButtonClick = { processLiveReservation(roomId) }, + cancelButtonTitle = activity.getString(R.string.cancel), + cancelButtonClick = {} + ).show(screenWidthProvider()) + } + } + } + + private fun processLiveReservation(roomId: Long, password: String? = null) { + liveViewModel.reservationRoom(roomId, password) { + refreshHome() + activity.startActivity( + Intent(activity, LiveReservationCompleteActivity::class.java).apply { + putExtra(Constants.EXTRA_LIVE_RESERVATION_RESPONSE, it) + } + ) + } + } + + private fun modifyLive(roomDetail: GetRoomDetailResponse) { + activity.startActivity( + Intent(activity, LiveRoomEditActivity::class.java).apply { + putExtra(Constants.EXTRA_ROOM_DETAIL, roomDetail) + } + ) + } + + private fun startLive(roomId: Long) { + liveViewModel.startLive(roomId) { + refreshHome() + activity.runOnUiThread { openLiveRoom(roomId) } + } + } + + private fun cancelLive(roomId: Long) { + LiveCancelDialog( + activity = activity, + layoutInflater = layoutInflater, + title = activity.getString(R.string.screen_live_cancel_title), + hint = activity.getString(R.string.screen_live_cancel_hint), + confirmButtonTitle = activity.getString(R.string.screen_live_cancel_confirm), + confirmButtonClick = { reason -> + liveViewModel.cancelLive(roomId, reason) { + Toast.makeText( + activity, + activity.getString(R.string.screen_live_cancel_success), + Toast.LENGTH_LONG + ).show() + refreshHome() + } + }, + cancelButtonTitle = activity.getString(R.string.dialog_close), + cancelButtonClick = {} + ).show(screenWidthProvider()) + } + + private fun showPaidLiveEntryDialog( + roomId: Long, + beginDateTimeUtc: String, + price: Int, + isPrivateRoom: Boolean, + onEnterRoomSuccess: () -> Unit + ) { + val locale = Locale(LanguageManager.getEffectiveLanguage(activity)) + val wrappedContext = LocaleHelper.wrap(activity) + val beginDate = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss", Locale.ENGLISH).apply { + timeZone = TimeZone.getTimeZone("UTC") + }.parse(beginDateTimeUtc) ?: return + val now = Date() + val dateFormat = SimpleDateFormat("yyyy-MM-dd, HH:mm", locale) + val diffTime = now.time - beginDate.time + val hours = (diffTime / (1000 * 60 * 60)).toInt() + val mins = (diffTime / (1000 * 60)).toInt() % 60 + + if (isPrivateRoom) { + LiveRoomPasswordDialog( + activity = activity, + layoutInflater = layoutInflater, + can = price, + confirmButtonClick = { password -> + liveViewModel.enterRoom( + roomId = roomId, + onSuccess = onEnterRoomSuccess, + password = password + ) + } + ).show(screenWidthProvider()) + return + } + + LivePaymentDialog( + activity = activity, + layoutInflater = layoutInflater, + title = wrappedContext.getString(R.string.live_paid_title), + startDateTime = if (hours >= 1) dateFormat.format(beginDate) else null, + nowDateTime = if (hours >= 1) dateFormat.format(now) else null, + desc = wrappedContext.getString(R.string.live_paid_desc, price), + desc2 = if (hours >= 1) { + wrappedContext.getString(R.string.live_paid_warning, hours, mins) + } else { + null + }, + confirmButtonTitle = wrappedContext.getString(R.string.live_paid_confirm), + confirmButtonClick = { liveViewModel.enterRoom(roomId, onEnterRoomSuccess) }, + cancelButtonTitle = wrappedContext.getString(R.string.cancel), + cancelButtonClick = {} + ).show(screenWidthProvider()) + } + + private fun openLiveRoom(roomId: Long) { + activity.startActivity( + Intent(activity, LiveRoomActivity::class.java).apply { + putExtra(Constants.EXTRA_ROOM_ID, roomId) + } + ) + } +}