mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 21:15:30 +03:00
convert ParticipantItem to kt
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
9fa560e97d
commit
8216811e99
2 changed files with 256 additions and 300 deletions
|
@ -1,300 +0,0 @@
|
||||||
/*
|
|
||||||
* Nextcloud Talk - Android Client
|
|
||||||
*
|
|
||||||
* SPDX-FileCopyrightText: 2022 Marcel Hibbe <dev@mhibbe.de>
|
|
||||||
* SPDX-FileCopyrightText: 2021 Andy Scherzinger <infoi@andy-scherzinger.de>
|
|
||||||
* SPDX-FileCopyrightText: 2017 Mario Danic <mario@lovelyhq.com>
|
|
||||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
*/
|
|
||||||
package com.nextcloud.talk.adapters.items;
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.View;
|
|
||||||
|
|
||||||
import com.nextcloud.talk.R;
|
|
||||||
import com.nextcloud.talk.application.NextcloudTalkApplication;
|
|
||||||
import com.nextcloud.talk.data.user.model.User;
|
|
||||||
import com.nextcloud.talk.databinding.RvItemConversationInfoParticipantBinding;
|
|
||||||
import com.nextcloud.talk.extensions.ImageViewExtensionsKt;
|
|
||||||
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter;
|
|
||||||
import com.nextcloud.talk.models.json.participants.Participant;
|
|
||||||
import com.nextcloud.talk.models.json.participants.Participant.InCallFlags;
|
|
||||||
import com.nextcloud.talk.models.json.status.StatusType;
|
|
||||||
import com.nextcloud.talk.ui.StatusDrawable;
|
|
||||||
import com.nextcloud.talk.ui.theme.ViewThemeUtils;
|
|
||||||
import com.nextcloud.talk.utils.DisplayUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter;
|
|
||||||
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem;
|
|
||||||
import eu.davidea.flexibleadapter.items.IFilterable;
|
|
||||||
import eu.davidea.viewholders.FlexibleViewHolder;
|
|
||||||
|
|
||||||
public class ParticipantItem extends AbstractFlexibleItem<ParticipantItem.ParticipantItemViewHolder> implements
|
|
||||||
IFilterable<String> {
|
|
||||||
|
|
||||||
private static final float STATUS_SIZE_IN_DP = 9f;
|
|
||||||
private static final String NO_ICON = "";
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private final Participant participant;
|
|
||||||
private final User user;
|
|
||||||
private final ViewThemeUtils viewThemeUtils;
|
|
||||||
public boolean isOnline = true;
|
|
||||||
|
|
||||||
public ParticipantItem(Context activityContext,
|
|
||||||
Participant participant,
|
|
||||||
User user, ViewThemeUtils viewThemeUtils) {
|
|
||||||
this.context = activityContext;
|
|
||||||
this.participant = participant;
|
|
||||||
this.user = user;
|
|
||||||
this.viewThemeUtils = viewThemeUtils;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Participant getModel() {
|
|
||||||
return participant;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (o instanceof ParticipantItem inItem) {
|
|
||||||
return participant.getCalculatedActorType() == inItem.getModel().getCalculatedActorType() &&
|
|
||||||
participant.getCalculatedActorId().equals(inItem.getModel().getCalculatedActorId());
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return participant.hashCode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLayoutRes() {
|
|
||||||
return R.layout.rv_item_conversation_info_participant;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ParticipantItemViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
|
|
||||||
return new ParticipantItemViewHolder(view, adapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
|
||||||
@Override
|
|
||||||
public void bindViewHolder(FlexibleAdapter adapter, ParticipantItemViewHolder holder, int position, List payloads) {
|
|
||||||
|
|
||||||
drawStatus(holder);
|
|
||||||
|
|
||||||
if (!isOnline) {
|
|
||||||
holder.binding.nameText.setTextColor(ResourcesCompat.getColor(
|
|
||||||
holder.binding.nameText.getContext().getResources(),
|
|
||||||
R.color.medium_emphasis_text,
|
|
||||||
null)
|
|
||||||
);
|
|
||||||
holder.binding.avatarView.setAlpha(0.38f);
|
|
||||||
} else {
|
|
||||||
holder.binding.nameText.setTextColor(ResourcesCompat.getColor(
|
|
||||||
holder.binding.nameText.getContext().getResources(),
|
|
||||||
R.color.high_emphasis_text,
|
|
||||||
null)
|
|
||||||
);
|
|
||||||
holder.binding.avatarView.setAlpha(1.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
holder.binding.nameText.setText(participant.getDisplayName());
|
|
||||||
|
|
||||||
if (adapter.hasFilter()) {
|
|
||||||
viewThemeUtils.talk.themeAndHighlightText(holder.binding.nameText, participant.getDisplayName(),
|
|
||||||
String.valueOf(adapter.getFilter(String.class)));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (TextUtils.isEmpty(participant.getDisplayName()) &&
|
|
||||||
(participant.getType() == Participant.ParticipantType.GUEST ||
|
|
||||||
participant.getType() == Participant.ParticipantType.USER_FOLLOWING_LINK)) {
|
|
||||||
holder.binding.nameText.setText(NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_guest));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (participant.getCalculatedActorType() == Participant.ActorType.GROUPS ||
|
|
||||||
"groups".equals(participant.getSource()) ||
|
|
||||||
participant.getCalculatedActorType() == Participant.ActorType.CIRCLES ||
|
|
||||||
"circles".equals(participant.getSource())) {
|
|
||||||
ImageViewExtensionsKt.loadDefaultGroupCallAvatar(holder.binding.avatarView, viewThemeUtils);
|
|
||||||
} else if (participant.getCalculatedActorType() == Participant.ActorType.EMAILS) {
|
|
||||||
ImageViewExtensionsKt.loadMailAvatar(holder.binding.avatarView, viewThemeUtils);
|
|
||||||
} else if (participant.getCalculatedActorType() == Participant.ActorType.GUESTS ||
|
|
||||||
participant.getType() == Participant.ParticipantType.GUEST ||
|
|
||||||
participant.getType() == Participant.ParticipantType.GUEST_MODERATOR) {
|
|
||||||
|
|
||||||
String displayName = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getResources()
|
|
||||||
.getString(R.string.nc_guest);
|
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(participant.getDisplayName())) {
|
|
||||||
displayName = participant.getDisplayName();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImageViewExtensionsKt.loadGuestAvatar(holder.binding.avatarView, user, displayName, false);
|
|
||||||
|
|
||||||
} else if (participant.getCalculatedActorType() == Participant.ActorType.USERS ||
|
|
||||||
"users".equals(participant.getSource())) {
|
|
||||||
ImageViewExtensionsKt.loadUserAvatar(holder.binding.avatarView,
|
|
||||||
user,
|
|
||||||
participant.getCalculatedActorId(),
|
|
||||||
true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
Resources resources = NextcloudTalkApplication.Companion.getSharedApplication().getResources();
|
|
||||||
|
|
||||||
long inCallFlag = participant.getInCall();
|
|
||||||
if ((inCallFlag & InCallFlags.WITH_PHONE) > 0) {
|
|
||||||
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_call_grey_600_24dp);
|
|
||||||
holder.binding.videoCallIcon.setVisibility(View.VISIBLE);
|
|
||||||
holder.binding.videoCallIcon.setContentDescription(
|
|
||||||
resources.getString(R.string.nc_call_state_with_phone, participant.getDisplayName()));
|
|
||||||
} else if ((inCallFlag & InCallFlags.WITH_VIDEO) > 0) {
|
|
||||||
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_videocam_grey_600_24dp);
|
|
||||||
holder.binding.videoCallIcon.setVisibility(View.VISIBLE);
|
|
||||||
holder.binding.videoCallIcon.setContentDescription(
|
|
||||||
resources.getString(R.string.nc_call_state_with_video, participant.getDisplayName()));
|
|
||||||
} else if (inCallFlag > InCallFlags.DISCONNECTED) {
|
|
||||||
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_mic_grey_600_24dp);
|
|
||||||
holder.binding.videoCallIcon.setVisibility(View.VISIBLE);
|
|
||||||
holder.binding.videoCallIcon.setContentDescription(
|
|
||||||
resources.getString(R.string.nc_call_state_in_call, participant.getDisplayName()));
|
|
||||||
} else {
|
|
||||||
holder.binding.videoCallIcon.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
String userType = "";
|
|
||||||
|
|
||||||
switch (new EnumParticipantTypeConverter().convertToInt(participant.getType())) {
|
|
||||||
case 1:
|
|
||||||
//userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_owner);
|
|
||||||
//break;
|
|
||||||
case 2:
|
|
||||||
case 6: // Guest moderator
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_moderator);
|
|
||||||
break;
|
|
||||||
case 3:
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_user);
|
|
||||||
if (participant.getCalculatedActorType() == Participant.ActorType.GROUPS) {
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_group);
|
|
||||||
}
|
|
||||||
if (participant.getCalculatedActorType() == Participant.ActorType.CIRCLES) {
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_team);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
userType = NextcloudTalkApplication.Companion.getSharedApplication().getString(R.string.nc_guest);
|
|
||||||
if (participant.getCalculatedActorType() == Participant.ActorType.EMAILS) {
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_email);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
userType = NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_following_link);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!userType.equals(NextcloudTalkApplication
|
|
||||||
.Companion
|
|
||||||
.getSharedApplication()
|
|
||||||
.getString(R.string.nc_user))) {
|
|
||||||
holder.binding.secondaryText.setText("(" + userType + ")");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void drawStatus(ParticipantItemViewHolder holder) {
|
|
||||||
float size = DisplayUtils.convertDpToPixel(STATUS_SIZE_IN_DP, context);
|
|
||||||
holder.binding.userStatusImage.setImageDrawable(new StatusDrawable(
|
|
||||||
participant.getStatus(),
|
|
||||||
NO_ICON,
|
|
||||||
size,
|
|
||||||
context.getResources().getColor(R.color.bg_default),
|
|
||||||
context));
|
|
||||||
|
|
||||||
if (participant.getStatusMessage() != null) {
|
|
||||||
holder.binding.conversationInfoStatusMessage.setText(participant.getStatusMessage());
|
|
||||||
alignUsernameVertical(holder, 0);
|
|
||||||
} else {
|
|
||||||
holder.binding.conversationInfoStatusMessage.setText("");
|
|
||||||
alignUsernameVertical(holder, 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (participant.getStatusIcon() != null && !participant.getStatusIcon().isEmpty()) {
|
|
||||||
holder.binding.participantStatusEmoji.setText(participant.getStatusIcon());
|
|
||||||
} else {
|
|
||||||
holder.binding.participantStatusEmoji.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (participant.getStatus() != null && participant.getStatus().equals(StatusType.DND.getString())) {
|
|
||||||
if (participant.getStatusMessage() == null || participant.getStatusMessage().isEmpty()) {
|
|
||||||
holder.binding.conversationInfoStatusMessage.setText(R.string.dnd);
|
|
||||||
}
|
|
||||||
} else if (participant.getStatus() != null && participant.getStatus().equals(StatusType.AWAY.getString())) {
|
|
||||||
if (participant.getStatusMessage() == null || participant.getStatusMessage().isEmpty()) {
|
|
||||||
holder.binding.conversationInfoStatusMessage.setText(R.string.away);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void alignUsernameVertical(ParticipantItem.ParticipantItemViewHolder holder, float densityPixelsFromTop) {
|
|
||||||
ConstraintLayout.LayoutParams layoutParams =
|
|
||||||
(ConstraintLayout.LayoutParams) holder.binding.nameText.getLayoutParams();
|
|
||||||
layoutParams.topMargin = (int) DisplayUtils.convertDpToPixel(densityPixelsFromTop, context);
|
|
||||||
holder.binding.nameText.setLayoutParams(layoutParams);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean filter(String constraint) {
|
|
||||||
return participant.getDisplayName() != null &&
|
|
||||||
(Pattern.compile(constraint, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
|
||||||
.matcher(participant.getDisplayName().trim()).find() ||
|
|
||||||
Pattern.compile(constraint, Pattern.CASE_INSENSITIVE | Pattern.LITERAL)
|
|
||||||
.matcher(participant.getCalculatedActorId().trim()).find());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ParticipantItemViewHolder extends FlexibleViewHolder {
|
|
||||||
|
|
||||||
RvItemConversationInfoParticipantBinding binding;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Default constructor.
|
|
||||||
*/
|
|
||||||
ParticipantItemViewHolder(View view, FlexibleAdapter adapter) {
|
|
||||||
super(view, adapter);
|
|
||||||
binding = RvItemConversationInfoParticipantBinding.bind(view);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,256 @@
|
||||||
|
/*
|
||||||
|
* Nextcloud Talk - Android Client
|
||||||
|
*
|
||||||
|
* SPDX-FileCopyrightText: 2022 Marcel Hibbe <dev@mhibbe.de>
|
||||||
|
* SPDX-FileCopyrightText: 2021 Andy Scherzinger <infoi@andy-scherzinger.de>
|
||||||
|
* SPDX-FileCopyrightText: 2017 Mario Danic <mario@lovelyhq.com>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
package com.nextcloud.talk.adapters.items
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.Context
|
||||||
|
import android.text.TextUtils
|
||||||
|
import android.view.View
|
||||||
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
import androidx.core.content.res.ResourcesCompat
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.nextcloud.talk.R
|
||||||
|
import com.nextcloud.talk.adapters.items.ParticipantItem.ParticipantItemViewHolder
|
||||||
|
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||||
|
import com.nextcloud.talk.data.user.model.User
|
||||||
|
import com.nextcloud.talk.databinding.RvItemConversationInfoParticipantBinding
|
||||||
|
import com.nextcloud.talk.extensions.loadDefaultGroupCallAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadGuestAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadMailAvatar
|
||||||
|
import com.nextcloud.talk.extensions.loadUserAvatar
|
||||||
|
import com.nextcloud.talk.models.json.converters.EnumParticipantTypeConverter
|
||||||
|
import com.nextcloud.talk.models.json.participants.Participant
|
||||||
|
import com.nextcloud.talk.models.json.participants.Participant.InCallFlags
|
||||||
|
import com.nextcloud.talk.models.json.status.StatusType
|
||||||
|
import com.nextcloud.talk.ui.StatusDrawable
|
||||||
|
import com.nextcloud.talk.ui.theme.ViewThemeUtils
|
||||||
|
import com.nextcloud.talk.utils.DisplayUtils.convertDpToPixel
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
|
import eu.davidea.flexibleadapter.items.IFilterable
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
|
import eu.davidea.viewholders.FlexibleViewHolder
|
||||||
|
import java.util.regex.Pattern
|
||||||
|
|
||||||
|
class ParticipantItem(
|
||||||
|
private val context: Context,
|
||||||
|
val model: Participant,
|
||||||
|
private val user: User,
|
||||||
|
private val viewThemeUtils: ViewThemeUtils
|
||||||
|
) : AbstractFlexibleItem<ParticipantItemViewHolder>(), IFilterable<String?> {
|
||||||
|
var isOnline = true
|
||||||
|
override fun equals(o: Any?): Boolean {
|
||||||
|
return if (o is ParticipantItem) {
|
||||||
|
model.calculatedActorType == o.model.calculatedActorType &&
|
||||||
|
model.calculatedActorId == o.model.calculatedActorId
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return model.hashCode()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getLayoutRes(): Int {
|
||||||
|
return R.layout.rv_item_conversation_info_participant
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createViewHolder(
|
||||||
|
view: View?,
|
||||||
|
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?
|
||||||
|
): ParticipantItemViewHolder {
|
||||||
|
return ParticipantItemViewHolder(view, adapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
|
override fun bindViewHolder(
|
||||||
|
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?,
|
||||||
|
holder: ParticipantItemViewHolder?,
|
||||||
|
position: Int,
|
||||||
|
payloads: List<*>?
|
||||||
|
) {
|
||||||
|
drawStatus(holder!!)
|
||||||
|
if (!isOnline) {
|
||||||
|
holder.binding.nameText.setTextColor(
|
||||||
|
ResourcesCompat.getColor(
|
||||||
|
holder.binding.nameText.context.resources,
|
||||||
|
R.color.medium_emphasis_text,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
holder.binding.avatarView.setAlpha(0.38f)
|
||||||
|
} else {
|
||||||
|
holder.binding.nameText.setTextColor(
|
||||||
|
ResourcesCompat.getColor(
|
||||||
|
holder.binding.nameText.context.resources,
|
||||||
|
R.color.high_emphasis_text,
|
||||||
|
null
|
||||||
|
)
|
||||||
|
)
|
||||||
|
holder.binding.avatarView.setAlpha(1.0f)
|
||||||
|
}
|
||||||
|
holder.binding.nameText.text = model.displayName
|
||||||
|
if (adapter!!.hasFilter()) {
|
||||||
|
viewThemeUtils.talk.themeAndHighlightText(
|
||||||
|
holder.binding.nameText,
|
||||||
|
model.displayName,
|
||||||
|
adapter.getFilter(
|
||||||
|
String::class.java
|
||||||
|
).toString()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (TextUtils.isEmpty(model.displayName) &&
|
||||||
|
(
|
||||||
|
model.type == Participant.ParticipantType.GUEST ||
|
||||||
|
model.type == Participant.ParticipantType.USER_FOLLOWING_LINK
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
holder.binding.nameText.text = sharedApplication!!.getString(R.string.nc_guest)
|
||||||
|
}
|
||||||
|
if (model.calculatedActorType == Participant.ActorType.GROUPS || "groups" == model.source ||
|
||||||
|
model.calculatedActorType == Participant.ActorType.CIRCLES || "circles" == model.source
|
||||||
|
) {
|
||||||
|
holder.binding.avatarView.loadDefaultGroupCallAvatar(viewThemeUtils)
|
||||||
|
} else if (model.calculatedActorType == Participant.ActorType.EMAILS) {
|
||||||
|
holder.binding.avatarView.loadMailAvatar(viewThemeUtils)
|
||||||
|
} else if (model.calculatedActorType == Participant.ActorType.GUESTS ||
|
||||||
|
model.type == Participant.ParticipantType.GUEST ||
|
||||||
|
model.type == Participant.ParticipantType.GUEST_MODERATOR
|
||||||
|
) {
|
||||||
|
var displayName: String? = sharedApplication!!.resources.getString(R.string.nc_guest)
|
||||||
|
if (!TextUtils.isEmpty(model.displayName)) {
|
||||||
|
displayName = model.displayName
|
||||||
|
}
|
||||||
|
holder.binding.avatarView.loadGuestAvatar(user, displayName!!, false)
|
||||||
|
} else if (model.calculatedActorType == Participant.ActorType.USERS || "users" == model.source) {
|
||||||
|
holder.binding.avatarView
|
||||||
|
.loadUserAvatar(user, model.calculatedActorId!!, true, false)
|
||||||
|
}
|
||||||
|
val resources = sharedApplication!!.resources
|
||||||
|
val inCallFlag = model.inCall
|
||||||
|
if (inCallFlag and InCallFlags.WITH_PHONE.toLong() > 0) {
|
||||||
|
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_call_grey_600_24dp)
|
||||||
|
holder.binding.videoCallIcon.setVisibility(View.VISIBLE)
|
||||||
|
holder.binding.videoCallIcon.setContentDescription(
|
||||||
|
resources.getString(R.string.nc_call_state_with_phone, model.displayName)
|
||||||
|
)
|
||||||
|
} else if (inCallFlag and InCallFlags.WITH_VIDEO.toLong() > 0) {
|
||||||
|
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_videocam_grey_600_24dp)
|
||||||
|
holder.binding.videoCallIcon.setVisibility(View.VISIBLE)
|
||||||
|
holder.binding.videoCallIcon.setContentDescription(
|
||||||
|
resources.getString(R.string.nc_call_state_with_video, model.displayName)
|
||||||
|
)
|
||||||
|
} else if (inCallFlag > InCallFlags.DISCONNECTED) {
|
||||||
|
holder.binding.videoCallIcon.setImageResource(R.drawable.ic_mic_grey_600_24dp)
|
||||||
|
holder.binding.videoCallIcon.setVisibility(View.VISIBLE)
|
||||||
|
holder.binding.videoCallIcon.setContentDescription(
|
||||||
|
resources.getString(R.string.nc_call_state_in_call, model.displayName)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
holder.binding.videoCallIcon.setVisibility(View.GONE)
|
||||||
|
}
|
||||||
|
var userType = ""
|
||||||
|
when (EnumParticipantTypeConverter().convertToInt(model.type)) {
|
||||||
|
1, 2, 6 -> userType = sharedApplication!!.getString(R.string.nc_moderator)
|
||||||
|
|
||||||
|
3 -> {
|
||||||
|
userType = sharedApplication!!.getString(R.string.nc_user)
|
||||||
|
if (model.calculatedActorType == Participant.ActorType.GROUPS) {
|
||||||
|
userType = sharedApplication!!.getString(R.string.nc_group)
|
||||||
|
}
|
||||||
|
if (model.calculatedActorType == Participant.ActorType.CIRCLES) {
|
||||||
|
userType = sharedApplication!!.getString(R.string.nc_team)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
4 -> {
|
||||||
|
userType = sharedApplication!!.getString(R.string.nc_guest)
|
||||||
|
if (model.calculatedActorType == Participant.ActorType.EMAILS) {
|
||||||
|
userType = sharedApplication!!.getString(R.string.nc_email)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
5 -> userType = sharedApplication!!.getString(R.string.nc_following_link)
|
||||||
|
|
||||||
|
else -> {}
|
||||||
|
}
|
||||||
|
if (userType != sharedApplication!!.getString(R.string.nc_user)
|
||||||
|
) {
|
||||||
|
holder.binding.secondaryText.text = "($userType)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun drawStatus(holder: ParticipantItemViewHolder) {
|
||||||
|
val size = convertDpToPixel(STATUS_SIZE_IN_DP, context)
|
||||||
|
holder.binding.userStatusImage.setImageDrawable(
|
||||||
|
StatusDrawable(
|
||||||
|
model.status,
|
||||||
|
NO_ICON,
|
||||||
|
size,
|
||||||
|
context.resources.getColor(R.color.bg_default),
|
||||||
|
context
|
||||||
|
)
|
||||||
|
)
|
||||||
|
if (model.statusMessage != null) {
|
||||||
|
holder.binding.conversationInfoStatusMessage.text = model.statusMessage
|
||||||
|
alignUsernameVertical(holder, 0f)
|
||||||
|
} else {
|
||||||
|
holder.binding.conversationInfoStatusMessage.text = ""
|
||||||
|
alignUsernameVertical(holder, 10f)
|
||||||
|
}
|
||||||
|
if (model.statusIcon != null && model.statusIcon!!.isNotEmpty()) {
|
||||||
|
holder.binding.participantStatusEmoji.setText(model.statusIcon)
|
||||||
|
} else {
|
||||||
|
holder.binding.participantStatusEmoji.visibility = View.GONE
|
||||||
|
}
|
||||||
|
if (model.status != null && model.status == StatusType.DND.string) {
|
||||||
|
if (model.statusMessage == null || model.statusMessage!!.isEmpty()) {
|
||||||
|
holder.binding.conversationInfoStatusMessage.setText(R.string.dnd)
|
||||||
|
}
|
||||||
|
} else if (model.status != null && model.status == StatusType.AWAY.string) {
|
||||||
|
if (model.statusMessage == null || model.statusMessage!!.isEmpty()) {
|
||||||
|
holder.binding.conversationInfoStatusMessage.setText(R.string.away)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun alignUsernameVertical(holder: ParticipantItemViewHolder, densityPixelsFromTop: Float) {
|
||||||
|
val layoutParams = holder.binding.nameText.layoutParams as ConstraintLayout.LayoutParams
|
||||||
|
layoutParams.topMargin = convertDpToPixel(densityPixelsFromTop, context).toInt()
|
||||||
|
holder.binding.nameText.setLayoutParams(layoutParams)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun filter(constraint: String?): Boolean {
|
||||||
|
return model.displayName != null &&
|
||||||
|
(
|
||||||
|
Pattern.compile(constraint, Pattern.CASE_INSENSITIVE or Pattern.LITERAL)
|
||||||
|
.matcher(model.displayName!!.trim { it <= ' ' }).find() ||
|
||||||
|
Pattern.compile(constraint, Pattern.CASE_INSENSITIVE or Pattern.LITERAL)
|
||||||
|
.matcher(model.calculatedActorId!!.trim { it <= ' ' }).find()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
class ParticipantItemViewHolder internal constructor(view: View?, adapter: FlexibleAdapter<*>?) :
|
||||||
|
FlexibleViewHolder(view, adapter) {
|
||||||
|
var binding: RvItemConversationInfoParticipantBinding
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default constructor.
|
||||||
|
*/
|
||||||
|
init {
|
||||||
|
binding = RvItemConversationInfoParticipantBinding.bind(view!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val STATUS_SIZE_IN_DP = 9f
|
||||||
|
private const val NO_ICON = ""
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue