mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-20 20:19:42 +01:00
Add "all" tab for reactions
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
357c67db83
commit
6bda280d15
@ -29,6 +29,7 @@ package com.nextcloud.talk.ui.dialog
|
||||
import android.app.Activity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.NonNull
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
@ -36,6 +37,7 @@ import autodagger.AutoInjector
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.google.android.material.tabs.TabLayout.OnTabSelectedListener
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.adapters.ReactionItem
|
||||
import com.nextcloud.talk.adapters.ReactionItemClickListener
|
||||
import com.nextcloud.talk.adapters.ReactionsAdapter
|
||||
@ -47,12 +49,14 @@ 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.generic.GenericOverall
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionVoter
|
||||
import com.nextcloud.talk.models.json.reactions.ReactionsOverall
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import io.reactivex.Observer
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.Disposable
|
||||
import io.reactivex.schedulers.Schedulers
|
||||
import java.util.HashMap
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class ShowReactionsDialog(
|
||||
@ -67,6 +71,8 @@ class ShowReactionsDialog(
|
||||
|
||||
private var adapter: ReactionsAdapter? = null
|
||||
|
||||
private val TAG_ALL: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = DialogMessageReactionsBinding.inflate(layoutInflater)
|
||||
@ -81,13 +87,9 @@ class ShowReactionsDialog(
|
||||
private fun initEmojiReactions() {
|
||||
adapter?.list?.clear()
|
||||
if (chatMessage.reactions != null && chatMessage.reactions.isNotEmpty()) {
|
||||
|
||||
var firstEmoji = ""
|
||||
var reactionsTotal = 0
|
||||
for ((emoji, amount) in chatMessage.reactions) {
|
||||
if (firstEmoji.isEmpty()) {
|
||||
firstEmoji = emoji
|
||||
}
|
||||
|
||||
reactionsTotal = reactionsTotal.plus(amount as Int)
|
||||
val tab: TabLayout.Tab = binding.emojiReactionsTabs.newTab() // Create a new Tab names "First Tab"
|
||||
|
||||
val itemBinding = ItemReactionsTabBinding.inflate(layoutInflater)
|
||||
@ -98,7 +100,6 @@ class ShowReactionsDialog(
|
||||
|
||||
binding.emojiReactionsTabs.addTab(tab)
|
||||
}
|
||||
updateParticipantsForEmoji(chatMessage, firstEmoji)
|
||||
|
||||
binding.emojiReactionsTabs.getTabAt(0)?.select()
|
||||
|
||||
@ -116,6 +117,18 @@ class ShowReactionsDialog(
|
||||
// called when a tab is reselected
|
||||
}
|
||||
})
|
||||
|
||||
val tab: TabLayout.Tab = binding.emojiReactionsTabs.newTab() // Create a new Tab names "First Tab"
|
||||
|
||||
val itemBinding = ItemReactionsTabBinding.inflate(layoutInflater)
|
||||
itemBinding.reactionTab.tag = TAG_ALL
|
||||
itemBinding.reactionIcon.text = context.getString(R.string.reactions_tab_all)
|
||||
itemBinding.reactionCount.text = reactionsTotal.toString()
|
||||
tab.customView = itemBinding.root
|
||||
|
||||
binding.emojiReactionsTabs.addTab(tab, 0)
|
||||
|
||||
updateParticipantsForEmoji(chatMessage, TAG_ALL)
|
||||
}
|
||||
adapter?.notifyDataSetChanged()
|
||||
}
|
||||
@ -144,9 +157,13 @@ class ShowReactionsDialog(
|
||||
override fun onNext(@NonNull reactionsOverall: ReactionsOverall) {
|
||||
val reactionVoters: ArrayList<ReactionItem> = ArrayList()
|
||||
if (reactionsOverall.ocs?.data != null) {
|
||||
for (reactionVoter in reactionsOverall.ocs?.data!![emoji]!!) {
|
||||
reactionVoters.add(ReactionItem(reactionVoter, emoji))
|
||||
val map = reactionsOverall.ocs?.data
|
||||
for (key in map!!.keys) {
|
||||
for (reactionVoter in reactionsOverall.ocs?.data!![key]!!) {
|
||||
reactionVoters.add(ReactionItem(reactionVoter, key))
|
||||
}
|
||||
}
|
||||
|
||||
adapter?.list?.addAll(reactionVoters)
|
||||
adapter?.notifyDataSetChanged()
|
||||
} else {
|
||||
|
@ -21,17 +21,18 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/reaction_tab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center">
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
android:id="@+id/reaction_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:textColor="@color/textColorMaxContrast"
|
||||
android:textIsSelectable="false"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold"
|
||||
tools:text="@string/default_emoji" />
|
||||
|
||||
<TextView
|
||||
|
@ -513,4 +513,6 @@
|
||||
<string name="audio_output_dialog_headline">Audio output</string>
|
||||
<string name="audio_output_wired_headset">Wired headset</string>
|
||||
|
||||
<string name="reactions_tab_all">All</string>
|
||||
|
||||
</resources>
|
||||
|
Loading…
Reference in New Issue
Block a user