mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-24 14:05:40 +03:00
MessageSearchActivity: don't skip viewmodel when selecting message
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
0d21ce4f17
commit
1f00f426c7
2 changed files with 15 additions and 7 deletions
|
@ -118,6 +118,7 @@ class MessageSearchActivity : BaseActivity() {
|
|||
is MessageSearchViewModel.LoadedState -> showLoaded(state)
|
||||
MessageSearchViewModel.LoadingState -> showLoading()
|
||||
MessageSearchViewModel.ErrorState -> showError()
|
||||
is MessageSearchViewModel.FinishedState -> onFinish()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -169,9 +170,8 @@ class MessageSearchActivity : BaseActivity() {
|
|||
viewModel.loadMore()
|
||||
}
|
||||
MessageResultItem.VIEW_TYPE -> {
|
||||
// TODO go through viewmodel
|
||||
val messageItem = item as MessageResultItem
|
||||
finishWithResult(messageItem.messageEntry.messageId!!)
|
||||
viewModel.selectMessage(messageItem.messageEntry)
|
||||
}
|
||||
}
|
||||
return false
|
||||
|
@ -179,13 +179,16 @@ class MessageSearchActivity : BaseActivity() {
|
|||
})
|
||||
}
|
||||
|
||||
private fun finishWithResult(messageId: String) {
|
||||
private fun onFinish() {
|
||||
val state = viewModel.state.value
|
||||
if (state is MessageSearchViewModel.FinishedState) {
|
||||
val resultIntent = Intent().apply {
|
||||
putExtra(RESULT_KEY_MESSAGE_ID, messageId)
|
||||
putExtra(RESULT_KEY_MESSAGE_ID, state.selectedMessageId)
|
||||
}
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun showInitial() {
|
||||
displayLoading(false)
|
||||
|
|
|
@ -58,6 +58,7 @@ class MessageSearchViewModel @Inject constructor(private val unifiedSearchReposi
|
|||
object EmptyState : ViewState()
|
||||
object ErrorState : ViewState()
|
||||
class LoadedState(val results: List<SearchMessageEntry>, val hasMore: Boolean) : ViewState()
|
||||
class FinishedState(val selectedMessageId: String) : ViewState()
|
||||
|
||||
private lateinit var messageSearchHelper: MessageSearchHelper
|
||||
|
||||
|
@ -111,6 +112,10 @@ class MessageSearchViewModel @Inject constructor(private val unifiedSearchReposi
|
|||
query?.let { onQueryTextChange(it) }
|
||||
}
|
||||
|
||||
fun selectMessage(messageEntry: SearchMessageEntry) {
|
||||
_state.value = FinishedState(messageEntry.messageId!!)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val TAG = MessageSearchViewModel::class.simpleName
|
||||
private const val MIN_CHARS_FOR_SEARCH = 2
|
||||
|
|
Loading…
Reference in a new issue