mirror of
https://github.com/quik-sms/quik.git
synced 2026-11-22 21:58:53 +01:00
Fixed freezing when typing fast or using auto complete
This commit is contained in:
@@ -178,12 +178,15 @@ class ComposeActivity : QkActivity<ComposeViewModel>(), ComposeView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (title != state.title) title = state.title
|
if (title != state.title) title = state.title
|
||||||
if (message.text.toString() != state.draft) message.setText(state.draft)
|
|
||||||
|
|
||||||
send.isEnabled = state.canSend
|
send.isEnabled = state.canSend
|
||||||
sendIcon.isEnabled = state.canSend
|
sendIcon.isEnabled = state.canSend
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun setDraft(draft: String) {
|
||||||
|
message.setText(draft)
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
|
||||||
menuInflater.inflate(R.menu.compose, menu)
|
menuInflater.inflate(R.menu.compose, menu)
|
||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
|
|||||||
@@ -13,6 +13,5 @@ data class ComposeState(
|
|||||||
val title: String = "",
|
val title: String = "",
|
||||||
val archived: Boolean = false,
|
val archived: Boolean = false,
|
||||||
val messages: RealmResults<Message>? = null,
|
val messages: RealmResults<Message>? = null,
|
||||||
val draft: String = "",
|
|
||||||
val canSend: Boolean = false
|
val canSend: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -22,4 +22,6 @@ interface ComposeView : QkView<ComposeState> {
|
|||||||
val attachIntent: Observable<Unit>
|
val attachIntent: Observable<Unit>
|
||||||
val sendIntent: Observable<Unit>
|
val sendIntent: Observable<Unit>
|
||||||
|
|
||||||
|
fun setDraft(draft: String)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,8 +24,8 @@ import io.reactivex.subjects.PublishSubject
|
|||||||
import io.reactivex.subjects.Subject
|
import io.reactivex.subjects.Subject
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class ComposeViewModel(threadId: Long, body: String)
|
class ComposeViewModel(threadId: Long, var draft: String)
|
||||||
: QkViewModel<ComposeView, ComposeState>(ComposeState(editingMode = threadId == 0L, draft = body)) {
|
: QkViewModel<ComposeView, ComposeState>(ComposeState(editingMode = threadId == 0L)) {
|
||||||
|
|
||||||
@Inject lateinit var context: Context
|
@Inject lateinit var context: Context
|
||||||
@Inject lateinit var contactFilter: ContactFilter
|
@Inject lateinit var contactFilter: ContactFilter
|
||||||
@@ -108,6 +108,11 @@ class ComposeViewModel(threadId: Long, body: String)
|
|||||||
override fun bindView(view: ComposeView) {
|
override fun bindView(view: ComposeView) {
|
||||||
super.bindView(view)
|
super.bindView(view)
|
||||||
|
|
||||||
|
if (draft.isNotEmpty()) {
|
||||||
|
view.setDraft(draft)
|
||||||
|
draft = ""
|
||||||
|
}
|
||||||
|
|
||||||
// Set the contact suggestions list to visible at all times when in editing mode and there are no contacts
|
// Set the contact suggestions list to visible at all times when in editing mode and there are no contacts
|
||||||
// selected yet, and also visible while in editing mode and there is text entered in the query field
|
// selected yet, and also visible while in editing mode and there is text entered in the query field
|
||||||
intents += Observables
|
intents += Observables
|
||||||
@@ -177,7 +182,7 @@ class ComposeViewModel(threadId: Long, body: String)
|
|||||||
|
|
||||||
// Enable the send button when there is text input into the new message body, disable otherwise
|
// Enable the send button when there is text input into the new message body, disable otherwise
|
||||||
intents += view.textChangedIntent.subscribe { text ->
|
intents += view.textChangedIntent.subscribe { text ->
|
||||||
newState { it.copy(draft = text.toString(), canSend = text.isNotEmpty()) }
|
newState { it.copy(canSend = text.isNotEmpty()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
// Send a message when the send button is clicked, and disable editing mode if it's enabled
|
||||||
@@ -188,7 +193,12 @@ class ComposeViewModel(threadId: Long, body: String)
|
|||||||
val threadId = conversation.id
|
val threadId = conversation.id
|
||||||
val address = conversation.recipients.first()?.address.orEmpty()
|
val address = conversation.recipients.first()?.address.orEmpty()
|
||||||
sendMessage.execute(SendMessage.Params(threadId, address, body))
|
sendMessage.execute(SendMessage.Params(threadId, address, body))
|
||||||
newState { it.copy(editingMode = false, draft = "", canSend = false) }
|
view.setDraft("")
|
||||||
|
})
|
||||||
|
.withLatestFrom(state, {_, state ->
|
||||||
|
if (state.editingMode) {
|
||||||
|
newState { it.copy(editingMode = false) }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.subscribe()
|
.subscribe()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user