diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/menu/ActionItem.kt b/app/src/main/java/org/thoughtcrime/securesms/components/menu/ActionItem.kt index 866962b38e..b63659c6c8 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/menu/ActionItem.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/menu/ActionItem.kt @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms.components.menu +import android.content.Context import androidx.annotation.AttrRes /** @@ -10,5 +11,5 @@ data class ActionItem( val title: Int, val action: Runnable, val contentDescription: Int? = null, - val subtitle: (() -> CharSequence?)? = null + val subtitle: ((Context) -> CharSequence?)? = null ) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/menu/ContextMenuList.kt b/app/src/main/java/org/thoughtcrime/securesms/components/menu/ContextMenuList.kt index a61bda07be..21f092b5e2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/menu/ContextMenuList.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/menu/ContextMenuList.kt @@ -1,5 +1,6 @@ package org.thoughtcrime.securesms.components.menu +import android.content.Context import android.util.TypedValue import android.view.View import android.widget.ImageView @@ -101,8 +102,8 @@ class ContextMenuList(recyclerView: RecyclerView, onItemClick: () -> Unit) { }.let(itemView::setBackgroundResource) } - private fun startSubtitleJob(textView: TextView, getSubtitle: () -> CharSequence?) { - fun updateText() = getSubtitle().let { + private fun startSubtitleJob(textView: TextView, getSubtitle: (Context) -> CharSequence?) { + fun updateText() = getSubtitle(context).let { textView.isGone = it == null textView.text = it } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt index 5a5a600b34..f982974d19 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationReactionOverlay.kt @@ -549,13 +549,7 @@ class ConversationReactionOverlay : FrameLayout { } // Delete message if (userCanDeleteSelectedItems(context, message, openGroup, userPublicKey, blindedPublicKey)) { - val subtitle = { message.takeIf { it.expireStarted > 0 } - ?.run { expiresIn - (SnodeAPI.nowWithOffset - expireStarted) } - ?.coerceAtLeast(0L) - ?.milliseconds - ?.to2partString() - ?.let { context.getString(R.string.auto_deletes_in, it) } } - items += ActionItem(R.attr.menu_trash_icon, R.string.delete, { handleActionItemClicked(Action.DELETE) }, R.string.AccessibilityId_delete_message, subtitle) + items += ActionItem(R.attr.menu_trash_icon, R.string.delete, { handleActionItemClicked(Action.DELETE) }, R.string.AccessibilityId_delete_message, message.subtitle) } // Ban user if (userCanBanSelectedUsers(context, message, openGroup, userPublicKey, blindedPublicKey)) { @@ -716,3 +710,14 @@ class ConversationReactionOverlay : FrameLayout { private fun Duration.to2partString(): String? = toComponents { days, hours, minutes, seconds, nanoseconds -> listOf(days.days, hours.hours, minutes.minutes, seconds.seconds) } .filter { it.inWholeSeconds > 0L }.take(2).takeIf { it.isNotEmpty() }?.joinToString(" ") + +private val MessageRecord.subtitle: ((Context) -> CharSequence?)? + get() = if (expiresIn <= 0) { + null + } else { context -> + (expiresIn - (SnodeAPI.nowWithOffset - (expireStarted.takeIf { it > 0 } ?: timestamp))) + .coerceAtLeast(0L) + .milliseconds + .to2partString() + ?.let { context.getString(R.string.auto_deletes_in, it) } + } \ No newline at end of file