mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-21 20:49:36 +01:00
Sorting the contacts
Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
parent
171fac03c6
commit
91f40d0b7f
@ -80,7 +80,7 @@ class GenericTextHeaderItem(val model: String) : AbstractHeaderItem<GenericTextH
|
||||
) : FlexibleViewHolder(view, adapter, true) {
|
||||
|
||||
@JvmField
|
||||
@BindView(R.id.title_text_view)
|
||||
@BindView(R.id.titleTextView)
|
||||
var titleTextView: TextView? = null
|
||||
|
||||
init {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.nextcloud.talk.newarch.features.contactsflow
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isVisible
|
||||
import coil.api.load
|
||||
@ -14,59 +15,69 @@ import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.otaliastudios.elements.Element
|
||||
import com.otaliastudios.elements.Page
|
||||
import com.otaliastudios.elements.Presenter
|
||||
import com.otaliastudios.elements.extensions.HeaderSource
|
||||
import kotlinx.android.synthetic.main.rv_item_contact.view.*
|
||||
import kotlinx.android.synthetic.main.rv_item_title_header.view.*
|
||||
import org.koin.core.KoinComponent
|
||||
import org.koin.core.inject
|
||||
|
||||
open class ContactPresenter(context: Context, onElementClick: ((Page, Holder, Element<Participant>) -> Unit)?) : Presenter<Participant>(context, onElementClick), KoinComponent {
|
||||
open class ContactPresenter<T : Any>(context: Context, onElementClick: ((Page, Holder, Element<T>) -> Unit)?) : Presenter<T>(context, onElementClick), KoinComponent {
|
||||
private val globalService: GlobalService by inject()
|
||||
|
||||
override val elementTypes: Collection<Int>
|
||||
get() = listOf(0)
|
||||
get() = listOf(ParticipantElementType.PARTICIPANT.ordinal, ParticipantElementType.PARTICIPANT_HEADER.ordinal)
|
||||
|
||||
override fun onCreate(parent: ViewGroup, elementType: Int): Holder {
|
||||
return Holder(getLayoutInflater().inflate(R.layout.rv_item_contact, parent, false))
|
||||
return if (elementType == ParticipantElementType.PARTICIPANT.ordinal) {
|
||||
Holder(getLayoutInflater().inflate(R.layout.rv_item_contact, parent, false))
|
||||
} else {
|
||||
Holder(getLayoutInflater().inflate(R.layout.rv_item_title_header, parent, false))
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBind(page: Page, holder: Holder, element: Element<Participant>, payloads: List<Any>) {
|
||||
override fun onBind(page: Page, holder: Holder, element: Element<T>, payloads: List<Any>) {
|
||||
super.onBind(page, holder, element, payloads)
|
||||
|
||||
val participant = element.data
|
||||
val user = globalService.currentUserLiveData.value
|
||||
if (element.type == ParticipantElementType.PARTICIPANT.ordinal) {
|
||||
val participant = element.data as Participant?
|
||||
val user = globalService.currentUserLiveData.value
|
||||
|
||||
holder.itemView.checkedImageView.isVisible = element.data?.selected == true
|
||||
holder.itemView.checkedImageView.isVisible = participant?.selected == true
|
||||
|
||||
if (!payloads.contains(ElementPayload.SELECTION_TOGGLE)) {
|
||||
participant?.displayName?.let {
|
||||
holder.itemView.name_text.text = it
|
||||
} ?: run {
|
||||
holder.itemView.name_text.text = context.getString(R.string.nc_guest)
|
||||
}
|
||||
if (!payloads.contains(ElementPayload.SELECTION_TOGGLE)) {
|
||||
participant?.displayName?.let {
|
||||
holder.itemView.name_text.text = it
|
||||
} ?: run {
|
||||
holder.itemView.name_text.text = context.getString(R.string.nc_guest)
|
||||
}
|
||||
|
||||
when (participant?.source) {
|
||||
"users" -> {
|
||||
when (participant.type) {
|
||||
Participant.ParticipantType.GUEST, Participant.ParticipantType.GUEST_AS_MODERATOR, Participant.ParticipantType.USER_FOLLOWING_LINK -> {
|
||||
holder.itemView.avatarImageView.load(ApiUtils.getUrlForAvatarWithNameForGuests(user?.baseUrl, participant.userId, R.dimen.avatar_size)) {
|
||||
user?.getCredentials()?.let { addHeader("Authorization", it) }
|
||||
when (participant?.source) {
|
||||
"users" -> {
|
||||
when (participant.type) {
|
||||
Participant.ParticipantType.GUEST, Participant.ParticipantType.GUEST_AS_MODERATOR, Participant.ParticipantType.USER_FOLLOWING_LINK -> {
|
||||
holder.itemView.avatarImageView.load(ApiUtils.getUrlForAvatarWithNameForGuests(user?.baseUrl, participant.userId, R.dimen.avatar_size)) {
|
||||
user?.getCredentials()?.let { addHeader("Authorization", it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
holder.itemView.avatarImageView.load(ApiUtils.getUrlForAvatarWithName(user?.baseUrl, participant.userId, R.dimen.avatar_size)) {
|
||||
user?.getCredentials()?.let { addHeader("Authorization", it) }
|
||||
else -> {
|
||||
holder.itemView.avatarImageView.load(ApiUtils.getUrlForAvatarWithName(user?.baseUrl, participant.userId, R.dimen.avatar_size)) {
|
||||
user?.getCredentials()?.let { addHeader("Authorization", it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"groups", "circles" -> {
|
||||
holder.itemView.avatarImageView.load(Images().getImageWithBackground(context, R.drawable.ic_people_group_white_24px))
|
||||
}
|
||||
"emails" -> {
|
||||
holder.itemView.avatarImageView.load(Images().getImageWithBackground(context, R.drawable.ic_baseline_email_24))
|
||||
}
|
||||
else -> {
|
||||
"groups", "circles" -> {
|
||||
holder.itemView.avatarImageView.load(Images().getImageWithBackground(context, R.drawable.ic_people_group_white_24px))
|
||||
}
|
||||
"emails" -> {
|
||||
holder.itemView.avatarImageView.load(Images().getImageWithBackground(context, R.drawable.ic_baseline_email_24))
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
holder.itemView.titleTextView.text = (element.data as HeaderSource.Data<*, *>).header.toString()
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package com.nextcloud.talk.newarch.features.contactsflow
|
||||
|
||||
import android.app.Application
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.viewModelScope
|
||||
@ -12,6 +13,8 @@ import com.nextcloud.talk.newarch.domain.usecases.base.UseCaseResponse
|
||||
import com.nextcloud.talk.newarch.features.conversationslist.ConversationsListView
|
||||
import com.nextcloud.talk.newarch.services.GlobalService
|
||||
import org.koin.core.parameter.parametersOf
|
||||
import java.util.*
|
||||
import kotlin.Comparator
|
||||
|
||||
class ContactsViewModel constructor(
|
||||
application: Application,
|
||||
@ -26,11 +29,19 @@ class ContactsViewModel constructor(
|
||||
getContactsUseCase.invoke(viewModelScope, parametersOf(globalService.currentUserLiveData.value, searchQuery.value, conversationToken), object :
|
||||
UseCaseResponse<List<Participant>> {
|
||||
override suspend fun onSuccess(result: List<Participant>) {
|
||||
val sortPriority = mapOf("users" to 3, "groups" to 2, "emails" to 1, "circles" to 0)
|
||||
contactsLiveData.postValue(result.sortedWith(Comparator { o1, o2 ->
|
||||
val sortPriority = mapOf("users" to 0, "groups" to 1, "emails" to 2, "circles" to 3)
|
||||
val typeComparator = Comparator<Participant> { o1, o2 ->
|
||||
sortPriority[o2.source]?.let { sortPriority[o1.source]?.compareTo(it) }
|
||||
0
|
||||
}
|
||||
|
||||
val sortedList = result.sortedWith(compareBy({
|
||||
sortPriority[it.source]
|
||||
}, {
|
||||
it.displayName.toLowerCase(Locale.getDefault())
|
||||
}))
|
||||
|
||||
contactsLiveData.postValue(sortedList)
|
||||
}
|
||||
|
||||
override suspend fun onError(errorModel: ErrorModel?) {
|
||||
|
@ -25,7 +25,7 @@
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title_text_view"
|
||||
android:id="@+id/titleTextView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
|
Loading…
Reference in New Issue
Block a user