라이브 예약 중 전체 보기 페이지 추가

This commit is contained in:
klaus 2023-08-09 08:21:27 +09:00
parent 035fa5a2fa
commit e8b4134956
9 changed files with 582 additions and 1 deletions

View File

@ -146,4 +146,6 @@ dependencies {
// Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
implementation "com.michalsvec:single-row-calednar:1.0.0"
}

View File

@ -87,6 +87,7 @@
<activity android:name=".audio_content.upload.AudioContentUploadActivity" />
<activity android:name=".following.FollowingCreatorActivity" />
<activity android:name=".live.now.all.LiveNowAllActivity" />
<activity android:name=".live.reservation.all.LiveReservationAllActivity" />
<activity
android:name="com.google.android.gms.oss.licenses.OssLicensesMenuActivity"

View File

@ -37,6 +37,7 @@ import kr.co.vividnext.sodalive.live.now.all.LiveNowAllActivity
import kr.co.vividnext.sodalive.live.recommend.RecommendLiveAdapter
import kr.co.vividnext.sodalive.live.recommend_channel.LiveRecommendChannelAdapter
import kr.co.vividnext.sodalive.live.reservation.LiveReservationAdapter
import kr.co.vividnext.sodalive.live.reservation.all.LiveReservationAllActivity
import kr.co.vividnext.sodalive.live.reservation.complete.LiveReservationCompleteActivity
import kr.co.vividnext.sodalive.live.room.LiveRoomActivity
import kr.co.vividnext.sodalive.live.room.create.LiveRoomCreateActivity
@ -460,7 +461,11 @@ class LiveFragment : BaseFragment<FragmentLiveBinding>(FragmentLiveBinding::infl
binding.layoutLiveReservation.root.requestLayout()
}
binding.layoutLiveReservation.tvAllView.setOnClickListener {}
binding.layoutLiveReservation.tvAllView.setOnClickListener {
startActivity(
Intent(requireContext(), LiveReservationAllActivity::class.java)
)
}
}
@SuppressLint("NotifyDataSetChanged")

View File

@ -490,4 +490,47 @@ class LiveViewModel(
)
}
}
fun getLiveReservation(dateString: String? = null) {
if (!isLast && !_isLoading.value!!) {
_isLoading.postValue(true)
compositeDisposable.add(
repository.roomList(
dateString = dateString,
status = LiveRoomStatus.RESERVATION,
page = page,
size = pageSize,
token = "Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
_isLoading.postValue(false)
if (it.success && it.data != null) {
_liveReservationLiveData.postValue(it.data!!)
if (it.data.isNotEmpty()) {
page += 1
} else {
isLast = true
}
} else {
if (it.message != null) {
_toastLiveData.postValue(it.message)
} else {
_toastLiveData.postValue(
"알 수 없는 오류가 발생했습니다. 다시 시도해 주세요."
)
}
}
},
{
_isLoading.postValue(false)
it.message?.let { message -> Logger.e(message) }
_toastLiveData.postValue("알 수 없는 오류가 발생했습니다. 다시 시도해 주세요.")
}
)
)
}
}
}

View File

