take last seen into account during status indicator calculation

This commit is contained in:
kosyak 2024-09-02 01:08:27 +02:00
parent ffbdad7503
commit e3542ccf72
6 changed files with 20 additions and 12 deletions

View file

@ -523,7 +523,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
AvatarWorkerTask.loadAvatar(contact, binding.detailsContactBadge, R.dimen.avatar_on_details_screen_size);
binding.detailsContactBadge.setOnClickListener(this::onBadgeClick);
binding.presenceIndicator.setStatus(contact.getShownStatus());
binding.presenceIndicator.setStatus(contact);
binding.detailsContactKeys.removeAllViews();
boolean hasKeys = false;

View file

@ -393,7 +393,7 @@ public class ConversationAdapter
Contact contact = conversation.getContact();
if (contact != null) {
viewHolder.binding.presenceIndicator.setStatus(contact.getShownStatus());
viewHolder.binding.presenceIndicator.setStatus(contact);
} else {
viewHolder.binding.presenceIndicator.setStatus(null);
}

View file

@ -94,7 +94,7 @@ public class ListItemAdapter extends ArrayAdapter<ListItem> {
AvatarWorkerTask.loadAvatar(item, viewHolder.avatar, R.dimen.avatar);
if (item instanceof Contact) {
viewHolder.presenceIndicator.setStatus(((Contact) item).getShownStatus());
viewHolder.presenceIndicator.setStatus(((Contact) item));
} else {
viewHolder.presenceIndicator.setStatus(null);
}

View file

@ -91,7 +91,7 @@ public class UserAdapter extends ListAdapter<MucOptions.User, UserAdapter.ViewHo
} else {
viewHolder.binding.contactJid.setText(ConferenceDetailsActivity.getStatus(viewHolder.binding.getRoot().getContext(), user, advancedMode));
}
viewHolder.binding.presenceIndicator.setStatus(contact.getShownStatus());
viewHolder.binding.presenceIndicator.setStatus(contact);
} else {
viewHolder.binding.contactDisplayName.setText(name == null ? "" : name);
viewHolder.binding.contactJid.setText(ConferenceDetailsActivity.getStatus(viewHolder.binding.getRoot().getContext(), user, advancedMode));

View file

@ -38,7 +38,7 @@ public class UserPreviewAdapter extends ListAdapter<MucOptions.User, UserPreview
AvatarWorkerTask.loadAvatar(user, viewHolder.binding.avatar, R.dimen.media_size);
Contact contact = user.getContact();
if (contact != null) {
viewHolder.binding.presenceIndicator.setStatus(user.getContact().getShownStatus());
viewHolder.binding.presenceIndicator.setStatus(user.getContact());
} else {
viewHolder.binding.presenceIndicator.setStatus(null);
}

View file

@ -8,9 +8,11 @@ import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import android.view.ViewOutlineProvider
import eu.siacs.conversations.entities.Contact
import eu.siacs.conversations.entities.Presence
import eu.siacs.conversations.ui.util.StyledAttributes
import eu.siacs.conversations.utils.UIHelper
import eu.siacs.conversations.xml.Namespace
class PresenceIndicator : View {
private var paint: Paint = Paint().also {
@ -19,13 +21,7 @@ class PresenceIndicator : View {
it.strokeWidth = 1 * Resources.getSystem().displayMetrics.density
}
var status: Presence.Status? = null
set(value) {
if (field != value) {
field = value
invalidate()
}
}
private var status: Presence.Status? = null
constructor(context: Context?) : super(context)
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
@ -51,6 +47,18 @@ class PresenceIndicator : View {
}
}
fun setStatus(contact: Contact?) {
val status = contact?.shownStatus
if ((status == Presence.Status.ONLINE || status == Presence.Status.CHAT) &&
(contact.lastseen <= 0 || !contact.presences.allOrNonSupport(Namespace.IDLE) || ((System.currentTimeMillis() - contact.lastseen) / 1000) > 60)) {
this.status = null
} else {
this.status = status
}
invalidate()
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)