Add message expiration timer icon

This commit is contained in:
Niels Andriesse 2021-06-30 15:40:15 +10:00
parent 9b513fa2ba
commit fa0b6703e1
3 changed files with 140 additions and 90 deletions

View File

@ -3,22 +3,27 @@ package org.thoughtcrime.securesms.conversation.v2.messages
import android.content.Context import android.content.Context
import android.content.res.Resources import android.content.res.Resources
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.ColorFilter
import android.graphics.Rect import android.graphics.Rect
import android.graphics.drawable.ColorDrawable import android.graphics.drawable.ColorDrawable
import android.os.AsyncTask
import android.os.Build import android.os.Build
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.util.AttributeSet import android.util.AttributeSet
import android.view.* import android.view.*
import android.widget.LinearLayout import android.widget.LinearLayout
import android.widget.RelativeLayout
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.view_visible_message.view.* import kotlinx.android.synthetic.main.view_visible_message.view.*
import kotlinx.android.synthetic.main.view_visible_message.view.profilePictureView
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.messaging.contacts.Contact.ContactContext import org.session.libsession.messaging.contacts.Contact.ContactContext
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2 import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
import org.session.libsession.utilities.ViewUtil import org.session.libsession.utilities.ViewUtil
import org.session.libsignal.utilities.ThreadUtils
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.database.model.MessageRecord import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.utilities.getColorWithID
@ -135,6 +140,8 @@ class VisibleMessageView : LinearLayout {
} else { } else {
messageStatusImageView.isVisible = false messageStatusImageView.isVisible = false
} }
// Expiration timer
updateExpirationTimer(message)
// Calculate max message bubble width // Calculate max message bubble width
var maxWidth = screenWidth - messageContentContainerLayoutParams.leftMargin - messageContentContainerLayoutParams.rightMargin var maxWidth = screenWidth - messageContentContainerLayoutParams.leftMargin - messageContentContainerLayoutParams.rightMargin
if (profilePictureContainer.visibility != View.GONE) { maxWidth -= profilePictureContainer.width } if (profilePictureContainer.visibility != View.GONE) { maxWidth -= profilePictureContainer.width }
@ -181,6 +188,37 @@ class VisibleMessageView : LinearLayout {
} }
} }
private fun updateExpirationTimer(message: MessageRecord) {
val expirationTimerViewLayoutParams = expirationTimerView.layoutParams as RelativeLayout.LayoutParams
val ruleToAdd = if (message.isOutgoing) RelativeLayout.ALIGN_PARENT_START else RelativeLayout.ALIGN_PARENT_END
val ruleToRemove = if (message.isOutgoing) RelativeLayout.ALIGN_PARENT_END else RelativeLayout.ALIGN_PARENT_START
expirationTimerViewLayoutParams.removeRule(ruleToRemove)
expirationTimerViewLayoutParams.addRule(ruleToAdd)
expirationTimerView.layoutParams = expirationTimerViewLayoutParams
if (message.expiresIn > 0 && !message.isPending) {
expirationTimerView.setColorFilter(ResourcesCompat.getColor(resources, R.color.text, context.theme))
expirationTimerView.isVisible = true
expirationTimerView.setPercentComplete(0.0f)
if (message.expireStarted > 0) {
expirationTimerView.setExpirationTime(message.expireStarted, message.expiresIn)
expirationTimerView.startAnimation()
if (message.expireStarted + message.expiresIn <= System.currentTimeMillis()) {
ApplicationContext.getInstance(context).expiringMessageManager.checkSchedule()
}
} else if (!message.isOutgoing && !message.isMediaPending) {
ThreadUtils.queue {
val expirationManager = ApplicationContext.getInstance(context).expiringMessageManager
val id = message.getId()
val mms = message.isMms
if (mms) DatabaseFactory.getMmsDatabase(context).markExpireStarted(id) else DatabaseFactory.getSmsDatabase(context).markExpireStarted(id)
expirationManager.scheduleDeletion(id, mms, message.expiresIn)
}
}
} else {
expirationTimerView.isVisible = false
}
}
private fun handleIsSelectedChanged() { private fun handleIsSelectedChanged() {
background = if (snIsSelected) { background = if (snIsSelected) {
ColorDrawable(context.resources.getColorWithID(R.color.message_selected, context.theme)) ColorDrawable(context.resources.getColorWithID(R.color.message_selected, context.theme))

View File

@ -5,7 +5,7 @@
android:id="@+id/searchBottomBarConstraintLayout" android:id="@+id/searchBottomBarConstraintLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/input_bar_height" android:layout_height="@dimen/input_bar_height"
android:background="@color/compose_view_background" android:background="@color/input_bar_background"
android:orientation="vertical"> android:orientation="vertical">
<View <View

View File

@ -1,114 +1,126 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<TextView
android:id="@+id/dateBreakTextView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="@color/text"
android:textSize="@dimen/very_small_font_size"
android:textStyle="bold"
android:gravity="center" />
<LinearLayout <LinearLayout
android:id="@+id/mainContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="vertical">
android:gravity="bottom">
<TextView
android:id="@+id/dateBreakTextView"
android:layout_width="match_parent"
android:layout_height="40dp"
android:textColor="@color/text"
android:textSize="@dimen/very_small_font_size"
android:textStyle="bold"
android:gravity="center" />
<LinearLayout <LinearLayout
android:id="@+id/profilePictureContainer" android:id="@+id/mainContainer"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal"> android:orientation="horizontal"
android:gravity="bottom">
<View <LinearLayout
android:layout_width="12dp" android:id="@+id/profilePictureContainer"
android:layout_height="0dp" />
<RelativeLayout
android:layout_width="26dp"
android:layout_height="32dp" >
<org.thoughtcrime.securesms.loki.views.ProfilePictureView
android:id="@+id/profilePictureView"
android:layout_width="@dimen/very_small_profile_picture_size"
android:layout_height="@dimen/very_small_profile_picture_size"
android:layout_marginTop="3dp" />
<ImageView
android:id="@+id/moderatorIconImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_crown"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<View
android:layout_width="12dp"
android:layout_height="0dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/messageContentContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/senderNameTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" android:orientation="horizontal">
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:textColor="@color/text"
android:textStyle="bold"
android:maxLines="1"
android:ellipsize="end" />
<org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageContentView <View
android:id="@+id/messageContentView" android:layout_width="12dp"
android:layout_height="0dp" />
<RelativeLayout
android:layout_width="26dp"
android:layout_height="32dp" >
<org.thoughtcrime.securesms.loki.views.ProfilePictureView
android:id="@+id/profilePictureView"
android:layout_width="@dimen/very_small_profile_picture_size"
android:layout_height="@dimen/very_small_profile_picture_size"
android:layout_marginTop="3dp" />
<ImageView
android:id="@+id/moderatorIconImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:src="@drawable/ic_crown"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true" />
</RelativeLayout>
<View
android:layout_width="12dp"
android:layout_height="0dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/messageContentContainer"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/messageTimestampTextView" android:id="@+id/senderNameTextView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_alignParentStart="true" android:layout_marginBottom="4dp"
android:layout_centerVertical="true" android:layout_marginStart="12dp"
android:layout_marginStart="2dp" android:layout_marginEnd="12dp"
android:textColor="@color/text"
android:textStyle="bold"
android:maxLines="1" android:maxLines="1"
android:textSize="10dp" /> android:ellipsize="end" />
<ImageView <org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageContentView
android:id="@+id/messageStatusImageView" android:id="@+id/messageContentView"
android:layout_width="16dp" android:layout_width="wrap_content"
android:layout_height="16dp" android:layout_height="wrap_content" />
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="2dp"
android:padding="2dp"
android:src="@drawable/ic_delivery_status_sent" />
</RelativeLayout> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/messageTimestampTextView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="2dp"
android:maxLines="1"
android:textSize="10dp" />
<ImageView
android:id="@+id/messageStatusImageView"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginEnd="2dp"
android:padding="2dp"
android:src="@drawable/ic_delivery_status_sent" />
</RelativeLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>
</LinearLayout> <org.thoughtcrime.securesms.conversation.v2.components.ExpirationTimerView
android:id="@+id/expirationTimerView"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginHorizontal="@dimen/medium_spacing"
android:layout_centerVertical="true" />
</RelativeLayout>