@ -0,0 +1,383 @@
package kr.co.vividnext.sodalive.live.reservation.all
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
import android.view.View
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.ActivityResultLauncher
import androidx.activity.result.contract.ActivityResultContracts
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.michalsvec.singlerowcalendar.calendar.CalendarChangesObserver
import com.michalsvec.singlerowcalendar.calendar.CalendarViewManager
import com.michalsvec.singlerowcalendar.calendar.SingleRowCalendarAdapter
import com.michalsvec.singlerowcalendar.selection.CalendarSelectionManager
import com.michalsvec.singlerowcalendar.utils.DateUtils
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseActivity
import kr.co.vividnext.sodalive.common.Constants
import kr.co.vividnext.sodalive.common.LoadingDialog
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.databinding.ActivityLiveReservationAllBinding
import kr.co.vividnext.sodalive.extensions.dpToPx
import kr.co.vividnext.sodalive.extensions.moneyFormat
import kr.co.vividnext.sodalive.live.LiveViewModel
import kr.co.vividnext.sodalive.live.reservation.LiveReservationAdapter
import kr.co.vividnext.sodalive.live.reservation.complete.LiveReservationCompleteActivity
import kr.co.vividnext.sodalive.live.room.LiveRoomActivity
import kr.co.vividnext.sodalive.live.room.create.LiveRoomCreateActivity
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 org.koin.android.ext.android.inject
import java.text.SimpleDateFormat
import java.util.Calendar
import java.util.Date
import java.util.Locale
class LiveReservationAllActivity : BaseActivity<ActivityLiveReservationAllBinding>(
ActivityLiveReservationAllBinding::inflate
) {
private val viewModel: LiveViewModel by inject()
private lateinit var loadingDialog: LoadingDialog
private lateinit var adapter: LiveReservationAdapter
private lateinit var selectedDateString: String
private lateinit var activityResultLauncher: ActivityResultLauncher<Intent>
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityResultLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) {
if (it.resultCode == Activity.RESULT_OK) {
refresh()
}
}
setupCalendar()
}
private fun setupCalendar() {
val myCalendarViewManager = object : CalendarViewManager {
override fun setCalendarViewResourceId(
position: Int,
date: Date,
isSelected: Boolean
): Int {
return if (isSelected)
R.layout.item_calendar_selected
else
R.layout.item_calendar
}
override fun bindDataToCalendarView(
holder: SingleRowCalendarAdapter.CalendarViewHolder,
date: Date,
position: Int,
isSelected: Boolean
) {
holder.itemView.findViewById<TextView>(
R.id.tv_date_calendar_item
).text = DateUtils.getDayNumber(date)
val tvDayCalendarItem = holder.itemView.findViewById<TextView>(
R.id.tv_day_calendar_item
)
tvDayCalendarItem.text = DateUtils.getDay3LettersName(date)
val cal = Calendar.getInstance()
cal.time = date
when (cal[Calendar.DAY_OF_WEEK]) {
Calendar.SATURDAY -> tvDayCalendarItem.setTextColor(
ContextCompat.getColor(
applicationContext,
R.color.color_2f90b7
)
)
Calendar.SUNDAY -> tvDayCalendarItem.setTextColor(
ContextCompat.getColor(
applicationContext,
R.color.color_a94400
)
)
else -> tvDayCalendarItem.setTextColor(
ContextCompat.getColor(
applicationContext,
R.color.white
)
)
}
}
}
// using calendar changes observer we can track changes in calendar
val myCalendarChangesObserver = object :
CalendarChangesObserver {
// you can override more methods, in this example we need only this one
override fun whenSelectionChanged(isSelected: Boolean, position: Int, date: Date) {
if (isSelected) {
val sdf = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
selectedDateString = sdf.format(date.time)
adapter.clear()
viewModel.page = 1
viewModel.isLast = false
viewModel.getLiveReservation(selectedDateString)
}
super.whenSelectionChanged(isSelected, position, date)
}
}
// selection manager is responsible for managing selection
val mySelectionManager = object : CalendarSelectionManager {
override fun canBeItemSelected(position: Int, date: Date): Boolean {
return true
}
}
binding.calendarView.apply {
calendarViewManager = myCalendarViewManager
calendarChangesObserver = myCalendarChangesObserver
calendarSelectionManager = mySelectionManager
setDates(getDates(mutableListOf()))
init()
select(0)
}
}
private fun getDates(list: MutableList<Date>): List<Date> {
// load dates of whole month
val calendar = Calendar.getInstance()
val currentMonth = calendar[Calendar.MONTH]
calendar.set(Calendar.MONTH, currentMonth)
calendar.set(Calendar.DAY_OF_MONTH, calendar[Calendar.DAY_OF_MONTH])
list.add(calendar.time)
for (index in 1..6) {
calendar.add(Calendar.DATE, +1)
list.add(calendar.time)
}
calendar.add(Calendar.DATE, -1)
return list
}
@SuppressLint("NotifyDataSetChanged")
override fun setupView() {
binding.toolbar.tvBack.text = "라이브, 예약 캘린더"
binding.toolbar.tvBack.setOnClickListener { finish() }
loadingDialog = LoadingDialog(this, layoutInflater)
val recyclerView = binding.rvCounselor
viewModel.toastLiveData.observe(this) {
it?.let { Toast.makeText(this, it, Toast.LENGTH_LONG).show() }
}
viewModel.isLoading.observe(this) {
if (it) {
loadingDialog.show(screenWidth, "")
} else {
loadingDialog.dismiss()
}
}
viewModel.liveReservationLiveData.observe(this) {
if (it.isEmpty()) {
if (adapter.items.isEmpty()) {
binding.swipeRefreshLayout.visibility = View.GONE
binding.llNoItems.visibility = View.VISIBLE
binding.llNoItems.setOnClickListener {
val intent = Intent(applicationContext, LiveRoomCreateActivity::class.java)
activityResultLauncher.launch(intent)
}
}
} else {
binding.swipeRefreshLayout.visibility = View.VISIBLE
binding.llNoItems.visibility = View.GONE
adapter.items.addAll(it)
adapter.notifyDataSetChanged()
}
}
adapter = LiveReservationAdapter {
val detailFragment = LiveRoomDetailFragment(
it.roomId,
onClickParticipant = {},
onClickReservation = { onClickReservation(it.roomId) },
onClickModify = { roomDetailResponse -> onClickModify(roomDetailResponse) },
onClickStart = { onClickStart(it.roomId) },
onClickCancel = { onClickCancel(it.roomId) }
)
if (detailFragment.isAdded) return@LiveReservationAdapter
detailFragment.show(
supportFragmentManager,
detailFragment.tag
)
}
recyclerView.layoutManager = LinearLayoutManager(
applicationContext,
LinearLayoutManager.VERTICAL,
false
)
recyclerView.addItemDecoration(object : RecyclerView.ItemDecoration() {
override fun getItemOffsets(
outRect: Rect,
view: View,
parent: RecyclerView,
state: RecyclerView.State
) {
super.getItemOffsets(outRect, view, parent, state)
when (parent.getChildAdapterPosition(view)) {
0 -> {
outRect.top = 0.dpToPx().toInt()
outRect.bottom = 6.7f.dpToPx().toInt()
}
adapter.itemCount - 1 -> {
outRect.top = 6.7f.dpToPx().toInt()
outRect.bottom = 0.dpToPx().toInt()
}
else -> {
outRect.top = 6.7f.dpToPx().toInt()
outRect.bottom = 6.7f.dpToPx().toInt()
}
}
}
})
recyclerView.adapter = adapter
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
super.onScrolled(recyclerView, dx, dy)
val lastVisiblePosition = (recyclerView.layoutManager as LinearLayoutManager)
.findLastVisibleItemPosition()
val itemTotalCount = adapter.itemCount - 1
if (lastVisiblePosition == itemTotalCount) {
viewModel.getLiveReservation(selectedDateString)
}
}
})
binding.swipeRefreshLayout.setOnRefreshListener { refresh() }
}
private fun refresh() {
adapter.clear()
viewModel.page = 1
viewModel.isLast = false
viewModel.getLiveReservation(selectedDateString)
binding.swipeRefreshLayout.isRefreshing = false
}
private fun onClickReservation(roomId: Long) {
viewModel.getRoomDetail(roomId) {
if (it.manager.id == SharedPreferenceManager.userId) {
showToast("내가 만든 라이브는 예약할 수 없습니다.")
} else {
if (it.isPrivateRoom) {
LiveRoomPasswordDialog(
activity = this,
layoutInflater = layoutInflater,
can = if (it.isPaid) 0 else it.price,
confirmButtonClick = { password ->
processLiveReservation(roomId, password)
}
).show(screenWidth)
} else {
if (it.price == 0 || it.isPaid) {
processLiveReservation(roomId)
} else {
LivePaymentDialog(
activity = this,
layoutInflater = layoutInflater,
title = "${it.price.moneyFormat()} 캔으로 예약",
desc = "'${it.title}' 라이브에 참여하기 위해 결제합니다.",
confirmButtonTitle = "예약하기",
confirmButtonClick = { processLiveReservation(roomId) },
cancelButtonTitle = "취소",
cancelButtonClick = {}
).show(screenWidth)
}
}
}
}
}
private fun processLiveReservation(roomId: Long, password: String? = null) {
viewModel.reservationRoom(roomId, password) {
refresh()
val intent = Intent(
applicationContext,
LiveReservationCompleteActivity::class.java
)
intent.putExtra(Constants.EXTRA_LIVE_RESERVATION_RESPONSE, it)
startActivity(intent)
}
}
private fun onClickStart(roomId: Long) {
val onEnterRoomSuccess = {
viewModel.getSummary()
runOnUiThread {
val intent = Intent(applicationContext, LiveRoomActivity::class.java)
intent.putExtra(Constants.EXTRA_ROOM_ID, roomId)
startActivity(intent)
}
}
viewModel.startLive(roomId, onEnterRoomSuccess)
}
private fun onClickCancel(roomId: Long) {
LiveCancelDialog(
activity = this,
layoutInflater = layoutInflater,
title = "예약취소",
hint = "취소사유를 입력하세요.",
confirmButtonTitle = "예약취소",
confirmButtonClick = {
viewModel.cancelLive(roomId, it) {
Toast.makeText(
applicationContext,
"예약이 취소되었습니다.",
Toast.LENGTH_LONG
).show()
adapter.clear()
refresh()
}
},
cancelButtonTitle = "닫기",
cancelButtonClick = {}
).show(screenWidth)
}
private fun onClickModify(roomDetail: GetRoomDetailResponse) {
startActivity(
Intent(applicationContext, LiveRoomEditActivity::class.java).apply {
putExtra(Constants.EXTRA_ROOM_DETAIL, roomDetail)
}
)
}
}

