mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 08:55:54 +03:00
load avatars of reaction actors, optimize layout
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
f99a33956a
commit
c4632f5d42
7 changed files with 134 additions and 12 deletions
|
@ -24,15 +24,17 @@ import android.view.LayoutInflater
|
|||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.nextcloud.talk.databinding.ReactionItemBinding
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
|
||||
class ReactionsAdapter(
|
||||
private val clickListener: ReactionItemClickListener
|
||||
private val clickListener: ReactionItemClickListener,
|
||||
private val userEntity: UserEntity?
|
||||
) : RecyclerView.Adapter<ReactionsViewHolder>() {
|
||||
internal var list: MutableList<ReactionItem> = ArrayList<ReactionItem>()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ReactionsViewHolder {
|
||||
val itemBinding = ReactionItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return ReactionsViewHolder(itemBinding)
|
||||
return ReactionsViewHolder(itemBinding, userEntity?.baseUrl)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: ReactionsViewHolder, position: Int) {
|
||||
|
|
|
@ -20,14 +20,69 @@
|
|||
|
||||
package com.nextcloud.talk.adapters
|
||||
|
||||
import android.text.TextUtils
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.facebook.drawee.backends.pipeline.Fresco
|
||||
import com.facebook.drawee.interfaces.DraweeController
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
|
||||
import com.nextcloud.talk.databinding.ReactionItemBinding
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
|
||||
class ReactionsViewHolder(private val binding: ReactionItemBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
class ReactionsViewHolder(
|
||||
private val binding: ReactionItemBinding,
|
||||
private val baseUrl: String?
|
||||
) : RecyclerView.ViewHolder(binding.root) {
|
||||
|
||||
fun bind(reactionItem: ReactionItem, clickListener: ReactionItemClickListener) {
|
||||
binding.root.setOnClickListener { clickListener.onClick(reactionItem) }
|
||||
binding.reaction.text = reactionItem.reaction
|
||||
binding.name.text = reactionItem.reactionVoter.actorDisplayName
|
||||
|
||||
if (baseUrl != null && baseUrl.isNotEmpty()) {
|
||||
loadAvatar(reactionItem)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAvatar(reactionItem: ReactionItem) {
|
||||
if (reactionItem.reactionVoter.actorType == ReactionVoter.ReactionActorType.GUESTS) {
|
||||
var displayName = sharedApplication?.resources?.getString(R.string.nc_guest)
|
||||
if (!TextUtils.isEmpty(reactionItem.reactionVoter.actorDisplayName)) {
|
||||
displayName = reactionItem.reactionVoter.actorDisplayName!!
|
||||
}
|
||||
val draweeController: DraweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setOldController(binding.avatar.controller)
|
||||
.setAutoPlayAnimations(true)
|
||||
.setImageRequest(
|
||||
DisplayUtils.getImageRequestForUrl(
|
||||
ApiUtils.getUrlForGuestAvatar(
|
||||
baseUrl,
|
||||
displayName,
|
||||
false
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
.build()
|
||||
binding.avatar.controller = draweeController
|
||||
} else if (reactionItem.reactionVoter.actorType == ReactionVoter.ReactionActorType.USERS) {
|
||||
val draweeController: DraweeController = Fresco.newDraweeControllerBuilder()
|
||||
.setOldController(binding.avatar.controller)
|
||||
.setAutoPlayAnimations(true)
|
||||
.setImageRequest(
|
||||
DisplayUtils.getImageRequestForUrl(
|
||||
ApiUtils.getUrlForAvatar(
|
||||
baseUrl,
|
||||
reactionItem.reactionVoter.actorId,
|
||||
false
|
||||
),
|
||||
null
|
||||
)
|
||||
)
|
||||
.build()
|
||||
binding.avatar.controller = draweeController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Nextcloud Talk application
|
||||
*
|
||||
* @author Andy Scherzinger
|
||||
* Copyright (C) 2022 Andy Scherzinger <info@andy-scherzinger.de>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.nextcloud.talk.models.json.converters
|
||||
|
||||
import com.bluelinelabs.logansquare.typeconverters.StringBasedTypeConverter
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter.ReactionActorType.DUMMY
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter.ReactionActorType.GUESTS
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter.ReactionActorType.USERS
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter
|
||||
|
||||
class EnumReactionActorTypeConverter : StringBasedTypeConverter<ReactionVoter.ReactionActorType>() {
|
||||
override fun getFromString(string: String): ReactionVoter.ReactionActorType {
|
||||
return when (string) {
|
||||
"guests" -> GUESTS
|
||||
"users" -> USERS
|
||||
else -> DUMMY
|
||||
}
|
||||
}
|
||||
|
||||
override fun convertToString(`object`: ReactionVoter.ReactionActorType?): String {
|
||||
|
||||
if (`object` == null) {
|
||||
return ""
|
||||
}
|
||||
|
||||
return when (`object`) {
|
||||
GUESTS -> "guests"
|
||||
USERS -> "users"
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
}
|
|
@ -23,13 +23,14 @@ package com.nextcloud.talk.models.json.reactions
|
|||
import android.os.Parcelable
|
||||
import com.bluelinelabs.logansquare.annotation.JsonField
|
||||
import com.bluelinelabs.logansquare.annotation.JsonObject
|
||||
import com.nextcloud.talk.models.json.converters.EnumReactionActorTypeConverter
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
@JsonObject
|
||||
data class ReactionVoter(
|
||||
@JsonField(name = ["actorType"])
|
||||
var actorType: String?,
|
||||
@JsonField(name = ["actorType"], typeConverter = EnumReactionActorTypeConverter::class)
|
||||
var actorType: ReactionActorType?,
|
||||
@JsonField(name = ["actorId"])
|
||||
var actorId: String?,
|
||||
@JsonField(name = ["actorDisplayName"])
|
||||
|
@ -39,4 +40,8 @@ data class ReactionVoter(
|
|||
) : Parcelable {
|
||||
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
|
||||
constructor() : this(null, null, null, 0)
|
||||
|
||||
enum class ReactionActorType {
|
||||
DUMMY, GUESTS, USERS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ class ShowReactionsDialog(
|
|||
binding = DialogMessageReactionsBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
adapter = ReactionsAdapter(this)
|
||||
adapter = ReactionsAdapter(this, userEntity)
|
||||
binding.reactionsList.adapter = adapter
|
||||
binding.reactionsList.layoutManager = LinearLayoutManager(context)
|
||||
initEmojiReactions()
|
||||
|
@ -106,7 +106,17 @@ class ShowReactionsDialog(
|
|||
}
|
||||
|
||||
// TODO: Add proper implementation
|
||||
adapter?.list?.add(ReactionItem(ReactionVoter(null, null, "Marcel", 0), emoji))
|
||||
adapter?.list?.add(
|
||||
ReactionItem(
|
||||
ReactionVoter(
|
||||
ReactionVoter.ReactionActorType.USERS,
|
||||
"marcel",
|
||||
"Marcel",
|
||||
0
|
||||
),
|
||||
emoji
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
adapter?.notifyDataSetChanged()
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/standard_padding"
|
||||
android:paddingEnd="@dimen/standard_padding"
|
||||
android:paddingBottom="@dimen/standard_half_padding">
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
|
|
|
@ -22,14 +22,14 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp">
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.facebook.drawee.view.SimpleDraweeView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="@dimen/avatar_size"
|
||||
android:layout_height="@dimen/avatar_size"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginEnd="@dimen/standard_margin"
|
||||
android:layout_margin="@dimen/standard_margin"
|
||||
app:roundAsCircle="true" />
|
||||
|
||||
<TextView
|
||||
|
@ -47,8 +47,10 @@
|
|||
android:id="@+id/reaction"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:gravity="center"
|
||||
android:textSize="25sp"
|
||||
android:textSize="24sp"
|
||||
android:layout_marginEnd="@dimen/standard_half_margin"
|
||||
tools:text="@string/default_emoji" />
|
||||
|
||||
</LinearLayout>
|
||||
|
|
Loading…
Reference in a new issue