메시지 추가 로딩 되지 않는 버그 수정
This commit is contained in:
parent
9ed175191b
commit
4d4ddb50ac
|
@ -27,7 +27,7 @@ class TextMessageViewModel(private val repository: MessageRepository) : BaseView
|
|||
|
||||
var page = 1
|
||||
var pageSize = 10
|
||||
private var totalCount = 0
|
||||
private var isLast = false
|
||||
|
||||
private var _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
|
@ -35,6 +35,7 @@ class TextMessageViewModel(private val repository: MessageRepository) : BaseView
|
|||
|
||||
fun selectMessageBox(messageBox: MessageBox) {
|
||||
if (messageBox != _messageBoxLiveData.value!!) {
|
||||
isLast = false
|
||||
page = 1
|
||||
_messageBoxLiveData.postValue(messageBox)
|
||||
getMessages(messageBox)
|
||||
|
@ -42,7 +43,7 @@ class TextMessageViewModel(private val repository: MessageRepository) : BaseView
|
|||
}
|
||||
|
||||
fun getMessages(messageBox: MessageBox = _messageBoxLiveData.value!!) {
|
||||
if (!_isLoading.value!! && (page - 1 == 0 || totalCount > page * pageSize)) {
|
||||
if (!_isLoading.value!! && !isLast) {
|
||||
_isLoading.postValue(true)
|
||||
|
||||
val messageBoxObservable = when (messageBox) {
|
||||
|
@ -78,10 +79,13 @@ class TextMessageViewModel(private val repository: MessageRepository) : BaseView
|
|||
.subscribe(
|
||||
{
|
||||
if (it.success && it.data != null) {
|
||||
totalCount = it.data.totalCount
|
||||
_getMessagesLiveData.postValue(it.data.items)
|
||||
|
||||
page += 1
|
||||
if (it.data.items.isNotEmpty()) {
|
||||
_getMessagesLiveData.postValue(it.data.items)
|
||||
} else {
|
||||
isLast = true
|
||||
_getMessagesLiveData.postValue(listOf())
|
||||
}
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
|
|
|
@ -27,7 +27,7 @@ class VoiceMessageViewModel(private val repository: MessageRepository) : BaseVie
|
|||
|
||||
var page = 1
|
||||
var pageSize = 10
|
||||
private var totalCount = 0
|
||||
private var isLast = false
|
||||
|
||||
private var _isLoading = MutableLiveData(false)
|
||||
val isLoading: LiveData<Boolean>
|
||||
|
@ -35,6 +35,7 @@ class VoiceMessageViewModel(private val repository: MessageRepository) : BaseVie
|
|||
|
||||
fun selectMessageBox(messageBox: MessageBox) {
|
||||
if (messageBox != _messageBoxLiveData.value!!) {
|
||||
isLast = false
|
||||
page = 1
|
||||
_messageBoxLiveData.postValue(messageBox)
|
||||
getMessages(messageBox)
|
||||
|
@ -42,7 +43,7 @@ class VoiceMessageViewModel(private val repository: MessageRepository) : BaseVie
|
|||
}
|
||||
|
||||
fun getMessages(messageBox: MessageBox = _messageBoxLiveData.value!!) {
|
||||
if (!_isLoading.value!! && (page - 1 == 0 || totalCount > page * pageSize)) {
|
||||
if (!_isLoading.value!! && !isLast) {
|
||||
_isLoading.postValue(true)
|
||||
val messageBoxObservable = when (messageBox) {
|
||||
MessageBox.SENT -> {
|
||||
|
@ -77,10 +78,13 @@ class VoiceMessageViewModel(private val repository: MessageRepository) : BaseVie
|
|||
.subscribe(
|
||||
{
|
||||
if (it.success && it.data != null) {
|
||||
totalCount = it.data.totalCount
|
||||
_getMessagesLiveData.postValue(it.data.items)
|
||||
|
||||
page += 1
|
||||
if (it.data.items.isNotEmpty()) {
|
||||
_getMessagesLiveData.postValue(it.data.items)
|
||||
} else {
|
||||
isLast = true
|
||||
_getMessagesLiveData.postValue(listOf())
|
||||
}
|
||||
} else {
|
||||
if (it.message != null) {
|
||||
_toastLiveData.postValue(it.message)
|
||||
|
|
Loading…
Reference in New Issue