2021-03-07 19:24:01 +01:00
|
|
|
/* Copyright 2021 Tusky Contributors
|
|
|
|
*
|
|
|
|
* This file is a part of Tusky.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Tusky 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 Tusky; if not,
|
|
|
|
* see <http://www.gnu.org/licenses>. */
|
|
|
|
|
2020-03-19 22:02:10 +01:00
|
|
|
package com.keylesspalace.tusky.adapter
|
|
|
|
|
2020-11-04 18:21:41 +01:00
|
|
|
import android.graphics.Typeface
|
|
|
|
import android.text.SpannableStringBuilder
|
|
|
|
import android.text.Spanned
|
|
|
|
import android.text.style.StyleSpan
|
2020-03-19 22:02:10 +01:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import com.keylesspalace.tusky.R
|
2021-03-07 19:24:01 +01:00
|
|
|
import com.keylesspalace.tusky.databinding.ItemFollowRequestBinding
|
2022-03-15 21:34:57 +01:00
|
|
|
import com.keylesspalace.tusky.entity.TimelineAccount
|
2020-03-19 22:02:10 +01:00
|
|
|
import com.keylesspalace.tusky.interfaces.AccountActionListener
|
2023-05-13 15:32:56 +02:00
|
|
|
import com.keylesspalace.tusky.interfaces.LinkListener
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.emojify
|
2023-05-04 16:00:30 +02:00
|
|
|
import com.keylesspalace.tusky.util.hide
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.loadAvatar
|
2023-05-04 16:00:30 +02:00
|
|
|
import com.keylesspalace.tusky.util.parseAsMastodonHtml
|
2023-05-13 15:32:56 +02:00
|
|
|
import com.keylesspalace.tusky.util.setClickableText
|
|
|
|
import com.keylesspalace.tusky.util.show
|
2021-06-28 21:13:24 +02:00
|
|
|
import com.keylesspalace.tusky.util.unicodeWrap
|
|
|
|
import com.keylesspalace.tusky.util.visible
|
2020-03-19 22:02:10 +01:00
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
class FollowRequestViewHolder(
|
2021-06-28 21:13:24 +02:00
|
|
|
private val binding: ItemFollowRequestBinding,
|
2023-05-13 15:32:56 +02:00
|
|
|
private val linkListener: LinkListener,
|
2021-06-28 21:13:24 +02:00
|
|
|
private val showHeader: Boolean
|
2023-09-09 21:11:23 +02:00
|
|
|
) : RecyclerView.ViewHolder(binding.root) {
|
2020-03-19 22:02:10 +01:00
|
|
|
|
2022-12-28 19:07:43 +01:00
|
|
|
fun setupWithAccount(
|
|
|
|
account: TimelineAccount,
|
|
|
|
animateAvatar: Boolean,
|
|
|
|
animateEmojis: Boolean,
|
|
|
|
showBotOverlay: Boolean
|
|
|
|
) {
|
2020-11-04 18:21:41 +01:00
|
|
|
val wrappedName = account.name.unicodeWrap()
|
2023-09-09 21:11:23 +02:00
|
|
|
val emojifiedName: CharSequence = wrappedName.emojify(account.emojis, itemView, animateEmojis)
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.displayNameTextView.text = emojifiedName
|
2020-03-19 22:02:10 +01:00
|
|
|
if (showHeader) {
|
2023-09-09 21:11:23 +02:00
|
|
|
val wholeMessage: String = itemView.context.getString(R.string.notification_follow_request_format, wrappedName)
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.notificationTextView.text = SpannableStringBuilder(wholeMessage).apply {
|
2023-09-09 21:11:23 +02:00
|
|
|
setSpan(StyleSpan(Typeface.BOLD), 0, wrappedName.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
|
2021-02-06 08:14:51 +01:00
|
|
|
}.emojify(account.emojis, itemView, animateEmojis)
|
2020-03-19 22:02:10 +01:00
|
|
|
}
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.notificationTextView.visible(showHeader)
|
2023-02-04 20:29:13 +01:00
|
|
|
val formattedUsername = itemView.context.getString(R.string.post_username_format, account.username)
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.usernameTextView.text = formattedUsername
|
2023-05-04 16:00:30 +02:00
|
|
|
if (account.note.isEmpty()) {
|
|
|
|
binding.accountNote.hide()
|
|
|
|
} else {
|
2023-05-13 15:32:56 +02:00
|
|
|
binding.accountNote.show()
|
|
|
|
|
|
|
|
val emojifiedNote = account.note.parseAsMastodonHtml()
|
|
|
|
.emojify(account.emojis, binding.accountNote, animateEmojis)
|
|
|
|
setClickableText(binding.accountNote, emojifiedNote, emptyList(), null, linkListener)
|
2023-05-04 16:00:30 +02:00
|
|
|
}
|
|
|
|
val avatarRadius = binding.avatar.context.resources.getDimensionPixelSize(R.dimen.avatar_radius_48dp)
|
2021-03-07 19:24:01 +01:00
|
|
|
loadAvatar(account.avatar, binding.avatar, avatarRadius, animateAvatar)
|
2023-02-04 20:29:13 +01:00
|
|
|
binding.avatarBadge.visible(showBotOverlay && account.bot)
|
2020-03-19 22:02:10 +01:00
|
|
|
}
|
|
|
|
|
2021-03-07 19:24:01 +01:00
|
|
|
fun setupActionListener(listener: AccountActionListener, accountId: String) {
|
|
|
|
binding.acceptButton.setOnClickListener {
|
2021-04-10 20:30:44 +02:00
|
|
|
val position = bindingAdapterPosition
|
2020-03-19 22:02:10 +01:00
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
2021-03-07 19:24:01 +01:00
|
|
|
listener.onRespondToFollowRequest(true, accountId, position)
|
2020-03-19 22:02:10 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-07 19:24:01 +01:00
|
|
|
binding.rejectButton.setOnClickListener {
|
2021-04-10 20:30:44 +02:00
|
|
|
val position = bindingAdapterPosition
|
2020-03-19 22:02:10 +01:00
|
|
|
if (position != RecyclerView.NO_POSITION) {
|
2021-03-07 19:24:01 +01:00
|
|
|
listener.onRespondToFollowRequest(false, accountId, position)
|
2020-03-19 22:02:10 +01:00
|
|
|
}
|
|
|
|
}
|
2021-03-07 19:24:01 +01:00
|
|
|
itemView.setOnClickListener { listener.onViewAccount(accountId) }
|
2020-03-19 22:02:10 +01:00
|
|
|
}
|
|
|
|
}
|