라이브 방

- 하트 총 개수 조회 기능 추가
This commit is contained in:
klaus 2024-10-16 18:31:14 +09:00
parent e964679154
commit ad0c18dceb
5 changed files with 48 additions and 5 deletions

View File

@ -24,6 +24,7 @@ import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationRequest
import kr.co.vividnext.sodalive.live.room.donation.LiveRoomDonationResponse
import kr.co.vividnext.sodalive.live.room.info.GetRoomInfoResponse
import kr.co.vividnext.sodalive.live.room.kick_out.LiveRoomKickOutRequest
import kr.co.vividnext.sodalive.live.room.like.GetLiveRoomHeartTotalResponse
import kr.co.vividnext.sodalive.live.room.like.LiveRoomLikeHeartRequest
import kr.co.vividnext.sodalive.live.room.profile.GetLiveRoomUserProfileResponse
import kr.co.vividnext.sodalive.live.room.tag.GetLiveTagResponse
@ -219,4 +220,10 @@ interface LiveApi {
@Body request: LiveRoomLikeHeartRequest,
@Header("Authorization") authHeader: String
): Single<ApiResponse<Any>>
@GET("/live/room/{id}/heart-total")
fun getTotalHeartCount(
@Path("id") id: Long,
@Header("Authorization") authHeader: String
): Single<ApiResponse<GetLiveRoomHeartTotalResponse>>
}

View File

@ -251,4 +251,9 @@ class LiveRepository(
),
authHeader = token
)
fun getTotalHeartCount(roomId: Long, token: String) = api.getTotalHeartCount(
roomId,
authHeader = token
)
}

View File

@ -1091,7 +1091,7 @@ class LiveRoomActivity : BaseActivity<ActivityLiveRoomBinding>(ActivityLiveRoomB
binding.tvTotalCan.text = it.moneyFormat()
}
viewModel.totalLikeHeart.observe(this) {
viewModel.totalHeartCount.observe(this) {
binding.tvTotalHeart.text = it.moneyFormat()
}

View File

@ -66,9 +66,9 @@ class LiveRoomViewModel(
val totalDonationCan: LiveData<Int>
get() = _totalDonationCan
private val _totalLikeHeart = MutableLiveData(0)
val totalLikeHeart: LiveData<Int>
get() = _totalLikeHeart
private val _totalHeartCount = MutableLiveData(0)
val totalHeartCount: LiveData<Int>
get() = _totalHeartCount
private val _userProfileLiveData = MutableLiveData<GetLiveRoomUserProfileResponse>()
val userProfileLiveData: LiveData<GetLiveRoomUserProfileResponse>
@ -223,6 +223,7 @@ class LiveRoomViewModel(
}
getTotalDonationCan(roomId = roomId)
getTotalHeart(roomId = roomId)
if (it.data.isAdult && !SharedPreferenceManager.isAuth) {
_changeIsAdultLiveData.value = true
@ -683,7 +684,7 @@ class LiveRoomViewModel(
suspend fun addHeartDonation() {
mutex.withLock {
_totalLikeHeart.postValue(totalLikeHeart.value!! + 1)
_totalHeartCount.postValue(totalHeartCount.value!! + 1)
}
}
@ -728,6 +729,27 @@ class LiveRoomViewModel(
}
}
private fun getTotalHeart(roomId: Long) {
compositeDisposable.add(
repository.getTotalHeartCount(
roomId = roomId,
token = "Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{
if (it.success && it.data != null) {
_totalHeartCount.postValue(it.data.totalHeartCount)
}
},
{
_totalHeartCount.postValue(0)
}
)
)
}
private fun getTotalDonationCan(roomId: Long) {
compositeDisposable.add(
repository.getTotalDonationCan(

View File

@ -0,0 +1,9 @@
package kr.co.vividnext.sodalive.live.room.like
import androidx.annotation.Keep
import com.google.gson.annotations.SerializedName
@Keep
data class GetLiveRoomHeartTotalResponse(
@SerializedName("totalHeartCount") val totalHeartCount: Int
)