From 237b22df5923376275c34018b4a0398e780be678 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 19 Dec 2019 20:31:36 +0100 Subject: [PATCH] Fix lots of trouble with the completion popup (resize, change mode, etc.) - next step --- .../EpoxyAutocompletePresenter.kt | 94 ------------------- .../command/AutocompleteCommandPresenter.kt | 15 ++- .../user/AutocompleteUserPresenter.kt | 15 ++- 3 files changed, 20 insertions(+), 104 deletions(-) delete mode 100644 vector/src/main/java/im/vector/riotx/features/autocomplete/EpoxyAutocompletePresenter.kt diff --git a/vector/src/main/java/im/vector/riotx/features/autocomplete/EpoxyAutocompletePresenter.kt b/vector/src/main/java/im/vector/riotx/features/autocomplete/EpoxyAutocompletePresenter.kt deleted file mode 100644 index 0862fc059f..0000000000 --- a/vector/src/main/java/im/vector/riotx/features/autocomplete/EpoxyAutocompletePresenter.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2019 New Vector Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package im.vector.riotx.features.autocomplete - -import android.content.Context -import android.database.DataSetObserver -import android.view.ViewGroup -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView -import com.airbnb.epoxy.EpoxyController -import com.otaliastudios.autocomplete.AutocompletePresenter - -abstract class EpoxyAutocompletePresenter(context: Context) : AutocompletePresenter(context), AutocompleteClickListener { - - private var recyclerView: RecyclerView? = null - private var clicks: ClickProvider? = null - private var observer: Observer? = null - - override fun registerClickProvider(provider: ClickProvider) { - this.clicks = provider - } - - override fun registerDataSetObserver(observer: DataSetObserver) { - this.observer = Observer(observer) - } - - override fun getView(): ViewGroup? { - recyclerView = RecyclerView(context).apply { - layoutManager = LinearLayoutManager(context) - setHasFixedSize(false) - adapter = providesController().adapter - observer?.let { - adapter?.registerAdapterDataObserver(it) - } - itemAnimator = null - } - return recyclerView - } - - override fun onViewShown() {} - - override fun onViewHidden() { - recyclerView?.adapter = null - recyclerView = null - observer = null - } - - abstract fun providesController(): EpoxyController - - protected fun dispatchLayoutChange() { - observer?.onChanged() - } - - override fun onItemClick(t: T) { - clicks?.click(t) - } - - private class Observer internal constructor(private val root: DataSetObserver) : RecyclerView.AdapterDataObserver() { - - override fun onChanged() { - root.onChanged() - } - - override fun onItemRangeChanged(positionStart: Int, itemCount: Int) { - root.onChanged() - } - - override fun onItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?) { - root.onChanged() - } - - override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { - root.onChanged() - } - - override fun onItemRangeRemoved(positionStart: Int, itemCount: Int) { - root.onChanged() - } - } -} diff --git a/vector/src/main/java/im/vector/riotx/features/autocomplete/command/AutocompleteCommandPresenter.kt b/vector/src/main/java/im/vector/riotx/features/autocomplete/command/AutocompleteCommandPresenter.kt index 915689fbeb..2f076c4c53 100644 --- a/vector/src/main/java/im/vector/riotx/features/autocomplete/command/AutocompleteCommandPresenter.kt +++ b/vector/src/main/java/im/vector/riotx/features/autocomplete/command/AutocompleteCommandPresenter.kt @@ -17,21 +17,26 @@ package im.vector.riotx.features.autocomplete.command import android.content.Context -import com.airbnb.epoxy.EpoxyController -import im.vector.riotx.features.autocomplete.EpoxyAutocompletePresenter +import androidx.recyclerview.widget.RecyclerView +import com.otaliastudios.autocomplete.RecyclerViewPresenter +import im.vector.riotx.features.autocomplete.AutocompleteClickListener import im.vector.riotx.features.command.Command import javax.inject.Inject class AutocompleteCommandPresenter @Inject constructor(context: Context, private val controller: AutocompleteCommandController) : - EpoxyAutocompletePresenter(context) { + RecyclerViewPresenter(context), AutocompleteClickListener { init { controller.listener = this } - override fun providesController(): EpoxyController { - return controller + override fun instantiateAdapter(): RecyclerView.Adapter<*> { + return controller.adapter + } + + override fun onItemClick(t: Command) { + dispatchClick(t) } override fun onQuery(query: CharSequence?) { diff --git a/vector/src/main/java/im/vector/riotx/features/autocomplete/user/AutocompleteUserPresenter.kt b/vector/src/main/java/im/vector/riotx/features/autocomplete/user/AutocompleteUserPresenter.kt index 5c2d2c49c0..d60ea5db67 100644 --- a/vector/src/main/java/im/vector/riotx/features/autocomplete/user/AutocompleteUserPresenter.kt +++ b/vector/src/main/java/im/vector/riotx/features/autocomplete/user/AutocompleteUserPresenter.kt @@ -17,16 +17,17 @@ package im.vector.riotx.features.autocomplete.user import android.content.Context -import com.airbnb.epoxy.EpoxyController +import androidx.recyclerview.widget.RecyclerView import com.airbnb.mvrx.Async import com.airbnb.mvrx.Success +import com.otaliastudios.autocomplete.RecyclerViewPresenter import im.vector.matrix.android.api.session.user.model.User -import im.vector.riotx.features.autocomplete.EpoxyAutocompletePresenter +import im.vector.riotx.features.autocomplete.AutocompleteClickListener import javax.inject.Inject class AutocompleteUserPresenter @Inject constructor(context: Context, private val controller: AutocompleteUserController -) : EpoxyAutocompletePresenter(context) { +) : RecyclerViewPresenter(context), AutocompleteClickListener { var callback: Callback? = null @@ -34,8 +35,12 @@ class AutocompleteUserPresenter @Inject constructor(context: Context, controller.listener = this } - override fun providesController(): EpoxyController { - return controller + override fun instantiateAdapter(): RecyclerView.Adapter<*> { + return controller.adapter + } + + override fun onItemClick(t: User) { + dispatchClick(t) } override fun onQuery(query: CharSequence?) {