View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/detail_toolbar" />
<com.michalsvec.singlerowcalendar.calendar.SingleRowCalendar
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:clipToPadding="false"
android:paddingHorizontal="15.3dp"
app:deselection="false"
app:longPress="false"
app:multiSelection="false" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="16.7dp"
android:background="@color/color_88909090" />
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_counselor"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:padding="13.3dp" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<LinearLayout
android:id="@+id/ll_no_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="13.3dp"
android:layout_marginTop="28.3dp"
android:background="@drawable/bg_round_corner_4_7_2b2635"
android:gravity="center"
android:orientation="vertical"
android:paddingVertical="16.7dp"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_no_item" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:text="지금 예약중인 라이브가 없습니다.\n직접 라이브를 만들어 보세요!"
android:textColor="@color/color_bbbbbb"
android:textSize="10.7sp"
tools:ignore="SmallSp" />
<TextView
android:id="@+id/tv_make_room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_round_corner_4_7_9970ff"
android:drawablePadding="8.3dp"
android:fontFamily="@font/gmarket_sans_bold"
android:gravity="center"
android:paddingHorizontal="51.7dp"
android:paddingVertical="8.3dp"
android:text="라이브 만들기"
android:textColor="@color/white"
android:textSize="13.3sp"
app:drawableStartCompat="@drawable/ic_plus_no_bg" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cl_calendar_item"
android:layout_width="53.3dp"
android:layout_height="66.7dp"
android:layout_marginHorizontal="6.7dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_day_calendar_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:textColor="@color/white"
android:textSize="11.3sp" />
<TextView
android:id="@+id/tv_date_calendar_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4.7dp"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15.3sp" />
</LinearLayout>

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/cl_calendar_item"
android:layout_width="53.3dp"
android:layout_height="66.7dp"
android:layout_marginHorizontal="6.7dp"
android:background="@drawable/bg_round_corner_4_7_9970ff"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/tv_day_calendar_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/gmarket_sans_medium"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="11.3sp" />
<TextView
android:id="@+id/tv_date_calendar_item"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4.7dp"
android:fontFamily="@font/gmarket_sans_bold"
android:gravity="center"
android:textColor="@android:color/white"
android:textSize="15.3sp" />
</LinearLayout>

View File

@ -94,4 +94,6 @@
<color name="color_26ffffff">#26FFFFFF</color>
<color name="color_979797">#979797</color>
<color name="color_660fd4">#660FD4</color>
<color name="color_2f90b7">#2F90B7</color>
<color name="color_a94400">#A94400</color>
</resources>