mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
add "seen recently" indicator
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="oval">
|
||||
|
||||
<solid android:color="@color/green" />
|
||||
|
||||
</shape>
|
||||
@@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<merge
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:parentTag="org.thoughtcrime.securesms.components.AvatarView">
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/avatar_image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:cropToPadding="true"
|
||||
tools:src="@color/blue_600"
|
||||
android:contentDescription="@null" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/status_indicator"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
|
||||
app:layout_constraintLeft_toLeftOf="@+id/left_guideline"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/top_guideline"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
||||
android:src="@drawable/ic_circle_status"
|
||||
android:contentDescription="@null"
|
||||
android:visibility="gone" />
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/left_guideline"
|
||||
app:layout_constraintGuide_percent=".69"
|
||||
android:orientation="vertical"/>
|
||||
|
||||
<androidx.constraintlayout.widget.Guideline
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/top_guideline"
|
||||
app:layout_constraintGuide_percent=".69"
|
||||
android:orientation="horizontal"/>
|
||||
|
||||
</merge>
|
||||
@@ -13,14 +13,10 @@
|
||||
android:paddingRight="24dp"
|
||||
android:paddingEnd="24dp">
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/contact_photo_image"
|
||||
<org.thoughtcrime.securesms.components.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="40dp"
|
||||
android:layout_height="40dp"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
android:cropToPadding="true"
|
||||
tools:src="@color/blue_600"
|
||||
android:contentDescription="@null" />
|
||||
android:layout_height="40dp" />
|
||||
|
||||
<LinearLayout android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -10,16 +10,13 @@
|
||||
android:nextFocusLeft="@+id/container"
|
||||
android:layout_height="72dp">
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/contact_photo_image"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
<org.thoughtcrime.securesms.components.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:cropToPadding="true"
|
||||
tools:src="@drawable/ic_contact_picture"
|
||||
android:importantForAccessibility="no"
|
||||
android:layout_marginLeft="12dp"
|
||||
android:layout_marginRight="12dp" />
|
||||
@@ -29,8 +26,8 @@
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_toRightOf="@id/contact_photo_image"
|
||||
android:layout_toEndOf="@id/contact_photo_image">
|
||||
android:layout_toRightOf="@id/avatar"
|
||||
android:layout_toEndOf="@id/avatar">
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
|
||||
@@ -25,9 +25,8 @@
|
||||
android:contentDescription="@string/back"
|
||||
android:visibility="visible"/>
|
||||
|
||||
<org.thoughtcrime.securesms.components.AvatarImageView
|
||||
android:id="@+id/contact_photo_image"
|
||||
android:foreground="@drawable/contact_photo_background"
|
||||
<org.thoughtcrime.securesms.components.AvatarView
|
||||
android:id="@+id/avatar"
|
||||
android:layout_width="46dp"
|
||||
android:layout_height="46dp"
|
||||
android:layout_toRightOf="@id/up_button"
|
||||
@@ -36,7 +35,6 @@
|
||||
android:cropToPadding="true"
|
||||
android:clickable="true"
|
||||
app:inverted="true"
|
||||
tools:src="@drawable/ic_contact_picture"
|
||||
android:contentDescription="@string/pref_profile_photo"/>
|
||||
|
||||
<LinearLayout
|
||||
@@ -47,8 +45,8 @@
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@id/contact_photo_image"
|
||||
android:layout_toRightOf="@id/contact_photo_image">
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
android:layout_toRightOf="@id/avatar">
|
||||
|
||||
<LinearLayout android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package com.b44t.messenger;
|
||||
|
||||
import org.thoughtcrime.securesms.util.DateUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class DcContact {
|
||||
|
||||
public final static int DC_CONTACT_ID_SELF = 1;
|
||||
@@ -46,6 +50,10 @@ public class DcContact {
|
||||
return getAddr();
|
||||
}
|
||||
|
||||
public boolean isSeenRecently() {
|
||||
return DateUtils.isWithin(getLastSeen(), 10, TimeUnit.MINUTES);
|
||||
}
|
||||
|
||||
public native int getId ();
|
||||
public native String getName ();
|
||||
public native String getDisplayName ();
|
||||
|
||||
@@ -268,6 +268,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_CHAT_EPHEMERAL_TIMER_MODIFIED, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_CONTACTS_CHANGED, this);
|
||||
|
||||
if (!isMultiUser()) {
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_INCOMING_MSG, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_MSG_DELIVERED, this);
|
||||
eventCenter.addObserver(DcContext.DC_EVENT_MSG_READ, this);
|
||||
}
|
||||
|
||||
if (isForwarding(this)) {
|
||||
handleForwarding();
|
||||
} else if (isSharing(this)) {
|
||||
@@ -1569,6 +1575,11 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
initializeSecurity(isSecureText, isDefaultSms);
|
||||
setComposePanelVisibility();
|
||||
initializeContactRequest();
|
||||
} else if ((eventId == DcContext.DC_EVENT_INCOMING_MSG
|
||||
|| eventId == DcContext.DC_EVENT_MSG_READ
|
||||
|| eventId == DcContext.DC_EVENT_MSG_DELIVERED)
|
||||
&& event.getData1Int() == chatId) {
|
||||
titleView.updateStatus(dcContext, chatId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ import com.b44t.messenger.DcContext;
|
||||
import com.b44t.messenger.DcLot;
|
||||
import com.b44t.messenger.DcMsg;
|
||||
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.AvatarView;
|
||||
import org.thoughtcrime.securesms.components.DeliveryStatusView;
|
||||
import org.thoughtcrime.securesms.components.FromTextView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
@@ -80,7 +80,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
private DeliveryStatusView deliveryStatusIndicator;
|
||||
private ImageView unreadIndicator;
|
||||
|
||||
private AvatarImageView contactPhotoImage;
|
||||
private AvatarView avatar;
|
||||
|
||||
public ConversationListItem(Context context) {
|
||||
this(context, null);
|
||||
@@ -97,7 +97,7 @@ public class ConversationListItem extends RelativeLayout
|
||||
this.fromView = findViewById(R.id.from_text);
|
||||
this.dateView = findViewById(R.id.date);
|
||||
this.deliveryStatusIndicator = new DeliveryStatusView(findViewById(R.id.delivery_indicator));
|
||||
this.contactPhotoImage = findViewById(R.id.contact_photo_image);
|
||||
this.avatar = findViewById(R.id.avatar);
|
||||
this.archivedBadgeView = findViewById(R.id.archived_badge);
|
||||
this.requestBadgeView = findViewById(R.id.request_badge);
|
||||
this.unreadIndicator = findViewById(R.id.unread_indicator);
|
||||
@@ -165,7 +165,16 @@ public class ConversationListItem extends RelativeLayout
|
||||
setBatchState(batchMode);
|
||||
setBgColor(thread);
|
||||
|
||||
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
this.avatar.setAvatar(glideRequests, recipient, false);
|
||||
|
||||
if (recipient.isMultiUserRecipient()) {
|
||||
avatar.setSeenRecently(false);
|
||||
} else {
|
||||
DcContext dcContext = DcHelper.getContext(getContext());
|
||||
int[] members = dcContext.getChatContacts((int)chatId);
|
||||
DcContact contact = dcContext.getContact(members.length>=1? members[0] : 0);
|
||||
avatar.setSeenRecently(contact.isSeenRecently());
|
||||
}
|
||||
|
||||
fromView.setCompoundDrawablesWithIntrinsicBounds(
|
||||
thread.isMuted()? R.drawable.ic_volume_off_grey600_18dp : 0,
|
||||
@@ -194,7 +203,8 @@ public class ConversationListItem extends RelativeLayout
|
||||
deliveryStatusIndicator.setNone();
|
||||
|
||||
setBatchState(false);
|
||||
contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
avatar.setAvatar(glideRequests, recipient, false);
|
||||
avatar.setSeenRecently(contact.isSeenRecently());
|
||||
}
|
||||
|
||||
public void bind(@NonNull DcMsg messageResult,
|
||||
@@ -226,7 +236,8 @@ public class ConversationListItem extends RelativeLayout
|
||||
deliveryStatusIndicator.setNone();
|
||||
|
||||
setBatchState(false);
|
||||
contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
avatar.setAvatar(glideRequests, recipient, false);
|
||||
avatar.setSeenRecently(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,7 +15,7 @@ import com.b44t.messenger.DcChat;
|
||||
import com.b44t.messenger.DcContact;
|
||||
import com.b44t.messenger.DcContext;
|
||||
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.AvatarView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
@@ -28,7 +28,7 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
|
||||
private View content;
|
||||
private ImageView back;
|
||||
private AvatarImageView avatar;
|
||||
private AvatarView avatar;
|
||||
private TextView title;
|
||||
private TextView subtitle;
|
||||
private ImageView ephemeralIcon;
|
||||
@@ -50,7 +50,7 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
this.content = ViewUtil.findById(this, R.id.content);
|
||||
this.title = ViewUtil.findById(this, R.id.title);
|
||||
this.subtitle = ViewUtil.findById(this, R.id.subtitle);
|
||||
this.avatar = ViewUtil.findById(this, R.id.contact_photo_image);
|
||||
this.avatar = ViewUtil.findById(this, R.id.avatar);
|
||||
this.ephemeralIcon = ViewUtil.findById(this, R.id.ephemeral_icon);
|
||||
|
||||
ViewUtil.setTextViewGravityStart(this.title, getContext());
|
||||
@@ -81,6 +81,7 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
imgRight = R.drawable.ic_verified;
|
||||
}
|
||||
|
||||
boolean isOnline = false;
|
||||
int[] chatContacts = dcContext.getChatContacts(chatId);
|
||||
if (dcChat.isMailingList()) {
|
||||
if (profileView) {
|
||||
@@ -109,12 +110,14 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
if (dcContact.isVerified()) {
|
||||
imgRight = R.drawable.ic_verified;
|
||||
}
|
||||
isOnline = dcContact.isSeenRecently();
|
||||
}
|
||||
}
|
||||
|
||||
subtitle.setText(subtitleStr);
|
||||
|
||||
avatar.setAvatar(glideRequests, new Recipient(getContext(), dcChat), false);
|
||||
avatar.setSeenRecently(isOnline);
|
||||
title.setCompoundDrawablesWithIntrinsicBounds(imgLeft, 0, imgRight, 0);
|
||||
if (!TextUtils.isEmpty(subtitleStr)) {
|
||||
subtitle.setText(subtitleStr);
|
||||
@@ -130,12 +133,24 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
// the verified state is _not_ shown in the title. this will be confusing as in the one-to-one-ChatViews, the verified
|
||||
// icon is also not shown as these chats are always opportunistic chats
|
||||
avatar.setAvatar(glideRequests, new Recipient(getContext(), contact), false);
|
||||
avatar.setSeenRecently(contact.isSeenRecently());
|
||||
title.setText(contact.getDisplayName());
|
||||
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
|
||||
subtitle.setText(contact.getAddr());
|
||||
subtitle.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
public void updateStatus(DcContext dcContext, int chatId) {
|
||||
boolean isOnline = false;
|
||||
if(!dcContext.getChat(chatId).isMultiUser()) {
|
||||
int[] members = dcContext.getChatContacts(chatId);
|
||||
if(members.length>=1) {
|
||||
isOnline = dcContext.getContact(members[0]).isSeenRecently();
|
||||
}
|
||||
}
|
||||
avatar.setSeenRecently(isOnline);
|
||||
}
|
||||
|
||||
public void hideAvatar() {
|
||||
avatar.setVisibility(View.GONE);
|
||||
}
|
||||
@@ -143,13 +158,13 @@ public class ConversationTitleView extends RelativeLayout {
|
||||
@Override
|
||||
public void setOnClickListener(@Nullable OnClickListener listener) {
|
||||
this.content.setOnClickListener(listener);
|
||||
this.avatar.setOnClickListener(listener);
|
||||
this.avatar.setAvatarClickListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnLongClickListener(@Nullable OnLongClickListener listener) {
|
||||
this.content.setOnLongClickListener(listener);
|
||||
this.avatar.setOnLongClickListener(listener);
|
||||
this.avatar.setAvatarLongClickListener(listener);
|
||||
}
|
||||
|
||||
public void setOnBackClickedListener(@Nullable OnClickListener listener) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
|
||||
public class AvatarView extends ConstraintLayout {
|
||||
|
||||
private AvatarImageView avatarImage;
|
||||
private ImageView seenRecentlyIndicator;
|
||||
|
||||
public AvatarView(Context context) {
|
||||
super(context);
|
||||
init();
|
||||
}
|
||||
|
||||
public AvatarView(Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
init();
|
||||
}
|
||||
|
||||
public AvatarView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
inflate(getContext(), R.layout.avatar_view, this);
|
||||
|
||||
avatarImage = findViewById(R.id.avatar_image);
|
||||
seenRecentlyIndicator = findViewById(R.id.status_indicator);
|
||||
}
|
||||
|
||||
public void setAvatar(@NonNull GlideRequests requestManager, @Nullable Recipient recipient, boolean quickContactEnabled) {
|
||||
avatarImage.setAvatar(requestManager, recipient, quickContactEnabled);
|
||||
}
|
||||
|
||||
public void setAvatarClickListener(OnClickListener listener) {
|
||||
avatarImage.setOnClickListener(listener);
|
||||
}
|
||||
|
||||
public void setAvatarLongClickListener(OnLongClickListener listener) {
|
||||
avatarImage.setOnLongClickListener(listener);
|
||||
}
|
||||
|
||||
public void setSeenRecently(boolean enabled) {
|
||||
seenRecentlyIndicator.setVisibility(enabled? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
public void clear(@NonNull GlideRequests glideRequests) {
|
||||
avatarImage.clear(glideRequests);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,7 +11,7 @@ import android.widget.TextView;
|
||||
import com.b44t.messenger.DcContact;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.AvatarView;
|
||||
import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.mms.GlideRequests;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
@@ -24,7 +24,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = ContactSelectionListItem.class.getSimpleName();
|
||||
|
||||
private AvatarImageView contactPhotoImage;
|
||||
private AvatarView avatar;
|
||||
private View numberContainer;
|
||||
private TextView numberView;
|
||||
private TextView nameView;
|
||||
@@ -48,7 +48,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
@Override
|
||||
protected void onFinishInflate() {
|
||||
super.onFinishInflate();
|
||||
this.contactPhotoImage = findViewById(R.id.contact_photo_image);
|
||||
this.avatar = findViewById(R.id.avatar);
|
||||
this.numberContainer = findViewById(R.id.number_container);
|
||||
this.numberView = findViewById(R.id.number);
|
||||
this.labelView = findViewById(R.id.label);
|
||||
@@ -76,7 +76,8 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
name = this.recipient.getName();
|
||||
}
|
||||
}
|
||||
this.contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
this.avatar.setAvatar(glideRequests, recipient, false);
|
||||
this.avatar.setSeenRecently(contact!=null? contact.isSeenRecently() : false);
|
||||
|
||||
setText(name, number, label, contact);
|
||||
setEnabled(enabled);
|
||||
@@ -95,7 +96,7 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
recipient = null;
|
||||
}
|
||||
|
||||
contactPhotoImage.clear(glideRequests);
|
||||
avatar.clear(glideRequests);
|
||||
}
|
||||
|
||||
private void setText(String name, String number, String label, DcContact contact) {
|
||||
@@ -141,7 +142,9 @@ public class ContactSelectionListItem extends LinearLayout implements RecipientM
|
||||
public void onModified(final Recipient recipient) {
|
||||
if (this.recipient == recipient) {
|
||||
Util.runOnMain(() -> {
|
||||
contactPhotoImage.setAvatar(glideRequests, recipient, false);
|
||||
avatar.setAvatar(glideRequests, recipient, false);
|
||||
DcContact contact = recipient.getDcContact();
|
||||
avatar.setSeenRecently(contact!=null? contact.isSeenRecently() : false);
|
||||
nameView.setText(recipient.toShortString());
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ public class DateUtils extends android.text.format.DateUtils {
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = DateUtils.class.getSimpleName();
|
||||
|
||||
private static boolean isWithin(final long millis, final long span, final TimeUnit unit) {
|
||||
public static boolean isWithin(final long millis, final long span, final TimeUnit unit) {
|
||||
return System.currentTimeMillis() - millis <= unit.toMillis(span);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user