feat(creator-channel): FanTalk 글 입력 상태 관리를 추가한다

This commit is contained in:
2026-07-08 03:44:22 +09:00
parent e8e8a63d6d
commit 34266abd90
3 changed files with 256 additions and 0 deletions

View File

@@ -160,4 +160,11 @@ class CreatorChannelRepository(
request = PutModifyCheersRequest(cheersId = fanTalkId, isActive = false),
token = token
)
fun writeFanTalk(creatorId: Long, content: String, token: String) = explorerRepository.writeCheers(
parentCheersId = null,
creatorId = creatorId,
content = content,
token = token
)
}

View File

@@ -0,0 +1,89 @@
package kr.co.vividnext.sodalive.v2.creator.channel.fantalk.write
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import com.orhanobut.logger.Logger
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.co.vividnext.sodalive.R
import kr.co.vividnext.sodalive.base.BaseViewModel
import kr.co.vividnext.sodalive.common.SharedPreferenceManager
import kr.co.vividnext.sodalive.common.SodaLiveApplicationHolder
import kr.co.vividnext.sodalive.v2.creator.channel.data.CreatorChannelRepository
class CreatorChannelFanTalkWriteViewModel(
private val repository: CreatorChannelRepository
) : BaseViewModel() {
private val _contentLiveData = MutableLiveData("")
val contentLiveData: LiveData<String>
get() = _contentLiveData
private val _isSendEnabledLiveData = MutableLiveData(false)
val isSendEnabledLiveData: LiveData<Boolean>
get() = _isSendEnabledLiveData
private val _contentLengthLiveData = MutableLiveData(0)
val contentLengthLiveData: LiveData<Int>
get() = _contentLengthLiveData
private val _isLoadingLiveData = MutableLiveData(false)
val isLoadingLiveData: LiveData<Boolean>
get() = _isLoadingLiveData
private val _finishEventLiveData = MutableLiveData(false)
val finishEventLiveData: LiveData<Boolean>
get() = _finishEventLiveData
private val _toastEventLiveData = MutableLiveData<String?>()
val toastEventLiveData: LiveData<String?>
get() = _toastEventLiveData
fun onContentChanged(content: String) {
val limitedContent = content.take(MAX_CONTENT_LENGTH)
_contentLiveData.value = limitedContent
_contentLengthLiveData.value = limitedContent.length
_isSendEnabledLiveData.value = limitedContent.trim().isNotEmpty()
}
fun submit(creatorId: Long) {
val trimmedContent = _contentLiveData.value.orEmpty().trim()
if (creatorId <= 0L) return
if (_isLoadingLiveData.value == true) return
if (trimmedContent.isEmpty()) return
_isLoadingLiveData.value = true
compositeDisposable.add(
repository.writeFanTalk(
creatorId = creatorId,
content = trimmedContent,
token = "Bearer ${SharedPreferenceManager.token}"
)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
{ response ->
_isLoadingLiveData.value = false
if (response.success) {
_finishEventLiveData.value = true
} else {
_toastEventLiveData.value = response.message ?: unknownErrorMessage()
}
},
{ error ->
_isLoadingLiveData.value = false
error.message?.let { Logger.e(it) }
_toastEventLiveData.value = unknownErrorMessage()
}
)
)
}
private fun unknownErrorMessage(): String {
return SodaLiveApplicationHolder.get().getString(R.string.common_error_unknown)
}
companion object {
const val MAX_CONTENT_LENGTH: Int = 500
}
}