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-12-03 06:51:21 +01:00
|
|
|
import androidx.core.view.isVisible
|
2021-06-25 06:06:53 +02:00
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
2021-06-01 05:01:03 +02:00
|
|
|
import kotlinx.android.synthetic.main.view_control_message.view.*
|
2021-05-31 06:29:11 +02:00
|
|
|
import network.loki.messenger.R
|
2021-12-06 05:07:46 +01:00
|
|
|
import org.thoughtcrime.securesms.conversation.v2.ConversationConstants.MAX_TIME_BETWEEN_BREAKS
|
2021-05-31 06:06:02 +02:00
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
2021-12-03 06:51:21 +01:00
|
|
|
import org.thoughtcrime.securesms.util.DateUtils
|
|
|
|
import java.util.Locale
|
2021-05-31 06:06:02 +02:00
|
|
|
|
2021-06-01 01:48:02 +02:00
|
|
|
class ControlMessageView : LinearLayout {
|
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() {
|
2021-06-01 01:48:02 +02:00
|
|
|
LayoutInflater.from(context).inflate(R.layout.view_control_message, this)
|
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?) {
|
2021-12-06 05:07:46 +01:00
|
|
|
val showDateBreak = (previous == null || message.timestamp - previous.timestamp > MAX_TIME_BETWEEN_BREAKS)
|
2021-12-03 06:51:21 +01:00
|
|
|
dateBreakTextView.isVisible = showDateBreak
|
|
|
|
dateBreakTextView.text = if (showDateBreak) DateUtils.getDisplayFormattedTimeSpanString(context, Locale.getDefault(), message.timestamp) else ""
|
2021-06-01 07:43:37 +02:00
|
|
|
iconImageView.visibility = View.GONE
|
|
|
|
if (message.isExpirationTimerUpdate) {
|
|
|
|
iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_timer, context.theme))
|
|
|
|
iconImageView.visibility = View.VISIBLE
|
2021-06-30 02:30:10 +02:00
|
|
|
} else if (message.isMediaSavedNotification) {
|
|
|
|
iconImageView.setImageDrawable(ResourcesCompat.getDrawable(resources, R.drawable.ic_file_download_white_36dp, context.theme))
|
|
|
|
iconImageView.visibility = View.VISIBLE
|
2021-06-01 07:43:37 +02:00
|
|
|
}
|
2021-06-01 06:28:14 +02:00
|
|
|
textView.text = message.getDisplayBody(context)
|
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
|
|
|
|
}
|