Create interactor for sending messages

This commit is contained in:
Moez Bhatti
2017-10-01 17:19:15 -04:00
parent 57d9ee1f77
commit 2cab83433e
4 changed files with 46 additions and 2 deletions
@@ -5,12 +5,14 @@ import android.arch.lifecycle.ViewModel
import com.moez.QKSMS.common.di.AppComponentManager
import com.moez.QKSMS.data.model.Conversation
import com.moez.QKSMS.data.repository.MessageRepository
import com.moez.QKSMS.domain.interactor.SendMessage
import io.reactivex.subjects.PublishSubject
import javax.inject.Inject
class MessageListViewModel : ViewModel() {
@Inject lateinit var messageRepo: MessageRepository
@Inject lateinit var sendMessage: SendMessage
val state: MutableLiveData<MessageListViewState> = MutableLiveData()
var threadId: Long = 0
@@ -48,7 +50,7 @@ class MessageListViewModel : ViewModel() {
fun sendMessage(body: String) {
conversation?.takeIf { conversation -> conversation.isValid }?.let { conversation ->
messageRepo.sendMessage(threadId, conversation.contacts[0].address, body)
sendMessage.execute({}, SendMessage.Params(threadId, conversation.contacts[0].address, body))
partialStates.onNext(PartialState.TextChanged(""))
}
}
@@ -63,6 +65,7 @@ class MessageListViewModel : ViewModel() {
override fun onCleared() {
super.onCleared()
sendMessage.dispose()
conversation?.removeAllChangeListeners()
}