Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-04-08 12:18:10 +02:00
parent b68ecb6247
commit 73a0d444f3
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
2 changed files with 33 additions and 14 deletions

View File

@ -92,10 +92,12 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
override val scopeProvider: LifecycleScopeProvider<*> = ControllerScopeProvider.from(this) override val scopeProvider: LifecycleScopeProvider<*> = ControllerScopeProvider.from(this)
override val lifecycleOwner = ControllerLifecycleOwner(this) override val lifecycleOwner = ControllerLifecycleOwner(this)
private lateinit var viewModel: ChatViewModel private lateinit var viewModel: ChatViewModel
val factory: ChatViewModelFactory by inject() val factory: ChatViewModelFactory by inject()
private val networkComponents: NetworkComponents by inject() private val networkComponents: NetworkComponents by inject()
private var popupBubbleScrollPosition = 0
var conversationInfoMenuItem: MenuItem? = null var conversationInfoMenuItem: MenuItem? = null
var conversationVoiceCallMenuItem: MenuItem? = null var conversationVoiceCallMenuItem: MenuItem? = null
var conversationVideoMenuItem: MenuItem? = null var conversationVideoMenuItem: MenuItem? = null
@ -128,7 +130,7 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
.addPresenter(ChatPresenter(activity as Context, ::onElementClick, ::onElementLongClick, this)) .addPresenter(ChatPresenter(activity as Context, ::onElementClick, ::onElementLongClick, this))
.into(view.messagesRecyclerView) .into(view.messagesRecyclerView)
messagesAdapter.registerAdapterDataObserver(object: RecyclerView.AdapterDataObserver() { messagesAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
super.onItemRangeInserted(positionStart, itemCount) super.onItemRangeInserted(positionStart, itemCount)
val layoutManager = view.messagesRecyclerView.layoutManager as LinearLayoutManager val layoutManager = view.messagesRecyclerView.layoutManager as LinearLayoutManager
@ -137,7 +139,10 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
view.messagesRecyclerView.smoothScrollToPosition(positionStart + 1) view.messagesRecyclerView.smoothScrollToPosition(positionStart + 1)
} }
} else { } else {
// show popup if (popupBubbleScrollPosition == 0) {
popupBubbleScrollPosition = positionStart
}
view.popupBubbleView.activate()
} }
} }
}) })
@ -160,6 +165,7 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
isReadOnlyConversation = conversation.conversationReadOnlyState == Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY isReadOnlyConversation = conversation.conversationReadOnlyState == Conversation.ConversationReadOnlyState.CONVERSATION_READ_ONLY
activity?.invalidateOptionsMenu() activity?.invalidateOptionsMenu()
setupMentionAutocomplete()
if (shouldShowLobby) { if (shouldShowLobby) {
view.messagesRecyclerView?.visibility = View.GONE view.messagesRecyclerView?.visibility = View.GONE
@ -187,6 +193,7 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
} }
} }
} }
return view return view
} }
@ -293,9 +300,11 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
private fun onElementLongClick(page: Page, holder: Presenter.Holder, element: Element<ChatElement>, payload: Map<String, String>) { private fun onElementLongClick(page: Page, holder: Presenter.Holder, element: Element<ChatElement>, payload: Map<String, String>) {
} }
override fun onAttach(view: View) { override fun onAttach(view: View) {
super.onAttach(view) super.onAttach(view)
viewModel.view = this
setupViews()
toolbar?.setOnClickListener(toolbarOnClickListener) toolbar?.setOnClickListener(toolbarOnClickListener)
} }
@ -334,7 +343,17 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
private fun setupViews() { private fun setupViews() {
view?.let { view -> view?.let { view ->
view.popupBubbleView.setRecyclerView(view.messagesRecyclerView) with(view.popupBubbleView) {
setRecyclerView(view.messagesRecyclerView)
setPopupBubbleListener {
view.messagesRecyclerView.post {
view.messagesRecyclerView.smoothScrollToPosition(popupBubbleScrollPosition)
popupBubbleScrollPosition = 0
}
deactivate()
}
}
val filters = arrayOfNulls<InputFilter>(1) val filters = arrayOfNulls<InputFilter>(1)
val lengthFilter = viewModel.user.getMaxMessageLength() val lengthFilter = viewModel.user.getMaxMessageLength()
@ -418,15 +437,16 @@ class ChatView(private val bundle: Bundle) : BaseView(), ImageLoaderInterface {
private fun setupMentionAutocomplete() { private fun setupMentionAutocomplete() {
viewModel.conversation.value?.let { conversation -> viewModel.conversation.value?.let { conversation ->
view?.let { view -> view?.let { view ->
val elevation = 6f
val backgroundDrawable = ColorDrawable(resources!!.getColor(R.color.bg_default))
val presenter = MentionAutocompletePresenter(context, conversation.token)
val callback = MentionAutocompleteCallback(
activity,
viewModel.user, view.messageInput
)
if (!::mentionAutocomplete.isInitialized) { if (!::mentionAutocomplete.isInitialized) {
val elevation = 6f
val backgroundDrawable = ColorDrawable(resources!!.getColor(R.color.bg_default))
val presenter = MentionAutocompletePresenter(activity as Context, conversation.token)
val callback = MentionAutocompleteCallback(
activity,
viewModel.user, view.messageInput
)
mentionAutocomplete = Autocomplete.on<Mention>(view.messageInput) mentionAutocomplete = Autocomplete.on<Mention>(view.messageInput)
.with(elevation) .with(elevation)
.with(backgroundDrawable) .with(backgroundDrawable)

View File

@ -71,8 +71,7 @@ class MentionAutocompletePresenter : RecyclerViewPresenter<Mention?>, FlexibleAd
} }
override fun onQuery(query: CharSequence?) { override fun onQuery(query: CharSequence?) {
val queryString: String val queryString: String = if (query != null && query.length > 1) {
queryString = if (query != null && query.length > 1) {
query.subSequence(1, query.length).toString() query.subSequence(1, query.length).toString()
} else { } else {
"" ""