|
@@ -1,3 +1,29 @@
|
|
|
|
+/*
|
|
|
|
+ * Nextcloud Talk application
|
|
|
|
+ *
|
|
|
|
+ * @author Andy Scherzinger
|
|
|
|
+ * @author Mario Danic
|
|
|
|
+ * @author Marcel Hibbe
|
|
|
|
+ * Copyright (C) 2021 Andy Scherzinger <info@andy-scherzinger.de>
|
|
|
|
+ * Copyright (C) 2017 Mario Danic <mario@lovelyhq.com>
|
|
|
|
+ * Copyright (C) 2022 Marcel Hibbe (dev@mhibbe.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/>.
|
|
|
|
+ *
|
|
|
|
+ * Parts related to account import were either copied from or inspired by the great work done by David Luhmer at:
|
|
|
|
+ * https://github.com/nextcloud/ownCloud-Account-Importer
|
|
|
|
+ */
|
|
package com.nextcloud.talk.ui.dialog
|
|
package com.nextcloud.talk.ui.dialog
|
|
|
|
|
|
import android.app.Activity
|
|
import android.app.Activity
|
|
@@ -7,15 +33,18 @@ import android.view.Gravity
|
|
import android.view.ViewGroup
|
|
import android.view.ViewGroup
|
|
import android.widget.LinearLayout
|
|
import android.widget.LinearLayout
|
|
import androidx.annotation.NonNull
|
|
import androidx.annotation.NonNull
|
|
|
|
+import androidx.recyclerview.widget.LinearLayoutManager
|
|
import autodagger.AutoInjector
|
|
import autodagger.AutoInjector
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
|
|
|
+import com.nextcloud.talk.adapters.ReactionItem
|
|
|
|
+import com.nextcloud.talk.adapters.ReactionItemClickListener
|
|
|
|
+import com.nextcloud.talk.adapters.ReactionsAdapter
|
|
import com.nextcloud.talk.api.NcApi
|
|
import com.nextcloud.talk.api.NcApi
|
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
|
import com.nextcloud.talk.application.NextcloudTalkApplication
|
|
import com.nextcloud.talk.databinding.DialogMessageReactionsBinding
|
|
import com.nextcloud.talk.databinding.DialogMessageReactionsBinding
|
|
import com.nextcloud.talk.models.database.UserEntity
|
|
import com.nextcloud.talk.models.database.UserEntity
|
|
import com.nextcloud.talk.models.json.chat.ChatMessage
|
|
import com.nextcloud.talk.models.json.chat.ChatMessage
|
|
import com.nextcloud.talk.models.json.conversations.Conversation
|
|
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.ReactionVoter
|
|
import com.nextcloud.talk.models.json.reactions.ReactionsOverall
|
|
import com.nextcloud.talk.models.json.reactions.ReactionsOverall
|
|
import com.nextcloud.talk.utils.ApiUtils
|
|
import com.nextcloud.talk.utils.ApiUtils
|
|
@@ -25,10 +54,6 @@ import io.reactivex.Observer
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.android.schedulers.AndroidSchedulers
|
|
import io.reactivex.disposables.Disposable
|
|
import io.reactivex.disposables.Disposable
|
|
import io.reactivex.schedulers.Schedulers
|
|
import io.reactivex.schedulers.Schedulers
|
|
-import org.apache.commons.lang3.StringEscapeUtils
|
|
|
|
-import java.net.URLDecoder
|
|
|
|
-import java.net.URLEncoder
|
|
|
|
-import javax.inject.Inject
|
|
|
|
|
|
|
|
@AutoInjector(NextcloudTalkApplication::class)
|
|
@AutoInjector(NextcloudTalkApplication::class)
|
|
class ShowReactionsDialog(
|
|
class ShowReactionsDialog(
|
|
@@ -37,10 +62,12 @@ class ShowReactionsDialog(
|
|
val chatMessage: ChatMessage,
|
|
val chatMessage: ChatMessage,
|
|
val userEntity: UserEntity?,
|
|
val userEntity: UserEntity?,
|
|
val ncApi: NcApi
|
|
val ncApi: NcApi
|
|
-) : BottomSheetDialog(activity) {
|
|
|
|
|
|
+) : BottomSheetDialog(activity), ReactionItemClickListener {
|
|
|
|
|
|
private lateinit var binding: DialogMessageReactionsBinding
|
|
private lateinit var binding: DialogMessageReactionsBinding
|
|
|
|
|
|
|
|
+ private var adapter: ReactionsAdapter? = null
|
|
|
|
+
|
|
// @Inject
|
|
// @Inject
|
|
// lateinit var ncApi: NcApi
|
|
// lateinit var ncApi: NcApi
|
|
|
|
|
|
@@ -49,12 +76,16 @@ class ShowReactionsDialog(
|
|
binding = DialogMessageReactionsBinding.inflate(layoutInflater)
|
|
binding = DialogMessageReactionsBinding.inflate(layoutInflater)
|
|
setContentView(binding.root)
|
|
setContentView(binding.root)
|
|
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
|
-
|
|
|
|
|
|
+ adapter = ReactionsAdapter(this)
|
|
|
|
+ binding.reactionsList.adapter = adapter
|
|
|
|
+ binding.reactionsList.layoutManager = LinearLayoutManager(context)
|
|
initEmojiReactions()
|
|
initEmojiReactions()
|
|
}
|
|
}
|
|
|
|
|
|
private fun initEmojiReactions() {
|
|
private fun initEmojiReactions() {
|
|
|
|
+ adapter?.list?.clear()
|
|
if (chatMessage.reactions != null && chatMessage.reactions.isNotEmpty()) {
|
|
if (chatMessage.reactions != null && chatMessage.reactions.isNotEmpty()) {
|
|
|
|
+
|
|
for ((emoji, amount) in chatMessage.reactions) {
|
|
for ((emoji, amount) in chatMessage.reactions) {
|
|
var emojiView = EmojiTextView(activity)
|
|
var emojiView = EmojiTextView(activity)
|
|
emojiView.setEmojiSize(DisplayUtils.convertDpToPixel(EMOJI_SIZE, context).toInt())
|
|
emojiView.setEmojiSize(DisplayUtils.convertDpToPixel(EMOJI_SIZE, context).toInt())
|
|
@@ -73,8 +104,12 @@ class ShowReactionsDialog(
|
|
emojiView.setOnClickListener {
|
|
emojiView.setOnClickListener {
|
|
updateParticipantsForEmoji(chatMessage, emoji)
|
|
updateParticipantsForEmoji(chatMessage, emoji)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // TODO: Add proper implementation
|
|
|
|
+ adapter?.list?.add(ReactionItem(ReactionVoter(null, null, "Marcel", 0), emoji))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ adapter?.notifyDataSetChanged()
|
|
}
|
|
}
|
|
|
|
|
|
private fun updateParticipantsForEmoji(chatMessage: ChatMessage, emoji: String?) {
|
|
private fun updateParticipantsForEmoji(chatMessage: ChatMessage, emoji: String?) {
|
|
@@ -93,7 +128,8 @@ class ShowReactionsDialog(
|
|
ApiUtils.getUrlForParticipantsForEmojiReaction(
|
|
ApiUtils.getUrlForParticipantsForEmojiReaction(
|
|
userEntity?.baseUrl,
|
|
userEntity?.baseUrl,
|
|
currentConversation!!.token,
|
|
currentConversation!!.token,
|
|
- chatMessage.id),
|
|
|
|
|
|
+ chatMessage.id
|
|
|
|
+ ),
|
|
emoji
|
|
emoji
|
|
)
|
|
)
|
|
?.subscribeOn(Schedulers.io())
|
|
?.subscribeOn(Schedulers.io())
|
|
@@ -106,11 +142,14 @@ class ShowReactionsDialog(
|
|
override fun onNext(@NonNull reactionsOverall: ReactionsOverall) {
|
|
override fun onNext(@NonNull reactionsOverall: ReactionsOverall) {
|
|
Log.d(TAG, "onNext")
|
|
Log.d(TAG, "onNext")
|
|
|
|
|
|
- val reactionVoters: ArrayList<ReactionVoter> = ArrayList()
|
|
|
|
- if (reactionsOverall.ocs?.data != null){
|
|
|
|
|
|
+ val reactionVoters: ArrayList<ReactionItem> = ArrayList()
|
|
|
|
+ if (reactionsOverall.ocs?.data != null) {
|
|
for (reactionVoter in reactionsOverall.ocs?.data!!) {
|
|
for (reactionVoter in reactionsOverall.ocs?.data!!) {
|
|
- reactionVoters.add(reactionVoter)
|
|
|
|
|
|
+ reactionVoters.add(ReactionItem(reactionVoter, emoji))
|
|
}
|
|
}
|
|
|
|
+ // TODO: Test and check for data notification call need
|
|
|
|
+ adapter?.list?.addAll(reactionVoters)
|
|
|
|
+ Log.e(TAG, "voters:" + reactionVoters.size)
|
|
} else {
|
|
} else {
|
|
Log.e(TAG, "no voters for this reaction")
|
|
Log.e(TAG, "no voters for this reaction")
|
|
}
|
|
}
|
|
@@ -125,12 +164,17 @@ class ShowReactionsDialog(
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
// binding.emojiReactionsContactList
|
|
// binding.emojiReactionsContactList
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ override fun onClick(reactionItem: ReactionItem) {
|
|
|
|
+ Log.d(TAG, "onClick(reactionItem: ReactionItem): " + reactionItem.reaction)
|
|
|
|
+ // TODO: implement removal of users reaction,
|
|
|
|
+ // ownership needs to be checked, so only owned
|
|
|
|
+ // reactions can be removed upon click
|
|
|
|
+ dismiss()
|
|
|
|
+ }
|
|
|
|
+
|
|
companion object {
|
|
companion object {
|
|
const val TAG = "ShowReactionsDialog"
|
|
const val TAG = "ShowReactionsDialog"
|
|
const val EMOJI_RIGHT_MARGIN: Int = 12
|
|
const val EMOJI_RIGHT_MARGIN: Int = 12
|