|
|
|
|
@ -21,6 +21,7 @@ import android.view.View
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import com.keylesspalace.tusky.R |
|
|
|
|
import com.keylesspalace.tusky.components.report.model.StatusViewState |
|
|
|
|
import com.keylesspalace.tusky.databinding.ItemReportStatusBinding |
|
|
|
|
import com.keylesspalace.tusky.entity.Emoji |
|
|
|
|
import com.keylesspalace.tusky.entity.Status |
|
|
|
|
import com.keylesspalace.tusky.interfaces.LinkListener |
|
|
|
|
@ -28,16 +29,15 @@ import com.keylesspalace.tusky.util.*
|
|
|
|
|
import com.keylesspalace.tusky.util.StatusViewHelper.Companion.COLLAPSE_INPUT_FILTER |
|
|
|
|
import com.keylesspalace.tusky.util.StatusViewHelper.Companion.NO_INPUT_FILTER |
|
|
|
|
import com.keylesspalace.tusky.viewdata.toViewData |
|
|
|
|
import kotlinx.android.synthetic.main.item_report_status.view.* |
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
|
|
class StatusViewHolder( |
|
|
|
|
itemView: View, |
|
|
|
|
private val binding: ItemReportStatusBinding, |
|
|
|
|
private val statusDisplayOptions: StatusDisplayOptions, |
|
|
|
|
private val viewState: StatusViewState, |
|
|
|
|
private val adapterHandler: AdapterHandler, |
|
|
|
|
private val getStatusForPosition: (Int) -> Status? |
|
|
|
|
) : RecyclerView.ViewHolder(itemView) { |
|
|
|
|
) : RecyclerView.ViewHolder(binding.root) { |
|
|
|
|
private val mediaViewHeight = itemView.context.resources.getDimensionPixelSize(R.dimen.status_media_preview_height) |
|
|
|
|
private val statusViewHelper = StatusViewHelper(itemView) |
|
|
|
|
|
|
|
|
|
@ -56,16 +56,16 @@ class StatusViewHolder(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
init { |
|
|
|
|
itemView.statusSelection.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.statusSelection.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
status()?.let { status -> |
|
|
|
|
adapterHandler.setStatusChecked(status, isChecked) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
itemView.status_media_preview_container.clipToOutline = true |
|
|
|
|
binding.statusMediaPreviewContainer.clipToOutline = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun bind(status: Status) { |
|
|
|
|
itemView.statusSelection.isChecked = adapterHandler.isStatusChecked(status.id) |
|
|
|
|
binding.statusSelection.isChecked = adapterHandler.isStatusChecked(status.id) |
|
|
|
|
|
|
|
|
|
updateTextView() |
|
|
|
|
|
|
|
|
|
@ -86,18 +86,18 @@ class StatusViewHolder(
|
|
|
|
|
|
|
|
|
|
if (status.spoilerText.isBlank()) { |
|
|
|
|
setTextVisible(true, status.content, status.mentions, status.emojis, adapterHandler) |
|
|
|
|
itemView.statusContentWarningButton.hide() |
|
|
|
|
itemView.statusContentWarningDescription.hide() |
|
|
|
|
binding.statusContentWarningButton.hide() |
|
|
|
|
binding.statusContentWarningDescription.hide() |
|
|
|
|
} else { |
|
|
|
|
val emojiSpoiler = status.spoilerText.emojify(status.emojis, itemView.statusContentWarningDescription, statusDisplayOptions.animateEmojis) |
|
|
|
|
itemView.statusContentWarningDescription.text = emojiSpoiler |
|
|
|
|
itemView.statusContentWarningDescription.show() |
|
|
|
|
itemView.statusContentWarningButton.show() |
|
|
|
|
val emojiSpoiler = status.spoilerText.emojify(status.emojis, binding.statusContentWarningDescription, statusDisplayOptions.animateEmojis) |
|
|
|
|
binding.statusContentWarningDescription.text = emojiSpoiler |
|
|
|
|
binding.statusContentWarningDescription.show() |
|
|
|
|
binding.statusContentWarningButton.show() |
|
|
|
|
setContentWarningButtonText(viewState.isContentShow(status.id, true)) |
|
|
|
|
itemView.statusContentWarningButton.setOnClickListener { |
|
|
|
|
binding.statusContentWarningButton.setOnClickListener { |
|
|
|
|
status()?.let { status -> |
|
|
|
|
val contentShown = viewState.isContentShow(status.id, true) |
|
|
|
|
itemView.statusContentWarningDescription.invalidate() |
|
|
|
|
binding.statusContentWarningDescription.invalidate() |
|
|
|
|
viewState.setContentShow(status.id, !contentShown) |
|
|
|
|
setTextVisible(!contentShown, status.content, status.mentions, status.emojis, adapterHandler) |
|
|
|
|
setContentWarningButtonText(!contentShown) |
|
|
|
|
@ -110,9 +110,9 @@ class StatusViewHolder(
|
|
|
|
|
|
|
|
|
|
private fun setContentWarningButtonText(contentShown: Boolean) { |
|
|
|
|
if(contentShown) { |
|
|
|
|
itemView.statusContentWarningButton.setText(R.string.status_content_warning_show_less) |
|
|
|
|
binding.statusContentWarningButton.setText(R.string.status_content_warning_show_less) |
|
|
|
|
} else { |
|
|
|
|
itemView.statusContentWarningButton.setText(R.string.status_content_warning_show_more) |
|
|
|
|
binding.statusContentWarningButton.setText(R.string.status_content_warning_show_more) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -122,26 +122,26 @@ class StatusViewHolder(
|
|
|
|
|
emojis: List<Emoji>, |
|
|
|
|
listener: LinkListener) { |
|
|
|
|
if (expanded) { |
|
|
|
|
val emojifiedText = content.emojify(emojis, itemView.statusContent, statusDisplayOptions.animateEmojis) |
|
|
|
|
LinkHelper.setClickableText(itemView.statusContent, emojifiedText, mentions, listener) |
|
|
|
|
val emojifiedText = content.emojify(emojis, binding.statusContent, statusDisplayOptions.animateEmojis) |
|
|
|
|
LinkHelper.setClickableText(binding.statusContent, emojifiedText, mentions, listener) |
|
|
|
|
} else { |
|
|
|
|
LinkHelper.setClickableMentions(itemView.statusContent, mentions, listener) |
|
|
|
|
LinkHelper.setClickableMentions(binding.statusContent, mentions, listener) |
|
|
|
|
} |
|
|
|
|
if (itemView.statusContent.text.isNullOrBlank()) { |
|
|
|
|
itemView.statusContent.hide() |
|
|
|
|
if (binding.statusContent.text.isNullOrBlank()) { |
|
|
|
|
binding.statusContent.hide() |
|
|
|
|
} else { |
|
|
|
|
itemView.statusContent.show() |
|
|
|
|
binding.statusContent.show() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun setCreatedAt(createdAt: Date?) { |
|
|
|
|
if (statusDisplayOptions.useAbsoluteTime) { |
|
|
|
|
itemView.timestampInfo.text = statusViewHelper.getAbsoluteTime(createdAt) |
|
|
|
|
binding.timestampInfo.text = statusViewHelper.getAbsoluteTime(createdAt) |
|
|
|
|
} else { |
|
|
|
|
itemView.timestampInfo.text = if (createdAt != null) { |
|
|
|
|
binding.timestampInfo.text = if (createdAt != null) { |
|
|
|
|
val then = createdAt.time |
|
|
|
|
val now = System.currentTimeMillis() |
|
|
|
|
TimestampUtils.getRelativeTimeSpanString(itemView.timestampInfo.context, then, now) |
|
|
|
|
TimestampUtils.getRelativeTimeSpanString(binding.timestampInfo.context, then, now) |
|
|
|
|
} else { |
|
|
|
|
// unknown minutes~ |
|
|
|
|
"?m" |
|
|
|
|
@ -149,28 +149,27 @@ class StatusViewHolder(
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun setupCollapsedState(collapsible: Boolean, collapsed: Boolean, expanded: Boolean, spoilerText: String) { |
|
|
|
|
/* input filter for TextViews have to be set before text */ |
|
|
|
|
if (collapsible && (expanded || TextUtils.isEmpty(spoilerText))) { |
|
|
|
|
itemView.buttonToggleContent.setOnClickListener{ |
|
|
|
|
binding.buttonToggleContent.setOnClickListener{ |
|
|
|
|
status()?.let { status -> |
|
|
|
|
viewState.setCollapsed(status.id, !collapsed) |
|
|
|
|
updateTextView() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
itemView.buttonToggleContent.show() |
|
|
|
|
binding.buttonToggleContent.show() |
|
|
|
|
if (collapsed) { |
|
|
|
|
itemView.buttonToggleContent.setText(R.string.status_content_show_more) |
|
|
|
|
itemView.statusContent.filters = COLLAPSE_INPUT_FILTER |
|
|
|
|
binding.buttonToggleContent.setText(R.string.status_content_show_more) |
|
|
|
|
binding.statusContent.filters = COLLAPSE_INPUT_FILTER |
|
|
|
|
} else { |
|
|
|
|
itemView.buttonToggleContent.setText(R.string.status_content_show_less) |
|
|
|
|
itemView.statusContent.filters = NO_INPUT_FILTER |
|
|
|
|
binding.buttonToggleContent.setText(R.string.status_content_show_less) |
|
|
|
|
binding.statusContent.filters = NO_INPUT_FILTER |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
itemView.buttonToggleContent.hide() |
|
|
|
|
itemView.statusContent.filters = NO_INPUT_FILTER |
|
|
|
|
binding.buttonToggleContent.hide() |
|
|
|
|
binding.statusContent.filters = NO_INPUT_FILTER |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|