mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-13 11:22:22 +00:00
Add message status indicator
This commit is contained in:
@@ -12,10 +12,14 @@ import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.widget.LinearLayout
|
||||
import androidx.annotation.ColorRes
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.withClip
|
||||
import androidx.core.view.isVisible
|
||||
import kotlinx.android.synthetic.main.view_conversation.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 org.session.libsession.messaging.contacts.Contact.ContactContext
|
||||
import org.session.libsession.utilities.ViewUtil
|
||||
@@ -113,6 +117,17 @@ class VisibleMessageView : LinearLayout {
|
||||
// Gravity
|
||||
val gravity = if (message.isOutgoing) Gravity.RIGHT else Gravity.LEFT
|
||||
mainContainer.gravity = gravity or Gravity.BOTTOM
|
||||
// Message status indicator
|
||||
val iconID = getMessageStatusImage(message)
|
||||
if (iconID != null) {
|
||||
messageStatusImageView.setImageResource(iconID)
|
||||
}
|
||||
if (message.isOutgoing) {
|
||||
val lastMessageID = DatabaseFactory.getMmsSmsDatabase(context).getLastMessageID(message.threadId)
|
||||
messageStatusImageView.isVisible = !message.isSent || message.id == lastMessageID
|
||||
} else {
|
||||
messageStatusImageView.isVisible = false
|
||||
}
|
||||
// Populate content view
|
||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide)
|
||||
}
|
||||
@@ -144,6 +159,16 @@ class VisibleMessageView : LinearLayout {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getMessageStatusImage(message: MessageRecord): Int? {
|
||||
when {
|
||||
!message.isOutgoing -> return null
|
||||
message.isFailed -> return R.drawable.ic_error
|
||||
message.isPending -> return R.drawable.ic_circle_dot_dot_dot
|
||||
message.isRead -> return R.drawable.ic_filled_circle_check
|
||||
else -> return R.drawable.ic_circle_check
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleIsSelectedChanged() {
|
||||
background = if (snIsSelected) {
|
||||
ColorDrawable(context.resources.getColorWithID(R.color.message_selected, context.theme))
|
||||
|
||||
@@ -129,7 +129,17 @@ public class MmsSmsDatabase extends Database {
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
||||
|
||||
return queryTables(PROJECTION, selection, order, "1");
|
||||
return queryTables(PROJECTION, selection, order, "1");
|
||||
}
|
||||
|
||||
public long getLastMessageID(long threadId) {
|
||||
String order = MmsSmsColumns.NORMALIZED_DATE_SENT + " DESC";
|
||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
||||
|
||||
try (Cursor cursor = queryTables(PROJECTION, selection, order, "1")) {
|
||||
cursor.moveToFirst();
|
||||
return cursor.getLong(cursor.getColumnIndex(MmsSmsColumns.ID));
|
||||
}
|
||||
}
|
||||
|
||||
public Cursor getUnread() {
|
||||
|
||||
@@ -63,33 +63,23 @@ public abstract class DisplayRecord {
|
||||
return body == null ? "" : body;
|
||||
}
|
||||
public abstract SpannableString getDisplayBody(@NonNull Context context);
|
||||
public Recipient getRecipient() {
|
||||
return recipient;
|
||||
}
|
||||
public long getDateSent() {
|
||||
return dateSent;
|
||||
}
|
||||
public long getDateReceived() {
|
||||
return dateReceived;
|
||||
}
|
||||
public long getThreadId() {
|
||||
return threadId;
|
||||
}
|
||||
public int getDeliveryStatus() {
|
||||
return deliveryStatus;
|
||||
}
|
||||
public int getDeliveryReceiptCount() {
|
||||
return deliveryReceiptCount;
|
||||
}
|
||||
public int getReadReceiptCount() {
|
||||
return readReceiptCount;
|
||||
}
|
||||
public Recipient getRecipient() { return recipient; }
|
||||
public long getDateSent() { return dateSent; }
|
||||
public long getDateReceived() { return dateReceived; }
|
||||
public long getThreadId() { return threadId; }
|
||||
public int getDeliveryStatus() { return deliveryStatus; }
|
||||
public int getDeliveryReceiptCount() { return deliveryReceiptCount; }
|
||||
public int getReadReceiptCount() { return readReceiptCount; }
|
||||
|
||||
public boolean isDelivered() {
|
||||
return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE
|
||||
&& deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0;
|
||||
}
|
||||
|
||||
public boolean isSent() {
|
||||
return !isFailed() && !isPending();
|
||||
}
|
||||
|
||||
public boolean isFailed() {
|
||||
return MmsSmsColumns.Types.isFailedMessageType(type)
|
||||
|| MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type)
|
||||
|
||||
Reference in New Issue
Block a user