-
-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1895 from nextcloud/feature/1772/reactions
Reactions to chat messages
- Loading branch information
Showing
65 changed files
with
1,855 additions
and
296 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/nextcloud/talk/adapters/ReactionItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Andy Scherzinger | ||
* Copyright (C) 2022 Andy Scherzinger <[email protected]> | ||
* | ||
* 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.adapters | ||
|
||
import com.nextcloud.talk.models.json.reactions.ReactionVoter | ||
|
||
data class ReactionItem( | ||
val reactionVoter: ReactionVoter, | ||
val reaction: String? | ||
) |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/com/nextcloud/talk/adapters/ReactionItemClickListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Andy Scherzinger | ||
* Copyright (C) 2022 Andy Scherzinger <[email protected]> | ||
* | ||
* 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.adapters | ||
|
||
interface ReactionItemClickListener { | ||
fun onClick(reactionItem: ReactionItem) | ||
} |
47 changes: 47 additions & 0 deletions
47
app/src/main/java/com/nextcloud/talk/adapters/ReactionsAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Andy Scherzinger | ||
* Copyright (C) 2022 Andy Scherzinger <[email protected]> | ||
* | ||
* 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.adapters | ||
|
||
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 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, userEntity?.baseUrl) | ||
} | ||
|
||
override fun onBindViewHolder(holder: ReactionsViewHolder, position: Int) { | ||
holder.bind(list[position], clickListener) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return list.size | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
app/src/main/java/com/nextcloud/talk/adapters/ReactionsViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Nextcloud Talk application | ||
* | ||
* @author Andy Scherzinger | ||
* Copyright (C) 2022 Andy Scherzinger <[email protected]> | ||
* | ||
* 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.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, | ||
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.