From b7f933051498df20772ba4a00f05feb1972343a6 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Wed, 22 Feb 2017 19:38:59 +0100 Subject: add resource to ContactDetails --- .../java/de/pixart/messenger/entities/Contact.java | 4 ++++ .../java/de/pixart/messenger/entities/Presences.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) (limited to 'src/main/java/de/pixart/messenger/entities') diff --git a/src/main/java/de/pixart/messenger/entities/Contact.java b/src/main/java/de/pixart/messenger/entities/Contact.java index 1e55526ce..7da8d423e 100644 --- a/src/main/java/de/pixart/messenger/entities/Contact.java +++ b/src/main/java/de/pixart/messenger/entities/Contact.java @@ -239,6 +239,10 @@ public class Contact implements ListItem, Blockable { return this.presences.getShownStatus(); } + public String getMostAvailableResource() { + return this.presences.getMostAvailableResource(); + } + public boolean setPhotoUri(String uri) { if (uri != null && !uri.equals(this.photoUri)) { this.photoUri = uri; diff --git a/src/main/java/de/pixart/messenger/entities/Presences.java b/src/main/java/de/pixart/messenger/entities/Presences.java index 6afd973fc..1565cfe12 100644 --- a/src/main/java/de/pixart/messenger/entities/Presences.java +++ b/src/main/java/de/pixart/messenger/entities/Presences.java @@ -3,8 +3,10 @@ package de.pixart.messenger.entities; import android.util.Pair; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; +import java.util.Iterator; import java.util.List; import java.util.Map; @@ -47,6 +49,23 @@ public class Presences { return status; } + public String getMostAvailableResource() { + synchronized (this.presences) { + if (presences.size() < 1) { + return ""; + } + Presence p = Collections.min(presences.values()); + Iterator> it = presences.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry entry = it.next(); + if (entry.getValue().equals(p)) { + return entry.getKey(); + } + } + return ""; + } + } + public int size() { synchronized (this.presences) { return presences.size(); -- cgit v1.2.3