mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-25 09:17:44 +00:00
Add message status indicator
This commit is contained in:
parent
b8f6321262
commit
b2a66e9293
@ -12,10 +12,14 @@ import android.util.AttributeSet
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
|
import androidx.annotation.ColorRes
|
||||||
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.graphics.withClip
|
import androidx.core.graphics.withClip
|
||||||
import androidx.core.view.isVisible
|
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.*
|
||||||
|
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.utilities.ViewUtil
|
import org.session.libsession.utilities.ViewUtil
|
||||||
@ -113,6 +117,17 @@ class VisibleMessageView : LinearLayout {
|
|||||||
// Gravity
|
// Gravity
|
||||||
val gravity = if (message.isOutgoing) Gravity.RIGHT else Gravity.LEFT
|
val gravity = if (message.isOutgoing) Gravity.RIGHT else Gravity.LEFT
|
||||||
mainContainer.gravity = gravity or Gravity.BOTTOM
|
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
|
// Populate content view
|
||||||
messageContentView.bind(message, isStartOfMessageCluster, isEndOfMessageCluster, glide)
|
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() {
|
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))
|
||||||
|
@ -129,7 +129,17 @@ public class MmsSmsDatabase extends Database {
|
|||||||
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
String order = MmsSmsColumns.NORMALIZED_DATE_RECEIVED + " DESC";
|
||||||
String selection = MmsSmsColumns.THREAD_ID + " = " + threadId;
|
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() {
|
public Cursor getUnread() {
|
||||||
|
@ -63,33 +63,23 @@ public abstract class DisplayRecord {
|
|||||||
return body == null ? "" : body;
|
return body == null ? "" : body;
|
||||||
}
|
}
|
||||||
public abstract SpannableString getDisplayBody(@NonNull Context context);
|
public abstract SpannableString getDisplayBody(@NonNull Context context);
|
||||||
public Recipient getRecipient() {
|
public Recipient getRecipient() { return recipient; }
|
||||||
return recipient;
|
public long getDateSent() { return dateSent; }
|
||||||
}
|
public long getDateReceived() { return dateReceived; }
|
||||||
public long getDateSent() {
|
public long getThreadId() { return threadId; }
|
||||||
return dateSent;
|
public int getDeliveryStatus() { return deliveryStatus; }
|
||||||
}
|
public int getDeliveryReceiptCount() { return deliveryReceiptCount; }
|
||||||
public long getDateReceived() {
|
public int getReadReceiptCount() { return readReceiptCount; }
|
||||||
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() {
|
public boolean isDelivered() {
|
||||||
return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE
|
return (deliveryStatus >= SmsDatabase.Status.STATUS_COMPLETE
|
||||||
&& deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0;
|
&& deliveryStatus < SmsDatabase.Status.STATUS_PENDING) || deliveryReceiptCount > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSent() {
|
||||||
|
return !isFailed() && !isPending();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFailed() {
|
public boolean isFailed() {
|
||||||
return MmsSmsColumns.Types.isFailedMessageType(type)
|
return MmsSmsColumns.Types.isFailedMessageType(type)
|
||||||
|| MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type)
|
|| MmsSmsColumns.Types.isPendingSecureSmsFallbackType(type)
|
||||||
|
@ -58,6 +58,7 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
tools:text="http://117.204.71.34"
|
tools:text="http://117.204.71.34"
|
||||||
|
android:layout_marginTop="2dp"
|
||||||
android:textColor="@color/black"
|
android:textColor="@color/black"
|
||||||
android:maxLines="1"
|
android:maxLines="1"
|
||||||
android:ellipsize="end"
|
android:ellipsize="end"
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
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">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@ -77,12 +78,31 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content" />
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<TextView
|
<RelativeLayout
|
||||||
android:id="@+id/messageTimestampTextView"
|
android:layout_width="match_parent"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content">
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:maxLines="1"
|
<TextView
|
||||||
android:textSize="10dp" />
|
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>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user