2021-05-31 06:06:02 +02:00
|
|
|
package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
|
|
|
|
import android.content.Context
|
|
|
|
import android.util.AttributeSet
|
2021-05-31 06:29:11 +02:00
|
|
|
import android.view.LayoutInflater
|
2021-06-01 07:43:37 +02:00
|
|
|
import android.view.View
|
2021-05-31 06:06:02 +02:00
|
|
|
import android.widget.LinearLayout
|
2021-06-01 07:43:37 +02:00
|
|
|
import androidx.core.content.res.ResourcesCompat
|
2021-06-25 06:06:53 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-05-31 06:29:11 +02:00
|
|
|
import network.loki.messenger.R
|
2022-01-14 06:56:15 +01:00
|
|
|
import network.loki.messenger.databinding.ViewControlMessageBinding
|
2021-05-31 06:06:02 +02:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
|
|
|
|
2021-06-01 01:48:02 +02:00
|
|
|
class ControlMessageView : LinearLayout {
|
2021-05-31 06:06:02 +02:00
|
|
|
|
2022-01-14 06:56:15 +01:00
|
|
|
private lateinit var binding: ViewControlMessageBinding
|
|
|
|
|
2021-05-31 06:06:02 +02:00
|
|
|
// region Lifecycle
|
2021-06-21 06:00:48 +02:00
|
|
|
constructor(context: Context) : super(context) { initialize() }
|
|
|
|
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
|
|
|
|
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
|
2021-05-31 06:06:02 +02:00
|
|
|
|
2021-06-21 06:00:48 +02:00
|
|
|
private fun initialize() {
|
2022-01-14 06:56:15 +01:00
|
|
|
binding = ViewControlMessageBinding.inflate(LayoutInflater.from(context), this, true)
|
2021-06-25 06:06:53 +02:00
|
|
|
layoutParams = RecyclerView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, RecyclerView.LayoutParams.WRAP_CONTENT)
|
2021-05-31 06:06:02 +02:00
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
// region Updating
|
2021-12-03 06:51:21 +01:00
|
|
|
fun bind(message: MessageRecord, previous: MessageRecord?) {
|
2022-01-14 06:56:15 +01:00
|
|
|
binding.dateBreakTextView.showDateBreak(message, previous)
|
|
|
|
binding.iconImageView.visibility = View.GONE
|
2022-03-04 07:46:39 +01:00
|
|
|
var messageBody: CharSequence = message.getDisplayBody(context)
|
|
|
|
when {
|
|
|
|
message.isExpirationTimerUpdate -> {
|
|
|
|
binding.iconImageView.setImageDrawable(
|
|
|
|
ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme)
|
|
|
|
)
|
|
|
|
binding.iconImageView.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
message.isMediaSavedNotification -> {
|
|
|
|
binding.iconImageView.setImageDrawable(
|
|
|
|
ResourcesCompat.getDrawable(resources, R.drawable.ic_file_download_white_36dp, context.theme)
|
|
|
|
)
|
|
|
|
binding.iconImageView.visibility = View.VISIBLE
|
|
|
|
}
|
|
|
|
message.isMessageRequestResponse -> {
|
|
|
|
messageBody = context.getString(R.string.message_requests_accepted)
|
|
|
|
}
|
2022-03-17 06:49:35 +01:00
|
|
|
message.isCallLog -> {
|
|
|
|
val drawable = when {
|
|
|
|
message.isIncomingCall -> R.drawable.ic_incoming_call
|
|
|
|
message.isOutgoingCall -> R.drawable.ic_outgoing_call
|
2022-04-06 08:38:55 +02:00
|
|
|
message.isFirstMissedCall -> R.drawable.ic_info_outline_light
|
2022-03-17 06:49:35 +01:00
|
|
|
else -> R.drawable.ic_missed_call
|
|
|
|
}
|
|
|
|
binding.iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, drawable, context.theme))
|
|
|
|
binding.iconImageView.visibility = View.VISIBLE
|
2021-11-25 07:23:48 +01:00
|
|
|
}
|
2021-06-01 07:43:37 +02:00
|
|
|
}
|
2022-03-04 07:46:39 +01:00
|
|
|
|
|
|
|
binding.textView.text = messageBody
|
2021-05-31 06:06:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fun recycle() {
|
2021-06-28 06:51:49 +02:00
|
|
|
|
2021-05-31 06:06:02 +02:00
|
|
|
}
|
|
|
|
// endregion
|
|
|
|
}
|