mirror of
https://github.com/vector-im/element-android.git
synced 2024-11-16 01:45:05 +08:00
Autocomplete : better code
This commit is contained in:
parent
3f1cc466ed
commit
fab1d249f4
@ -14,12 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package im.vector.riotredesign.core.listener
|
package im.vector.riotredesign.features.autocomplete
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple generic listener interface
|
* Simple generic listener interface
|
||||||
*/
|
*/
|
||||||
interface Listener<T> {
|
interface AutocompleteClickListener<T> {
|
||||||
|
|
||||||
fun onEvent(t: T)
|
fun onItemClick(t: T)
|
||||||
}
|
}
|
@ -23,9 +23,8 @@ import androidx.recyclerview.widget.RecyclerView
|
|||||||
import com.airbnb.epoxy.EpoxyController
|
import com.airbnb.epoxy.EpoxyController
|
||||||
import com.airbnb.epoxy.EpoxyRecyclerView
|
import com.airbnb.epoxy.EpoxyRecyclerView
|
||||||
import com.otaliastudios.autocomplete.AutocompletePresenter
|
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 recyclerView: EpoxyRecyclerView? = null
|
||||||
private var clicks: AutocompletePresenter.ClickProvider<T>? = null
|
private var clicks: AutocompletePresenter.ClickProvider<T>? = null
|
||||||
@ -64,7 +63,7 @@ abstract class EpoxyAutocompletePresenter<T>(context: Context) : AutocompletePre
|
|||||||
observer?.onChanged()
|
observer?.onChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onEvent(t: T) {
|
override fun onItemClick(t: T) {
|
||||||
clicks?.click(t)
|
clicks?.click(t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,13 +17,13 @@
|
|||||||
package im.vector.riotredesign.features.autocomplete.command
|
package im.vector.riotredesign.features.autocomplete.command
|
||||||
|
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import im.vector.riotredesign.core.listener.Listener
|
|
||||||
import im.vector.riotredesign.core.resources.StringProvider
|
import im.vector.riotredesign.core.resources.StringProvider
|
||||||
|
import im.vector.riotredesign.features.autocomplete.AutocompleteClickListener
|
||||||
import im.vector.riotredesign.features.command.Command
|
import im.vector.riotredesign.features.command.Command
|
||||||
|
|
||||||
class AutocompleteCommandController(private val stringProvider: StringProvider) : TypedEpoxyController<List<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>?) {
|
override fun buildModels(data: List<Command>?) {
|
||||||
if (data.isNullOrEmpty()) {
|
if (data.isNullOrEmpty()) {
|
||||||
@ -36,7 +36,7 @@ class AutocompleteCommandController(private val stringProvider: StringProvider)
|
|||||||
parameters(command.parameters)
|
parameters(command.parameters)
|
||||||
description(stringProvider.getString(command.description))
|
description(stringProvider.getString(command.description))
|
||||||
clickListener { _ ->
|
clickListener { _ ->
|
||||||
listener?.onEvent(command)
|
listener?.onItemClick(command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,11 +18,11 @@ package im.vector.riotredesign.features.autocomplete.user
|
|||||||
|
|
||||||
import com.airbnb.epoxy.TypedEpoxyController
|
import com.airbnb.epoxy.TypedEpoxyController
|
||||||
import im.vector.matrix.android.api.session.user.model.User
|
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>>() {
|
class AutocompleteUserController : TypedEpoxyController<List<User>>() {
|
||||||
|
|
||||||
var listener: Listener<User>? = null
|
var listener: AutocompleteClickListener<User>? = null
|
||||||
|
|
||||||
override fun buildModels(data: List<User>?) {
|
override fun buildModels(data: List<User>?) {
|
||||||
if (data.isNullOrEmpty()) {
|
if (data.isNullOrEmpty()) {
|
||||||
@ -34,7 +34,7 @@ class AutocompleteUserController : TypedEpoxyController<List<User>>() {
|
|||||||
name(user.displayName)
|
name(user.displayName)
|
||||||
avatarUrl(user.avatarUrl)
|
avatarUrl(user.avatarUrl)
|
||||||
clickListener { _ ->
|
clickListener { _ ->
|
||||||
listener?.onEvent(user)
|
listener?.onItemClick(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,11 @@ import com.airbnb.epoxy.EpoxyController
|
|||||||
import com.airbnb.mvrx.Async
|
import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
import im.vector.matrix.android.api.session.user.model.User
|
import im.vector.matrix.android.api.session.user.model.User
|
||||||
import im.vector.riotredesign.core.listener.Listener
|
|
||||||
import im.vector.riotredesign.features.autocomplete.EpoxyAutocompletePresenter
|
import im.vector.riotredesign.features.autocomplete.EpoxyAutocompletePresenter
|
||||||
|
|
||||||
class AutocompleteUserPresenter(context: Context,
|
class AutocompleteUserPresenter(context: Context,
|
||||||
private val controller: AutocompleteUserController
|
private val controller: AutocompleteUserController
|
||||||
) : EpoxyAutocompletePresenter<User>(context), Listener<User> {
|
) : EpoxyAutocompletePresenter<User>(context) {
|
||||||
|
|
||||||
var callback: Callback? = null
|
var callback: Callback? = null
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user