Autocomplete : better code

This commit is contained in:
Benoit Marty 2019-04-09 10:03:06 +02:00
parent 3f1cc466ed
commit fab1d249f4
5 changed files with 12 additions and 14 deletions

View File

@ -14,12 +14,12 @@
* limitations under the License.
*/
package im.vector.riotredesign.core.listener
package im.vector.riotredesign.features.autocomplete
/**
* Simple generic listener interface
*/
interface Listener<T> {
interface AutocompleteClickListener<T> {
fun onEvent(t: T)
fun onItemClick(t: T)
}

View File

@ -23,9 +23,8 @@ import androidx.recyclerview.widget.RecyclerView
import com.airbnb.epoxy.EpoxyController
import com.airbnb.epoxy.EpoxyRecyclerView
import com.otaliastudios.autocomplete.AutocompletePresenter
import im.vector.riotredesign.core.listener.Listener
abstract class EpoxyAutocompletePresenter<T>(context: Context) : AutocompletePresenter<T>(context), Listener<T> {
abstract class EpoxyAutocompletePresenter<T>(context: Context) : AutocompletePresenter<T>(context), AutocompleteClickListener<T> {
private var recyclerView: EpoxyRecyclerView? = null
private var clicks: AutocompletePresenter.ClickProvider<T>? = null
@ -64,7 +63,7 @@ abstract class EpoxyAutocompletePresenter<T>(context: Context) : AutocompletePre
observer?.onChanged()
}
override fun onEvent(t: T) {
override fun onItemClick(t: T) {
clicks?.click(t)
}

View File

@ -17,13 +17,13 @@
package im.vector.riotredesign.features.autocomplete.command
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.riotredesign.core.listener.Listener
import im.vector.riotredesign.core.resources.StringProvider
import im.vector.riotredesign.features.autocomplete.AutocompleteClickListener
import im.vector.riotredesign.features.command.Command
class AutocompleteCommandController(private val stringProvider: StringProvider) : TypedEpoxyController<List<Command>>() {
var listener: Listener<Command>? = null
var listener: AutocompleteClickListener<Command>? = null
override fun buildModels(data: List<Command>?) {
if (data.isNullOrEmpty()) {
@ -36,7 +36,7 @@ class AutocompleteCommandController(private val stringProvider: StringProvider)
parameters(command.parameters)
description(stringProvider.getString(command.description))
clickListener { _ ->
listener?.onEvent(command)
listener?.onItemClick(command)
}
}
}

View File

@ -18,11 +18,11 @@ package im.vector.riotredesign.features.autocomplete.user
import com.airbnb.epoxy.TypedEpoxyController
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotredesign.core.listener.Listener
import im.vector.riotredesign.features.autocomplete.AutocompleteClickListener
class AutocompleteUserController : TypedEpoxyController<List<User>>() {
var listener: Listener<User>? = null
var listener: AutocompleteClickListener<User>? = null
override fun buildModels(data: List<User>?) {
if (data.isNullOrEmpty()) {
@ -34,7 +34,7 @@ class AutocompleteUserController : TypedEpoxyController<List<User>>() {
name(user.displayName)
avatarUrl(user.avatarUrl)
clickListener { _ ->
listener?.onEvent(user)
listener?.onItemClick(user)
}
}
}

View File

@ -21,12 +21,11 @@ import com.airbnb.epoxy.EpoxyController
import com.airbnb.mvrx.Async
import com.airbnb.mvrx.Success
import im.vector.matrix.android.api.session.user.model.User
import im.vector.riotredesign.core.listener.Listener
import im.vector.riotredesign.features.autocomplete.EpoxyAutocompletePresenter
class AutocompleteUserPresenter(context: Context,
private val controller: AutocompleteUserController
) : EpoxyAutocompletePresenter<User>(context), Listener<User> {
) : EpoxyAutocompletePresenter<User>(context) {
var callback: Callback? = null