|
|
@ -5,9 +5,7 @@ import android.util.AttributeSet
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
import androidx.annotation.DimenRes
|
|
|
|
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.core.view.marginEnd
|
|
|
|
|
|
|
|
import androidx.recyclerview.widget.DiffUtil
|
|
|
|
import androidx.recyclerview.widget.DiffUtil
|
|
|
|
import androidx.recyclerview.widget.ListAdapter
|
|
|
|
import androidx.recyclerview.widget.ListAdapter
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
@ -21,6 +19,7 @@ import network.loki.messenger.libsession_util.util.ExpiryMode
|
|
|
|
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|
|
|
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
|
|
|
import org.session.libsession.messaging.open_groups.OpenGroup
|
|
|
|
import org.session.libsession.messaging.open_groups.OpenGroup
|
|
|
|
import org.session.libsession.utilities.ExpirationUtil
|
|
|
|
import org.session.libsession.utilities.ExpirationUtil
|
|
|
|
|
|
|
|
import org.session.libsession.utilities.modifyLayoutParams
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.MentionManagerUtilities
|
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase
|
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase
|
|
|
@ -28,12 +27,14 @@ import org.thoughtcrime.securesms.database.LokiAPIDatabase
|
|
|
|
import org.thoughtcrime.securesms.util.DateUtils
|
|
|
|
import org.thoughtcrime.securesms.util.DateUtils
|
|
|
|
import java.util.Locale
|
|
|
|
import java.util.Locale
|
|
|
|
import javax.inject.Inject
|
|
|
|
import javax.inject.Inject
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AndroidEntryPoint
|
|
|
|
@AndroidEntryPoint
|
|
|
|
class ConversationActionBarView : LinearLayout {
|
|
|
|
class ConversationActionBarView @JvmOverloads constructor(
|
|
|
|
|
|
|
|
context: Context,
|
|
|
|
private lateinit var binding: ViewConversationActionBarBinding
|
|
|
|
attrs: AttributeSet? = null,
|
|
|
|
|
|
|
|
defStyleAttr: Int = 0
|
|
|
|
|
|
|
|
) : LinearLayout(context, attrs, defStyleAttr) {
|
|
|
|
|
|
|
|
private val binding = ViewConversationActionBarBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
|
|
|
|
|
|
|
@Inject lateinit var lokiApiDb: LokiAPIDatabase
|
|
|
|
@Inject lateinit var lokiApiDb: LokiAPIDatabase
|
|
|
|
@Inject lateinit var groupDb: GroupDatabase
|
|
|
|
@Inject lateinit var groupDb: GroupDatabase
|
|
|
@ -46,12 +47,7 @@ class ConversationActionBarView : LinearLayout {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
constructor(context: Context) : super(context) { initialize() }
|
|
|
|
init {
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
|
|
|
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun initialize() {
|
|
|
|
|
|
|
|
binding = ViewConversationActionBarBinding.inflate(LayoutInflater.from(context), this, true)
|
|
|
|
|
|
|
|
var previousState: Int
|
|
|
|
var previousState: Int
|
|
|
|
var currentState = 0
|
|
|
|
var currentState = 0
|
|
|
|
binding.settingsPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
|
|
|
binding.settingsPager.registerOnPageChangeCallback(object : OnPageChangeCallback() {
|
|
|
@ -68,8 +64,7 @@ class ConversationActionBarView : LinearLayout {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
binding.settingsPager.adapter = settingsAdapter
|
|
|
|
binding.settingsPager.adapter = settingsAdapter
|
|
|
|
val mediator = TabLayoutMediator(binding.settingsTabLayout, binding.settingsPager) { _, _ -> }
|
|
|
|
TabLayoutMediator(binding.settingsTabLayout, binding.settingsPager) { _, _ -> }.attach()
|
|
|
|
mediator.attach()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun bind(
|
|
|
|
fun bind(
|
|
|
@ -80,42 +75,32 @@ class ConversationActionBarView : LinearLayout {
|
|
|
|
openGroup: OpenGroup? = null
|
|
|
|
openGroup: OpenGroup? = null
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
this.delegate = delegate
|
|
|
|
this.delegate = delegate
|
|
|
|
@DimenRes val sizeID: Int = if (recipient.isClosedGroupRecipient) {
|
|
|
|
binding.profilePictureView.layoutParams = resources.getDimensionPixelSize(
|
|
|
|
R.dimen.medium_profile_picture_size
|
|
|
|
if (recipient.isClosedGroupRecipient) R.dimen.medium_profile_picture_size else R.dimen.small_profile_picture_size
|
|
|
|
} else {
|
|
|
|
).let { LayoutParams(it, it) }
|
|
|
|
R.dimen.small_profile_picture_size
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
val size = resources.getDimension(sizeID).roundToInt()
|
|
|
|
|
|
|
|
binding.profilePictureView.layoutParams = LayoutParams(size, size)
|
|
|
|
|
|
|
|
MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadId, context)
|
|
|
|
MentionManagerUtilities.populateUserPublicKeyCacheIfNeeded(threadId, context)
|
|
|
|
update(recipient, openGroup, config)
|
|
|
|
update(recipient, openGroup, config)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fun update(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
|
|
|
fun update(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
|
|
|
binding.profilePictureView.update(recipient)
|
|
|
|
binding.profilePictureView.update(recipient)
|
|
|
|
binding.conversationTitleView.text = when {
|
|
|
|
binding.conversationTitleView.text = recipient.takeUnless { it.isLocalNumber }?.toShortString() ?: context.getString(R.string.note_to_self)
|
|
|
|
recipient.isLocalNumber -> context.getString(R.string.note_to_self)
|
|
|
|
|
|
|
|
else -> recipient.toShortString()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
updateSubtitle(recipient, openGroup, config)
|
|
|
|
updateSubtitle(recipient, openGroup, config)
|
|
|
|
|
|
|
|
|
|
|
|
binding.conversationTitleContainer.apply {
|
|
|
|
binding.conversationTitleContainer.modifyLayoutParams<MarginLayoutParams> {
|
|
|
|
layoutParams = (layoutParams as MarginLayoutParams).apply {
|
|
|
|
|
|
|
|
marginEnd = if (recipient.showCallMenu()) 0 else binding.profilePictureView.width
|
|
|
|
marginEnd = if (recipient.showCallMenu()) 0 else binding.profilePictureView.width
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun updateSubtitle(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
|
|
|
fun updateSubtitle(recipient: Recipient, openGroup: OpenGroup? = null, config: ExpirationConfiguration? = null) {
|
|
|
|
val settings = mutableListOf<ConversationSetting>()
|
|
|
|
val settings = mutableListOf<ConversationSetting>()
|
|
|
|
if (config?.isEnabled == true) {
|
|
|
|
if (config?.isEnabled == true) {
|
|
|
|
val prefix = if (config.expiryMode is ExpiryMode.AfterRead) {
|
|
|
|
val prefix = when (config.expiryMode) {
|
|
|
|
context.getString(R.string.expiration_type_disappear_after_read)
|
|
|
|
is ExpiryMode.AfterRead -> R.string.expiration_type_disappear_after_read
|
|
|
|
} else {
|
|
|
|
else -> R.string.expiration_type_disappear_after_send
|
|
|
|
context.getString(R.string.expiration_type_disappear_after_send)
|
|
|
|
}.let(context::getString)
|
|
|
|
}
|
|
|
|
|
|
|
|
settings += ConversationSetting(
|
|
|
|
settings += ConversationSetting(
|
|
|
|
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}" ,
|
|
|
|
"$prefix - ${ExpirationUtil.getExpirationAbbreviatedDisplayValue(context, config.expiryMode.expirySeconds)}",
|
|
|
|
ConversationSettingType.EXPIRATION,
|
|
|
|
ConversationSettingType.EXPIRATION,
|
|
|
|
R.drawable.ic_timer,
|
|
|
|
R.drawable.ic_timer,
|
|
|
|
resources.getString(R.string.AccessibilityId_disappearing_messages_type_and_time)
|
|
|
|
resources.getString(R.string.AccessibilityId_disappearing_messages_type_and_time)
|
|
|
@ -123,11 +108,9 @@ class ConversationActionBarView : LinearLayout {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (recipient.isMuted) {
|
|
|
|
if (recipient.isMuted) {
|
|
|
|
settings += ConversationSetting(
|
|
|
|
settings += ConversationSetting(
|
|
|
|
if (recipient.mutedUntil != Long.MAX_VALUE) {
|
|
|
|
recipient.mutedUntil.takeUnless { it == Long.MAX_VALUE }
|
|
|
|
context.getString(R.string.ConversationActivity_muted_until_date, DateUtils.getFormattedDateTime(recipient.mutedUntil, "EEE, MMM d, yyyy HH:mm", Locale.getDefault()))
|
|
|
|
?.let { context.getString(R.string.ConversationActivity_muted_until_date, DateUtils.getFormattedDateTime(it, "EEE, MMM d, yyyy HH:mm", Locale.getDefault())) }
|
|
|
|
} else {
|
|
|
|
?: context.getString(R.string.ConversationActivity_muted_forever),
|
|
|
|
context.getString(R.string.ConversationActivity_muted_forever)
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
ConversationSettingType.NOTIFICATION,
|
|
|
|
ConversationSettingType.NOTIFICATION,
|
|
|
|
R.drawable.ic_outline_notifications_off_24
|
|
|
|
R.drawable.ic_outline_notifications_off_24
|
|
|
|
)
|
|
|
|
)
|
|
|
@ -174,23 +157,15 @@ class ConversationActionBarView : LinearLayout {
|
|
|
|
binding.leftArrowImageView.isVisible = itemCount > 1
|
|
|
|
binding.leftArrowImageView.isVisible = itemCount > 1
|
|
|
|
binding.rightArrowImageView.isVisible = itemCount > 1
|
|
|
|
binding.rightArrowImageView.isVisible = itemCount > 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SettingsDiffer: DiffUtil.ItemCallback<ConversationSetting>() {
|
|
|
|
class SettingsDiffer: DiffUtil.ItemCallback<ConversationSetting>() {
|
|
|
|
override fun areItemsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean {
|
|
|
|
override fun areItemsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean = oldItem.settingType === newItem.settingType
|
|
|
|
return oldItem.settingType === newItem.settingType
|
|
|
|
override fun areContentsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean = oldItem == newItem
|
|
|
|
}
|
|
|
|
}
|
|
|
|
override fun areContentsTheSame(oldItem: ConversationSetting, newItem: ConversationSetting): Boolean {
|
|
|
|
|
|
|
|
return oldItem == newItem
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun interface ConversationActionBarDelegate {
|
|
|
|
fun interface ConversationActionBarDelegate {
|
|
|
|
fun onDisappearingMessagesClicked()
|
|
|
|
fun onDisappearingMessagesClicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|