2021-06-28 09:09:00 +02:00
|
|
|
package jp.juggler.subwaytooter.itemviewholder
|
2021-06-22 10:31:51 +02:00
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
import android.text.Spannable
|
2021-06-22 10:31:51 +02:00
|
|
|
import android.text.SpannableStringBuilder
|
|
|
|
import android.view.View
|
|
|
|
import android.widget.ImageView
|
2023-04-22 08:41:17 +02:00
|
|
|
import jp.juggler.subwaytooter.ActMain
|
|
|
|
import jp.juggler.subwaytooter.R
|
2021-06-28 09:09:00 +02:00
|
|
|
import jp.juggler.subwaytooter.actmain.checkAutoCW
|
2023-04-22 08:41:17 +02:00
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAccount
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAttachment
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAttachmentLike
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootAttachmentType
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootMessageHolder
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootNotification
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootPolls
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootPollsType
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootStatus
|
|
|
|
import jp.juggler.subwaytooter.api.entity.TootVisibility
|
|
|
|
import jp.juggler.subwaytooter.calcIconRound
|
2021-06-28 09:09:00 +02:00
|
|
|
import jp.juggler.subwaytooter.column.Column
|
|
|
|
import jp.juggler.subwaytooter.column.ColumnType
|
2022-08-02 04:41:05 +02:00
|
|
|
import jp.juggler.subwaytooter.column.isConversation
|
2023-04-22 08:41:17 +02:00
|
|
|
import jp.juggler.subwaytooter.defaultColorIcon
|
2021-11-06 04:00:29 +01:00
|
|
|
import jp.juggler.subwaytooter.pref.PrefB
|
|
|
|
import jp.juggler.subwaytooter.pref.PrefI
|
2023-04-22 08:41:17 +02:00
|
|
|
import jp.juggler.subwaytooter.stylerBoostAlpha
|
2023-02-04 21:52:26 +01:00
|
|
|
import jp.juggler.subwaytooter.table.daoContentWarning
|
|
|
|
import jp.juggler.subwaytooter.table.daoMediaShown
|
2021-06-22 10:31:51 +02:00
|
|
|
import jp.juggler.subwaytooter.util.OpenSticker
|
2023-04-22 08:41:17 +02:00
|
|
|
import jp.juggler.util.data.cast
|
|
|
|
import jp.juggler.util.data.ellipsizeDot3
|
|
|
|
import jp.juggler.util.data.notBlank
|
|
|
|
import jp.juggler.util.data.notEmpty
|
|
|
|
import jp.juggler.util.data.notZero
|
2023-01-13 13:22:25 +01:00
|
|
|
import jp.juggler.util.log.LogCategory
|
|
|
|
import jp.juggler.util.ui.attrColor
|
|
|
|
import jp.juggler.util.ui.setIconDrawableId
|
|
|
|
import jp.juggler.util.ui.textOrGone
|
|
|
|
import jp.juggler.util.ui.vg
|
2021-06-22 10:31:51 +02:00
|
|
|
import org.jetbrains.anko.backgroundColor
|
2023-02-10 12:45:48 +01:00
|
|
|
import org.jetbrains.anko.imageResource
|
2021-06-22 10:31:51 +02:00
|
|
|
import org.jetbrains.anko.textColor
|
|
|
|
|
2022-12-27 03:54:52 +01:00
|
|
|
private val log = LogCategory("ItemViewHolderShowStatus")
|
|
|
|
|
2021-12-03 17:57:07 +01:00
|
|
|
fun ItemViewHolder.showStatusOrReply(
|
|
|
|
item: TootStatus,
|
|
|
|
colorBgArg: Int = 0,
|
2022-03-11 00:11:49 +01:00
|
|
|
fadeText: Boolean = false,
|
2021-12-03 17:57:07 +01:00
|
|
|
) {
|
2021-06-22 10:31:51 +02:00
|
|
|
var colorBg = colorBgArg
|
|
|
|
val reply = item.reply
|
|
|
|
val inReplyToId = item.in_reply_to_id
|
|
|
|
val inReplyToAccountId = item.in_reply_to_account_id
|
|
|
|
when {
|
|
|
|
reply != null -> {
|
2023-01-07 14:37:33 +01:00
|
|
|
showReply(item.account, reply, R.drawable.ic_reply, R.string.reply_to)
|
2023-02-04 21:52:26 +01:00
|
|
|
if (colorBgArg == 0) colorBg = PrefI.ipEventBgColorMention.value
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inReplyToId != null && inReplyToAccountId != null -> {
|
2023-01-07 14:37:33 +01:00
|
|
|
showReply(null, item, inReplyToAccountId)
|
2023-02-04 21:52:26 +01:00
|
|
|
if (colorBgArg == 0) colorBg = PrefI.ipEventBgColorMention.value
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
}
|
2021-12-03 17:57:07 +01:00
|
|
|
showStatus(item, colorBg, fadeText = fadeText)
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
2021-12-03 17:57:07 +01:00
|
|
|
fun ItemViewHolder.showStatus(
|
|
|
|
status: TootStatus,
|
|
|
|
colorBg: Int = 0,
|
2022-03-11 00:11:49 +01:00
|
|
|
fadeText: Boolean = false,
|
2021-12-03 17:57:07 +01:00
|
|
|
) {
|
2021-06-22 10:31:51 +02:00
|
|
|
|
|
|
|
val filteredWord = status.filteredWord
|
|
|
|
if (filteredWord != null) {
|
2023-02-10 13:35:32 +01:00
|
|
|
PrefI.ipEventBgColorFiltered.value.notZero()?.let {
|
2023-02-10 13:19:55 +01:00
|
|
|
viewRoot.backgroundColor = it
|
|
|
|
}
|
2023-02-10 13:35:32 +01:00
|
|
|
val text = StringBuilder().apply {
|
|
|
|
append(activity.getString(R.string.filtered))
|
|
|
|
if (PrefB.bpShowFilteredWord.value) {
|
|
|
|
append(" / $filteredWord")
|
|
|
|
}
|
|
|
|
if (PrefB.bpShowUsernameFilteredPost.value) {
|
|
|
|
val s = status.reblog ?: status
|
|
|
|
append(" / ${s.account.display_name} @${s.account.acct}")
|
|
|
|
}
|
|
|
|
}.toString()
|
|
|
|
showMessageHolder(TootMessageHolder(text))
|
2021-06-22 10:31:51 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
this.statusShowing = status
|
|
|
|
llStatus.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
if (status.conversation_main) {
|
2023-02-04 21:52:26 +01:00
|
|
|
PrefI.ipConversationMainTootBgColor.value.notZero()
|
2023-01-13 07:33:28 +01:00
|
|
|
?: activity.attrColor(R.attr.colorConversationMainTootBg)
|
2021-06-22 10:31:51 +02:00
|
|
|
} else {
|
2021-06-24 04:31:34 +02:00
|
|
|
colorBg.notZero() ?: when (status.bookmarked) {
|
2023-02-04 21:52:26 +01:00
|
|
|
true -> PrefI.ipEventBgColorBookmark.value
|
2021-06-24 04:31:34 +02:00
|
|
|
false -> 0
|
|
|
|
}.notZero() ?: when (status.getBackgroundColorType(accessInfo)) {
|
|
|
|
TootVisibility.UnlistedHome -> ItemViewHolder.toot_color_unlisted
|
|
|
|
TootVisibility.PrivateFollowers -> ItemViewHolder.toot_color_follower
|
|
|
|
TootVisibility.DirectSpecified -> ItemViewHolder.toot_color_direct_user
|
|
|
|
TootVisibility.DirectPrivate -> ItemViewHolder.toot_color_direct_me
|
|
|
|
// TODO add color setting for limited?
|
|
|
|
TootVisibility.Limited -> ItemViewHolder.toot_color_follower
|
|
|
|
else -> 0
|
|
|
|
}.notZero()
|
|
|
|
}?.let { viewRoot.backgroundColor = it }
|
2021-06-22 10:31:51 +02:00
|
|
|
|
|
|
|
showStatusTime(activity, tvTime, who = status.account, status = status)
|
|
|
|
|
|
|
|
val whoRef = status.accountRef
|
|
|
|
val who = whoRef.get()
|
|
|
|
this.statusAccount = whoRef
|
|
|
|
|
|
|
|
setAcct(tvAcct, accessInfo, who)
|
|
|
|
|
2023-02-21 16:17:29 +01:00
|
|
|
nameInvalidator.text = whoRef.decoded_display_name
|
|
|
|
|
2021-06-22 10:31:51 +02:00
|
|
|
ivAvatar.setImageUrl(
|
2023-01-13 13:22:25 +01:00
|
|
|
calcIconRound(ivAvatar.layoutParams),
|
2021-06-22 10:31:51 +02:00
|
|
|
accessInfo.supplyBaseUrl(who.avatar_static),
|
|
|
|
accessInfo.supplyBaseUrl(who.avatar)
|
|
|
|
)
|
|
|
|
|
|
|
|
showOpenSticker(who)
|
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
val modifiedContent = if (status.time_deleted_at > 0L) {
|
|
|
|
SpannableStringBuilder()
|
|
|
|
.append('(')
|
|
|
|
.append(
|
|
|
|
activity.getString(
|
|
|
|
R.string.deleted_at,
|
|
|
|
TootStatus.formatTime(activity, status.time_deleted_at, true)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.append(')')
|
|
|
|
} else {
|
|
|
|
showPoll(status) ?: status.decoded_content
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// if( status.decoded_tags == null ){
|
|
|
|
// tvTags.setVisibility( View.GONE );
|
|
|
|
// }else{
|
|
|
|
// tvTags.setVisibility( View.VISIBLE );
|
|
|
|
// tvTags.setText( status.decoded_tags );
|
|
|
|
// }
|
|
|
|
|
2021-12-03 17:57:07 +01:00
|
|
|
val fadeAlpha = ActMain.eventFadeAlpha
|
|
|
|
if (fadeAlpha < 1f) {
|
|
|
|
val a = if (fadeText) fadeAlpha else 1f
|
|
|
|
tvMentions.alpha = a
|
|
|
|
tvContentWarning.alpha = a
|
|
|
|
tvContent.alpha = a
|
|
|
|
tvApplication.alpha = a
|
2021-12-04 09:55:28 +01:00
|
|
|
tvCardText.alpha = a
|
2021-12-03 17:57:07 +01:00
|
|
|
}
|
|
|
|
|
2022-03-11 00:11:49 +01:00
|
|
|
tvMentions.textOrGone = status.decoded_mentions
|
2021-06-22 10:31:51 +02:00
|
|
|
|
2023-02-21 16:17:29 +01:00
|
|
|
contentInvalidator.text = modifiedContent
|
2021-06-22 10:31:51 +02:00
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
activity.checkAutoCW(status, modifiedContent)
|
2021-06-22 10:31:51 +02:00
|
|
|
val r = status.auto_cw
|
|
|
|
tvContent.minLines = r?.originalLineCount ?: -1
|
|
|
|
|
2022-01-05 04:54:30 +01:00
|
|
|
showPreviewCard(status)
|
2021-06-24 04:31:34 +02:00
|
|
|
showSpoilerTextAndContent(status)
|
|
|
|
showAttachments(status)
|
|
|
|
makeReactionsView(status)
|
|
|
|
buttonsForStatus?.bind(status, (item as? TootNotification))
|
|
|
|
showApplicationAndLanguage(status)
|
|
|
|
}
|
|
|
|
|
|
|
|
// 投票の表示
|
|
|
|
// returns modified decoded_content or null
|
|
|
|
private fun ItemViewHolder.showPoll(status: TootStatus): Spannable? {
|
|
|
|
val enquete = status.enquete
|
|
|
|
return when {
|
|
|
|
enquete == null -> null
|
|
|
|
|
|
|
|
// フレニコの投票の結果表示は普通にテキストを表示するだけでよい
|
|
|
|
enquete.pollType == TootPollsType.FriendsNico && enquete.type != TootPolls.TYPE_ENQUETE -> null
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
showEnqueteItems(status, enquete)
|
|
|
|
// アンケートの本文を使ってcontentを上書きする
|
|
|
|
enquete.decoded_question.notBlank()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun ItemViewHolder.showSpoilerTextAndContent(status: TootStatus) {
|
|
|
|
val r = status.auto_cw
|
2021-06-22 10:31:51 +02:00
|
|
|
val decodedSpoilerText = status.decoded_spoiler_text
|
2023-02-21 16:17:29 +01:00
|
|
|
val autoCwText = r?.decodedSpoilerText
|
2021-06-22 10:31:51 +02:00
|
|
|
when {
|
|
|
|
decodedSpoilerText.isNotEmpty() -> {
|
|
|
|
// 元データに含まれるContent Warning を使う
|
|
|
|
llContentWarning.visibility = View.VISIBLE
|
2023-02-21 16:17:29 +01:00
|
|
|
spoilerInvalidator.text = status.decoded_spoiler_text
|
2023-02-06 03:10:24 +01:00
|
|
|
val cwShown = daoContentWarning.isShown(status, accessInfo.expandCw)
|
2021-06-24 04:31:34 +02:00
|
|
|
setContentVisibility(cwShown)
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
2023-02-21 16:17:29 +01:00
|
|
|
autoCwText != null -> {
|
2021-06-22 10:31:51 +02:00
|
|
|
// 自動CW
|
|
|
|
llContentWarning.visibility = View.VISIBLE
|
2023-02-21 16:17:29 +01:00
|
|
|
spoilerInvalidator.text = autoCwText
|
2023-02-06 03:10:24 +01:00
|
|
|
val cwShown = daoContentWarning.isShown(status, accessInfo.expandCw)
|
2021-06-24 04:31:34 +02:00
|
|
|
setContentVisibility(cwShown)
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
// CWしない
|
|
|
|
llContentWarning.visibility = View.GONE
|
|
|
|
llContents.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
}
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
2021-06-22 10:31:51 +02:00
|
|
|
|
2021-06-24 06:49:27 +02:00
|
|
|
// 予約投稿でも使う
|
|
|
|
fun ItemViewHolder.setContentVisibility(shown: Boolean) {
|
2021-06-24 04:31:34 +02:00
|
|
|
llContents.visibility = if (shown) View.VISIBLE else View.GONE
|
2023-02-10 13:35:32 +01:00
|
|
|
btnContentWarning.contentDescription =
|
|
|
|
activity.getString(if (shown) R.string.hide else R.string.show)
|
|
|
|
btnContentWarning.imageResource =
|
|
|
|
if (shown) R.drawable.outline_compress_24 else R.drawable.outline_expand_24
|
2023-02-10 12:45:48 +01:00
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
statusShowing?.let { status ->
|
|
|
|
val r = status.auto_cw
|
|
|
|
tvContent.minLines = r?.originalLineCount ?: -1
|
2023-02-21 16:17:29 +01:00
|
|
|
val autoCwText = r?.decodedSpoilerText
|
|
|
|
if (autoCwText != null) {
|
2021-06-24 04:31:34 +02:00
|
|
|
// 自動CWの場合はContentWarningのテキストを切り替える
|
2023-02-21 16:17:29 +01:00
|
|
|
spoilerInvalidator.text =
|
|
|
|
if (shown) activity.getString(R.string.auto_cw_prefix) else autoCwText
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
}
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
2021-06-22 10:31:51 +02:00
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
private fun ItemViewHolder.showApplicationAndLanguage(status: TootStatus) {
|
2021-06-22 10:31:51 +02:00
|
|
|
|
|
|
|
var sb: StringBuilder? = null
|
|
|
|
fun prepareSb(): StringBuilder =
|
|
|
|
sb?.append(", ") ?: StringBuilder().also { sb = it }
|
|
|
|
|
|
|
|
val application = status.application
|
|
|
|
if (application != null &&
|
2023-02-04 21:52:26 +01:00
|
|
|
(column.isConversation || PrefB.bpShowAppName.value)
|
2021-06-22 10:31:51 +02:00
|
|
|
) {
|
|
|
|
prepareSb().append(activity.getString(R.string.application_is, application.name ?: ""))
|
|
|
|
}
|
|
|
|
|
|
|
|
val language = status.language
|
|
|
|
if (language != null &&
|
2023-02-04 21:52:26 +01:00
|
|
|
(column.isConversation || PrefB.bpShowLanguage.value)
|
2021-06-22 10:31:51 +02:00
|
|
|
) {
|
|
|
|
prepareSb().append(activity.getString(R.string.language_is, language))
|
|
|
|
}
|
|
|
|
|
|
|
|
tvApplication.vg(sb != null)?.text = sb
|
|
|
|
}
|
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
private fun ItemViewHolder.showOpenSticker(who: TootAccount) {
|
2021-06-22 10:31:51 +02:00
|
|
|
try {
|
|
|
|
if (!Column.showOpenSticker) return
|
|
|
|
|
|
|
|
val host = who.apDomain
|
|
|
|
|
|
|
|
// LTLでホスト名が同じならTickerを表示しない
|
|
|
|
when (column.type) {
|
|
|
|
ColumnType.LOCAL, ColumnType.LOCAL_AROUND -> {
|
|
|
|
if (host == accessInfo.apDomain) return
|
|
|
|
}
|
2023-04-22 08:41:17 +02:00
|
|
|
|
2021-11-20 01:36:43 +01:00
|
|
|
else -> Unit
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
val item = OpenSticker.lastList[host.ascii] ?: return
|
|
|
|
|
|
|
|
tvOpenSticker.text = item.name
|
|
|
|
tvOpenSticker.textColor = item.fontColor
|
|
|
|
|
|
|
|
val density = activity.density
|
|
|
|
|
|
|
|
val lp = ivOpenSticker.layoutParams
|
|
|
|
lp.height = (density * 16f + 0.5f).toInt()
|
|
|
|
lp.width = (density * item.imageWidth + 0.5f).toInt()
|
|
|
|
|
|
|
|
ivOpenSticker.layoutParams = lp
|
2021-11-20 01:36:43 +01:00
|
|
|
ivOpenSticker.setImageUrl(0f, item.favicon)
|
2021-06-22 10:31:51 +02:00
|
|
|
val colorBg = item.bgColor
|
|
|
|
when (colorBg.size) {
|
|
|
|
1 -> {
|
|
|
|
val c = colorBg.first()
|
|
|
|
tvOpenSticker.setBackgroundColor(c)
|
|
|
|
ivOpenSticker.setBackgroundColor(c)
|
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
ivOpenSticker.setBackgroundColor(colorBg.last())
|
|
|
|
tvOpenSticker.background = colorBg.getGradation()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
llOpenSticker.visibility = View.VISIBLE
|
|
|
|
llOpenSticker.requestLayout()
|
|
|
|
} catch (ex: Throwable) {
|
2022-12-27 03:54:52 +01:00
|
|
|
log.e(ex, "showOpenSticker failed.")
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
private fun ItemViewHolder.showAttachments(status: TootStatus) {
|
|
|
|
val mediaAttachments = status.media_attachments
|
2023-04-22 08:41:17 +02:00
|
|
|
if (mediaAttachments.isNullOrEmpty()) {
|
2021-06-24 04:31:34 +02:00
|
|
|
flMedia.visibility = View.GONE
|
|
|
|
llMedia.visibility = View.GONE
|
|
|
|
btnShowMedia.visibility = View.GONE
|
|
|
|
} else {
|
|
|
|
flMedia.visibility = View.VISIBLE
|
2023-04-22 08:41:17 +02:00
|
|
|
tvMediaCount.vg(mediaAttachments.size > 4)?.let {
|
|
|
|
it.text = activity.getString(R.string.media_count, mediaAttachments.size)
|
|
|
|
}
|
2021-06-24 04:31:34 +02:00
|
|
|
|
|
|
|
// hide sensitive media
|
|
|
|
val defaultShown = when {
|
|
|
|
column.hideMediaDefault -> false
|
2023-02-06 03:10:24 +01:00
|
|
|
accessInfo.dontHideNsfw -> true
|
2021-06-24 04:31:34 +02:00
|
|
|
else -> !status.sensitive
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
2023-02-04 21:52:26 +01:00
|
|
|
val isShown = daoMediaShown.isShown(status, defaultShown)
|
2021-06-24 04:31:34 +02:00
|
|
|
|
|
|
|
btnShowMedia.visibility = if (!isShown) View.VISIBLE else View.GONE
|
|
|
|
llMedia.visibility = if (!isShown) View.GONE else View.VISIBLE
|
2022-09-10 22:06:56 +02:00
|
|
|
repeat(ItemViewHolder.MEDIA_VIEW_COUNT) { idx ->
|
|
|
|
setMedia(mediaAttachments, idx)
|
2021-06-24 04:31:34 +02:00
|
|
|
}
|
|
|
|
|
2022-09-10 22:06:56 +02:00
|
|
|
btnShowMedia.blurhash = mediaAttachments.firstOrNull()
|
|
|
|
?.cast<TootAttachment>()
|
|
|
|
?.blurhash
|
|
|
|
|
2021-06-24 04:31:34 +02:00
|
|
|
setIconDrawableId(
|
|
|
|
activity,
|
|
|
|
btnHideMedia,
|
|
|
|
R.drawable.ic_close,
|
2023-01-14 21:37:23 +01:00
|
|
|
color = colorTextContent,
|
|
|
|
alphaMultiplier = stylerBoostAlpha
|
2021-06-24 04:31:34 +02:00
|
|
|
)
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-20 04:40:12 +02:00
|
|
|
val reUrlGif by lazy {
|
2023-07-18 19:38:18 +02:00
|
|
|
"""\.gif(?:\z|\?|#)"""
|
|
|
|
.toRegex(RegexOption.IGNORE_CASE)
|
|
|
|
}
|
2023-07-17 02:37:48 +02:00
|
|
|
|
2021-06-22 10:31:51 +02:00
|
|
|
fun ItemViewHolder.setMedia(
|
|
|
|
mediaAttachments: ArrayList<TootAttachmentLike>,
|
|
|
|
idx: Int,
|
|
|
|
) {
|
2022-09-10 22:06:56 +02:00
|
|
|
val iv = ivMediaThumbnails[idx]
|
2021-06-22 10:31:51 +02:00
|
|
|
val ta = if (idx < mediaAttachments.size) mediaAttachments[idx] else null
|
|
|
|
if (ta == null) {
|
|
|
|
iv.visibility = View.GONE
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
iv.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
iv.setFocusPoint(ta.focusX, ta.focusY)
|
|
|
|
|
2023-02-04 21:52:26 +01:00
|
|
|
if (PrefB.bpDontCropMediaThumb.value) {
|
2021-06-22 10:31:51 +02:00
|
|
|
iv.scaleType = ImageView.ScaleType.FIT_CENTER
|
|
|
|
} else {
|
|
|
|
iv.setScaleTypeForMedia()
|
|
|
|
}
|
|
|
|
|
|
|
|
val showUrl: Boolean
|
|
|
|
|
|
|
|
when (ta.type) {
|
|
|
|
TootAttachmentType.Audio -> {
|
|
|
|
iv.setMediaType(0)
|
2023-01-13 13:22:25 +01:00
|
|
|
iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_music))
|
2023-02-04 21:52:26 +01:00
|
|
|
iv.setImageUrl(0f, ta.urlForThumbnail())
|
2021-06-22 10:31:51 +02:00
|
|
|
showUrl = true
|
|
|
|
}
|
|
|
|
|
|
|
|
TootAttachmentType.Unknown -> {
|
|
|
|
iv.setMediaType(0)
|
2023-01-13 13:22:25 +01:00
|
|
|
iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_question))
|
2023-07-17 02:37:48 +02:00
|
|
|
if (ta is TootAttachment &&
|
|
|
|
reUrlGif.containsMatchIn(ta.remote_url ?: "") &&
|
|
|
|
PrefB.bpImageAnimationEnable.value
|
|
|
|
) {
|
|
|
|
val url = ta.remote_url!!
|
|
|
|
iv.setImageUrl(0f, url, url)
|
|
|
|
} else {
|
|
|
|
iv.setImageUrl(0f, null)
|
|
|
|
}
|
2021-06-22 10:31:51 +02:00
|
|
|
showUrl = true
|
|
|
|
}
|
|
|
|
|
2023-07-17 02:37:48 +02:00
|
|
|
else -> if (ta is TootAttachment &&
|
|
|
|
reUrlGif.containsMatchIn(ta.remote_url ?: "") &&
|
|
|
|
PrefB.bpImageAnimationEnable.value
|
|
|
|
) {
|
|
|
|
iv.setMediaType(0)
|
|
|
|
iv.setDefaultImage(null)
|
|
|
|
val url = ta.remote_url!!
|
|
|
|
iv.setImageUrl(0f, url, url)
|
|
|
|
showUrl = false
|
|
|
|
} else when (val urlThumbnail = ta.urlForThumbnail()) {
|
2021-06-22 10:31:51 +02:00
|
|
|
null, "" -> {
|
|
|
|
iv.setMediaType(0)
|
2023-01-13 13:22:25 +01:00
|
|
|
iv.setDefaultImage(defaultColorIcon(activity, R.drawable.wide_question))
|
2021-11-20 01:36:43 +01:00
|
|
|
iv.setImageUrl(0f, null)
|
2021-06-22 10:31:51 +02:00
|
|
|
showUrl = true
|
|
|
|
}
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
iv.setMediaType(
|
|
|
|
when (ta.type) {
|
|
|
|
TootAttachmentType.Video -> R.drawable.media_type_video
|
|
|
|
TootAttachmentType.GIFV -> R.drawable.media_type_gifv
|
|
|
|
else -> 0
|
|
|
|
}
|
|
|
|
)
|
|
|
|
iv.setDefaultImage(null)
|
|
|
|
iv.setImageUrl(
|
|
|
|
0f,
|
|
|
|
accessInfo.supplyBaseUrl(urlThumbnail),
|
|
|
|
accessInfo.supplyBaseUrl(urlThumbnail)
|
|
|
|
)
|
|
|
|
showUrl = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:06:56 +02:00
|
|
|
val desc = ta.description.notEmpty()
|
|
|
|
?: if (!showUrl) null else ta.urlForDescription.notEmpty()
|
|
|
|
|
|
|
|
tvMediaDescriptions[idx].vg(
|
|
|
|
!desc.isNullOrBlank() && column.showMediaDescription
|
|
|
|
)?.let {
|
2021-06-22 10:31:51 +02:00
|
|
|
// val lp = LinearLayout.LayoutParams(
|
|
|
|
// LinearLayout.LayoutParams.MATCH_PARENT,
|
|
|
|
// LinearLayout.LayoutParams.WRAP_CONTENT
|
|
|
|
// )
|
|
|
|
// lp.topMargin = (0.5f + activity.density * 3f).toInt()
|
|
|
|
//
|
|
|
|
// val tv = MyTextView(activity)
|
|
|
|
// tv.layoutParams = lp
|
|
|
|
// //
|
|
|
|
// tv.movementMethod = MyLinkMovementMethod
|
|
|
|
// if(! activity.timeline_font_size_sp.isNaN()) {
|
|
|
|
// tv.textSize = activity.timeline_font_size_sp
|
|
|
|
// }
|
|
|
|
// tv.setTextColor(content_color)
|
2022-12-27 03:54:52 +01:00
|
|
|
it.setTag(R.id.text, desc)
|
2022-09-10 22:06:56 +02:00
|
|
|
it.text = activity.getString(
|
|
|
|
R.string.media_description,
|
|
|
|
idx + 1,
|
|
|
|
desc?.ellipsizeDot3(140)
|
|
|
|
)
|
2021-06-22 10:31:51 +02:00
|
|
|
}
|
|
|
|
}
|