From 091fddc2c0263edc7a343303f0fb2d7ec438ba43 Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Fri, 5 Apr 2024 12:43:37 +0200 Subject: [PATCH] show federated avatars for polls Signed-off-by: Marcel Hibbe --- .../adapters/PollResultVoterViewHolder.kt | 38 +++++++++++++++---- .../PollResultVotersOverviewViewHolder.kt | 38 +++++++++++++++---- .../talk/polls/adapters/PollResultsAdapter.kt | 5 ++- .../talk/polls/ui/PollResultsFragment.kt | 21 +++++++--- 4 files changed, 81 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVoterViewHolder.kt b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVoterViewHolder.kt index 56fd01480..a0da9be22 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVoterViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVoterViewHolder.kt @@ -13,13 +13,18 @@ import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.PollResultVoterItemBinding +import com.nextcloud.talk.extensions.loadFederatedUserAvatar import com.nextcloud.talk.extensions.loadGuestAvatar import com.nextcloud.talk.extensions.loadUserAvatar +import com.nextcloud.talk.models.json.converters.EnumActorTypeConverter +import com.nextcloud.talk.models.json.participants.Participant import com.nextcloud.talk.polls.model.PollDetails import com.nextcloud.talk.ui.theme.ViewThemeUtils +import com.nextcloud.talk.utils.DisplayUtils class PollResultVoterViewHolder( private val user: User, + private val roomToken: String, override val binding: PollResultVoterItemBinding, private val viewThemeUtils: ViewThemeUtils ) : PollResultViewHolder(binding) { @@ -36,14 +41,33 @@ class PollResultVoterViewHolder( } private fun loadAvatar(pollDetail: PollDetails, avatar: ImageView) { - if (pollDetail.actorType == "guests") { - var displayName = NextcloudTalkApplication.sharedApplication?.resources?.getString(R.string.nc_guest) - if (!TextUtils.isEmpty(pollDetail.actorDisplayName)) { - displayName = pollDetail.actorDisplayName!! + when (EnumActorTypeConverter().getFromString(pollDetail.actorType)) { + Participant.ActorType.GUESTS -> { + var displayName = NextcloudTalkApplication.sharedApplication?.resources?.getString(R.string.nc_guest) + if (!TextUtils.isEmpty(pollDetail.actorDisplayName)) { + displayName = pollDetail.actorDisplayName!! + } + avatar.loadGuestAvatar(user, displayName!!, false) } - avatar.loadGuestAvatar(user, displayName!!, false) - } else if (pollDetail.actorType == "users") { - avatar.loadUserAvatar(user, pollDetail.actorId!!, false, false) + + Participant.ActorType.USERS -> { + avatar.loadUserAvatar(user, pollDetail.actorId!!, false, false) + } + + Participant.ActorType.FEDERATED -> { + val darkTheme = if (DisplayUtils.isDarkModeOn(binding.root.context)) 1 else 0 + avatar.loadFederatedUserAvatar( + user, + user.baseUrl!!, + roomToken, + pollDetail.actorId!!, + darkTheme, + false, + false + ) + } + + else -> {} } } } diff --git a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVotersOverviewViewHolder.kt b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVotersOverviewViewHolder.kt index 3f6f809a5..c9219a0e3 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVotersOverviewViewHolder.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultVotersOverviewViewHolder.kt @@ -16,12 +16,17 @@ import com.nextcloud.talk.R import com.nextcloud.talk.application.NextcloudTalkApplication import com.nextcloud.talk.data.user.model.User import com.nextcloud.talk.databinding.PollResultVotersOverviewItemBinding +import com.nextcloud.talk.extensions.loadFederatedUserAvatar import com.nextcloud.talk.extensions.loadGuestAvatar import com.nextcloud.talk.extensions.loadUserAvatar +import com.nextcloud.talk.models.json.converters.EnumActorTypeConverter +import com.nextcloud.talk.models.json.participants.Participant import com.nextcloud.talk.polls.model.PollDetails +import com.nextcloud.talk.utils.DisplayUtils class PollResultVotersOverviewViewHolder( private val user: User, + private val roomToken: String, override val binding: PollResultVotersOverviewItemBinding ) : PollResultViewHolder(binding) { @@ -66,14 +71,33 @@ class PollResultVotersOverviewViewHolder( } private fun loadAvatar(pollDetail: PollDetails, avatar: ImageView) { - if (pollDetail.actorType == "guests") { - var displayName = NextcloudTalkApplication.sharedApplication?.resources?.getString(R.string.nc_guest) - if (!TextUtils.isEmpty(pollDetail.actorDisplayName)) { - displayName = pollDetail.actorDisplayName!! + when (EnumActorTypeConverter().getFromString(pollDetail.actorType)) { + Participant.ActorType.GUESTS -> { + var displayName = NextcloudTalkApplication.sharedApplication?.resources?.getString(R.string.nc_guest) + if (!TextUtils.isEmpty(pollDetail.actorDisplayName)) { + displayName = pollDetail.actorDisplayName!! + } + avatar.loadGuestAvatar(user, displayName!!, false) } - avatar.loadGuestAvatar(user, displayName!!, false) - } else if (pollDetail.actorType == "users") { - avatar.loadUserAvatar(user, pollDetail.actorId!!, false, false) + + Participant.ActorType.USERS -> { + avatar.loadUserAvatar(user, pollDetail.actorId!!, false, false) + } + + Participant.ActorType.FEDERATED -> { + val darkTheme = if (DisplayUtils.isDarkModeOn(binding.root.context)) 1 else 0 + avatar.loadFederatedUserAvatar( + user, + user.baseUrl!!, + roomToken, + pollDetail.actorId!!, + darkTheme, + false, + false + ) + } + + else -> {} } } diff --git a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultsAdapter.kt b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultsAdapter.kt index 82f3be807..6ca1b1f98 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultsAdapter.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/adapters/PollResultsAdapter.kt @@ -17,6 +17,7 @@ import com.nextcloud.talk.ui.theme.ViewThemeUtils class PollResultsAdapter( private val user: User, + private val roomToken: String, private val clickListener: PollResultItemClickListener, private val viewThemeUtils: ViewThemeUtils ) : RecyclerView.Adapter() { @@ -40,7 +41,7 @@ class PollResultsAdapter( parent, false ) - viewHolder = PollResultVoterViewHolder(user, itemBinding, viewThemeUtils) + viewHolder = PollResultVoterViewHolder(user, roomToken, itemBinding, viewThemeUtils) } PollResultVotersOverviewItem.VIEW_TYPE -> { val itemBinding = PollResultVotersOverviewItemBinding.inflate( @@ -48,7 +49,7 @@ class PollResultsAdapter( parent, false ) - viewHolder = PollResultVotersOverviewViewHolder(user, itemBinding) + viewHolder = PollResultVotersOverviewViewHolder(user, roomToken, itemBinding) } } return viewHolder!! diff --git a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt index 3218cc3b4..48b4ceaba 100644 --- a/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt +++ b/app/src/main/java/com/nextcloud/talk/polls/ui/PollResultsFragment.kt @@ -68,11 +68,17 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { } viewModel.items.observe(viewLifecycleOwner) { - val adapter = PollResultsAdapter(parentViewModel.user, this, viewThemeUtils).apply { - if (it != null) { - list = it + val adapter = PollResultsAdapter( + parentViewModel.user, + parentViewModel.roomToken, + this, + viewThemeUtils + ) + .apply { + if (it != null) { + list = it + } } - } binding.pollResultsList.adapter = adapter } @@ -85,7 +91,12 @@ class PollResultsFragment : Fragment(), PollResultItemClickListener { } private fun initAdapter() { - adapter = PollResultsAdapter(parentViewModel.user, this, viewThemeUtils) + adapter = PollResultsAdapter( + parentViewModel.user, + parentViewModel.roomToken, + this, + viewThemeUtils + ) binding.pollResultsList.adapter = adapter binding.pollResultsList.layoutManager = LinearLayoutManager(context) }