mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-22 13:05:31 +03:00
show federated avatars for polls
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
e57f08f2d5
commit
091fddc2c0
4 changed files with 81 additions and 21 deletions
|
@ -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 -> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 -> {}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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<PollResultViewHolder>() {
|
||||
|
@ -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!!
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue