aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2017-02-22 19:38:59 +0100
committerChristian Schneppe <christian@pix-art.de>2017-02-22 20:49:03 +0100
commitb7f933051498df20772ba4a00f05feb1972343a6 (patch)
tree86b9048a944317adfa2f23abc9bd2f7e84132dd5 /src/main/java/de/pixart
parent35538440cfbcdf8aeb208d3dfd981a514dda1d98 (diff)
add resource to ContactDetails
Diffstat (limited to '')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Contact.java4
-rw-r--r--src/main/java/de/pixart/messenger/entities/Presences.java19
-rw-r--r--src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java10
3 files changed, 33 insertions, 0 deletions
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<Map.Entry<String, Presence>> it = presences.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<String, Presence> entry = it.next();
+ if (entry.getValue().equals(p)) {
+ return entry.getKey();
+ }
+ }
+ return "";
+ }
+ }
+
public int size() {
synchronized (this.presences) {
return presences.size();
diff --git a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
index cdc1ba336..d028078c4 100644
--- a/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ContactDetailsActivity.java
@@ -115,6 +115,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
private TextView contactJidTv;
private TextView accountJidTv;
private TextView statusMessage;
+ private TextView resource;
private CheckBox send;
private CheckBox receive;
private Button addContactButton;
@@ -275,6 +276,7 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
accountJidTv = (TextView) findViewById(R.id.details_account);
lastseen = (TextView) findViewById(R.id.details_lastseen);
statusMessage = (TextView) findViewById(R.id.status_message);
+ resource = (TextView) findViewById(R.id.resource);
send = (CheckBox) findViewById(R.id.details_send_presence);
receive = (CheckBox) findViewById(R.id.details_receive_presence);
badge = (QuickContactBadge) findViewById(R.id.details_contact_badge);
@@ -458,6 +460,14 @@ public class ContactDetailsActivity extends OmemoActivity implements OnAccountUp
statusMessage.setText(builder);
}
+ String resources = contact.getPresences().getMostAvailableResource();
+ if (resources.length() == 0) {
+ resource.setVisibility(View.GONE);
+ } else {
+ statusMessage.setVisibility(View.VISIBLE);
+ statusMessage.setText(resources);
+ }
+
if (contact.getOption(Contact.Options.FROM)) {
send.setText(R.string.send_presence_updates);
send.setChecked(true);