fix parsing of json of emoji voters

basic update for emoji voters in UI

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-04-05 13:39:24 +02:00
parent f61872af7c
commit 9c0ea73b5d
No known key found for this signature in database
GPG Key ID: C793F8B59F43CE7B
2 changed files with 15 additions and 17 deletions

View File

@ -24,13 +24,14 @@ import com.bluelinelabs.logansquare.annotation.JsonField
import com.bluelinelabs.logansquare.annotation.JsonObject
import com.nextcloud.talk.models.json.generic.GenericOCS
import kotlinx.android.parcel.Parcelize
import java.util.HashMap
@Parcelize
@JsonObject
data class ReactionsOCS(
@JsonField(name = ["data"])
var data: List<ReactionVoter>?
var data: HashMap<String, List<ReactionVoter>>?
) : GenericOCS(), Parcelable {
// This constructor is added to work with the 'com.bluelinelabs.logansquare.annotation.JsonObject'
constructor() : this(null)
constructor() : this(HashMap())
}

View File

@ -36,6 +36,7 @@ import androidx.annotation.NonNull
import androidx.recyclerview.widget.LinearLayoutManager
import autodagger.AutoInjector
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.nextcloud.talk.R
import com.nextcloud.talk.adapters.ReactionItem
import com.nextcloud.talk.adapters.ReactionItemClickListener
import com.nextcloud.talk.adapters.ReactionsAdapter
@ -45,7 +46,6 @@ import com.nextcloud.talk.databinding.DialogMessageReactionsBinding
import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.models.json.conversations.Conversation
import com.nextcloud.talk.models.json.reactions.ReactionVoter
import com.nextcloud.talk.models.json.reactions.ReactionsOverall
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
@ -86,7 +86,12 @@ class ShowReactionsDialog(
adapter?.list?.clear()
if (chatMessage.reactions != null && chatMessage.reactions.isNotEmpty()) {
var firstEmoji = ""
for ((emoji, amount) in chatMessage.reactions) {
if(firstEmoji.isEmpty()){
firstEmoji = emoji
}
var emojiView = EmojiTextView(activity)
emojiView.setEmojiSize(DisplayUtils.convertDpToPixel(EMOJI_SIZE, context).toInt())
emojiView.text = emoji
@ -103,6 +108,7 @@ class ShowReactionsDialog(
emojiView.setOnClickListener {
updateParticipantsForEmoji(chatMessage, emoji)
emojiView.setBackgroundColor(context.resources.getColor(R.color.colorPrimary))
}
// TODO: Add proper implementation
@ -118,21 +124,16 @@ class ShowReactionsDialog(
)
)
}
updateParticipantsForEmoji(chatMessage, firstEmoji)
}
adapter?.notifyDataSetChanged()
}
private fun updateParticipantsForEmoji(chatMessage: ChatMessage, emoji: String?) {
adapter?.list?.clear()
val credentials = ApiUtils.getCredentials(userEntity?.username, userEntity?.token)
Log.d(TAG, "emoji= " + emoji)
// TODO: fix encoding for emoji. set this in NcApi or here...
// var emojiForServer = StringEscapeUtils.escapeJava(emoji)
// Log.d(TAG, "emojiForServer= " + emojiForServer) // ?reaction=%5Cu2764%5CuFE0F
ncApi.getParticipantsForEmojiReaction(
credentials,
ApiUtils.getUrlForParticipantsForEmojiReaction(
@ -146,20 +147,17 @@ class ShowReactionsDialog(
?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<ReactionsOverall> {
override fun onSubscribe(d: Disposable) {
Log.d(TAG, "onSubscribe")
}
override fun onNext(@NonNull reactionsOverall: ReactionsOverall) {
Log.d(TAG, "onNext")
val reactionVoters: ArrayList<ReactionItem> = ArrayList()
if (reactionsOverall.ocs?.data != null) {
for (reactionVoter in reactionsOverall.ocs?.data!!) {
for (reactionVoter in reactionsOverall.ocs?.data!![emoji]!!) {
reactionVoters.add(ReactionItem(reactionVoter, emoji))
}
// TODO: Test and check for data notification call need
adapter?.list?.addAll(reactionVoters)
Log.e(TAG, "voters:" + reactionVoters.size)
adapter?.notifyDataSetChanged()
} else {
Log.e(TAG, "no voters for this reaction")
}
@ -170,7 +168,6 @@ class ShowReactionsDialog(
}
override fun onComplete() {
Log.d(TAG, "onComplete")
}
})
}