diff --git a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/UserProfileActivity.kt b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/UserProfileActivity.kt index cbcf738..f5e3274 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/UserProfileActivity.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/explorer/profile/UserProfileActivity.kt @@ -55,6 +55,9 @@ import kr.co.vividnext.sodalive.report.ProfileReportDialog import kr.co.vividnext.sodalive.report.ReportType import kr.co.vividnext.sodalive.report.UserReportDialog import org.koin.android.ext.android.inject +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale class UserProfileActivity : BaseActivity( ActivityUserProfileBinding::inflate @@ -848,6 +851,15 @@ class UserProfileActivity : BaseActivity( liveViewModel.enterRoom(roomId, onEnterRoomSuccess) } } else { + val beginDateFormat = SimpleDateFormat("yyyy.MM.dd EEE hh:mm a", Locale.ENGLISH) + val beginDate = beginDateFormat.parse(it.beginDateTime)!! + val now = Date() + + val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()) + val diffTime: Long = now.time - beginDate.time + val hours = (diffTime / (1000 * 60 * 60)).toInt() + val mins = (diffTime / (1000 * 60)).toInt() % 60 + if (it.isPrivateRoom) { LiveRoomPasswordDialog( activity = this, @@ -866,7 +878,21 @@ class UserProfileActivity : BaseActivity( activity = this, layoutInflater = layoutInflater, title = "${it.price.moneyFormat()}캔으로 입장", - desc = "'${it.title}' 라이브에 참여하기 위해 결제합니다.", + startDateTime = if (hours >= 1) { + dateFormat.format(beginDate) + } else { + null + }, + nowDateTime = if (hours >= 1) { + dateFormat.format(now) + } else { + null + }, + desc = if (hours >= 1) { + "라이브를 시작한지 ${hours}시간 ${mins}분 이상 지났습니다. 결제 후 참여하시겠습니까?" + } else { + "'${it.title}' 라이브에 참여하기 위해 결제합니다." + }, confirmButtonTitle = "결제 후 입장", confirmButtonClick = { liveViewModel.enterRoom(roomId, onEnterRoomSuccess) diff --git a/app/src/main/java/kr/co/vividnext/sodalive/live/LiveFragment.kt b/app/src/main/java/kr/co/vividnext/sodalive/live/LiveFragment.kt index 2ea0a33..798180c 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/live/LiveFragment.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/live/LiveFragment.kt @@ -51,6 +51,9 @@ import kr.co.vividnext.sodalive.live.room.update.LiveRoomEditActivity import kr.co.vividnext.sodalive.settings.event.EventDetailActivity import kr.co.vividnext.sodalive.settings.notification.MemberRole import org.koin.android.ext.android.inject +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale import kotlin.math.roundToInt class LiveFragment : BaseFragment(FragmentLiveBinding::inflate) { @@ -695,6 +698,15 @@ class LiveFragment : BaseFragment(FragmentLiveBinding::infl }, 300) } } else { + val beginDateFormat = SimpleDateFormat("yyyy.MM.dd EEE hh:mm a", Locale.ENGLISH) + val beginDate = beginDateFormat.parse(it.beginDateTime)!! + val now = Date() + + val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()) + val diffTime: Long = now.time - beginDate.time + val hours = (diffTime / (1000 * 60 * 60)).toInt() + val mins = (diffTime / (1000 * 60)).toInt() % 60 + if (it.isPrivateRoom) { LiveRoomPasswordDialog( activity = requireActivity(), @@ -715,7 +727,21 @@ class LiveFragment : BaseFragment(FragmentLiveBinding::infl activity = requireActivity(), layoutInflater = layoutInflater, title = "${it.price.moneyFormat()}캔으로 입장", - desc = "'${it.title}' 라이브에 참여하기 위해 결제합니다.", + startDateTime = if (hours >= 1) { + dateFormat.format(beginDate) + } else { + null + }, + nowDateTime = if (hours >= 1) { + dateFormat.format(now) + } else { + null + }, + desc = if (hours >= 1) { + "라이브를 시작한지 ${hours}시간 ${mins}분 이상 지났습니다. 결제 후 참여하시겠습니까?" + } else { + "'${it.title}' 라이브에 참여하기 위해 결제합니다." + }, confirmButtonTitle = "결제 후 입장", confirmButtonClick = { handler.postDelayed({ diff --git a/app/src/main/java/kr/co/vividnext/sodalive/live/now/all/LiveNowAllActivity.kt b/app/src/main/java/kr/co/vividnext/sodalive/live/now/all/LiveNowAllActivity.kt index 59d39d8..d5f3b70 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/live/now/all/LiveNowAllActivity.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/live/now/all/LiveNowAllActivity.kt @@ -22,6 +22,9 @@ import kr.co.vividnext.sodalive.live.room.detail.LiveRoomDetailFragment import kr.co.vividnext.sodalive.live.room.dialog.LivePaymentDialog import kr.co.vividnext.sodalive.live.room.dialog.LiveRoomPasswordDialog import org.koin.android.ext.android.inject +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale class LiveNowAllActivity : BaseActivity( ActivityLiveNowAllBinding::inflate @@ -157,6 +160,15 @@ class LiveNowAllActivity : BaseActivity( viewModel.enterRoom(roomId, onEnterRoomSuccess) } } else { + val beginDateFormat = SimpleDateFormat("yyyy.MM.dd EEE hh:mm a", Locale.ENGLISH) + val beginDate = beginDateFormat.parse(it.beginDateTime)!! + val now = Date() + + val dateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault()) + val diffTime: Long = now.time - beginDate.time + val hours = (diffTime / (1000 * 60 * 60)).toInt() + val mins = (diffTime / (1000 * 60)).toInt() % 60 + if (it.isPrivateRoom) { LiveRoomPasswordDialog( activity = this, @@ -175,7 +187,21 @@ class LiveNowAllActivity : BaseActivity( activity = this, layoutInflater = layoutInflater, title = "${it.price.moneyFormat()} 캔으로 입장", - desc = "'${it.title}' 라이브에 참여하기 위해 결제합니다.", + startDateTime = if (hours >= 1) { + dateFormat.format(beginDate) + } else { + null + }, + nowDateTime = if (hours >= 1) { + dateFormat.format(now) + } else { + null + }, + desc = if (hours >= 1) { + "라이브를 시작한지 ${hours}시간 ${mins}분 이상 지났습니다. 결제 후 참여하시겠습니까?" + } else { + "'${it.title}' 라이브에 참여하기 위해 결제합니다." + }, confirmButtonTitle = "결제 후 입장", confirmButtonClick = { viewModel.enterRoom(roomId, onEnterRoomSuccess) diff --git a/app/src/main/java/kr/co/vividnext/sodalive/live/room/dialog/LivePaymentDialog.kt b/app/src/main/java/kr/co/vividnext/sodalive/live/room/dialog/LivePaymentDialog.kt index c7ca33b..0b86c00 100644 --- a/app/src/main/java/kr/co/vividnext/sodalive/live/room/dialog/LivePaymentDialog.kt +++ b/app/src/main/java/kr/co/vividnext/sodalive/live/room/dialog/LivePaymentDialog.kt @@ -1,32 +1,90 @@ package kr.co.vividnext.sodalive.live.room.dialog import android.app.Activity +import android.graphics.Color +import android.graphics.drawable.ColorDrawable import android.view.LayoutInflater -import android.widget.LinearLayout -import kr.co.vividnext.sodalive.dialog.LiveDialog +import android.view.View +import android.view.WindowManager +import androidx.appcompat.app.AlertDialog +import kr.co.vividnext.sodalive.databinding.DialogLivePaymentBinding +import kr.co.vividnext.sodalive.extensions.dpToPx class LivePaymentDialog( activity: Activity, layoutInflater: LayoutInflater, title: String, desc: String, + startDateTime: String? = null, + nowDateTime: String? = null, confirmButtonTitle: String, confirmButtonClick: () -> Unit, cancelButtonTitle: String = "", cancelButtonClick: (() -> Unit)? = null, -) : LiveDialog( - activity, - layoutInflater, - title, - desc, - confirmButtonTitle, - confirmButtonClick, - cancelButtonTitle, - cancelButtonClick ) { + private val alertDialog: AlertDialog + private val dialogView = DialogLivePaymentBinding.inflate(layoutInflater) + init { - val lp = dialogView.tvConfirm.layoutParams as LinearLayout.LayoutParams - lp.weight = 2F - dialogView.tvConfirm.layoutParams = lp + val dialogBuilder = AlertDialog.Builder(activity) + dialogBuilder.setView(dialogView.root) + + alertDialog = dialogBuilder.create() + alertDialog.setCancelable(false) + alertDialog.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) + + dialogView.tvTitle.text = title + + if (startDateTime != null && nowDateTime != null) { + dialogView.tvDesc.visibility = View.GONE + + dialogView.tvDesc2.text = desc + dialogView.tvNowDate.text = nowDateTime + dialogView.tvStartDate.text = startDateTime + + dialogView.tvDesc2.visibility = View.VISIBLE + dialogView.llTimeNotice.visibility = View.VISIBLE + } else { + dialogView.tvDesc2.visibility = View.GONE + dialogView.llTimeNotice.visibility = View.GONE + + dialogView.tvDesc.text = desc + dialogView.tvDesc.visibility = View.VISIBLE + } + + dialogView.tvCancel.text = cancelButtonTitle + dialogView.tvCancel.setOnClickListener { + alertDialog.dismiss() + cancelButtonClick?.let { it() } + } + + dialogView.tvConfirm.text = confirmButtonTitle + dialogView.tvConfirm.setOnClickListener { + alertDialog.dismiss() + confirmButtonClick() + } + + dialogView.tvCancel.visibility = if (cancelButtonTitle.isNotBlank()) { + View.VISIBLE + } else { + View.GONE + } + + dialogView.tvConfirm.visibility = if (confirmButtonTitle.isNotBlank()) { + View.VISIBLE + } else { + View.GONE + } + } + + fun show(width: Int, message: String = "") { + alertDialog.show() + + val lp = WindowManager.LayoutParams() + lp.copyFrom(alertDialog.window?.attributes) + lp.width = width - (26.7f.dpToPx()).toInt() + lp.height = WindowManager.LayoutParams.WRAP_CONTENT + + alertDialog.window?.attributes = lp } } diff --git a/app/src/main/res/layout/dialog_live_payment.xml b/app/src/main/res/layout/dialog_live_payment.xml new file mode 100644 index 0000000..b4dcc90 --- /dev/null +++ b/app/src/main/res/layout/dialog_live_payment.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +