From a73ce32e272675d899b5029b63233b4e5ef616c9 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Tue, 26 May 2015 22:28:31 +0200 Subject: Status color added to "create conversation" (refers to ticket #22 in flyspray) --- .../java/eu/siacs/conversations/entities/Bookmark.java | 7 +++++++ src/main/java/eu/siacs/conversations/entities/Contact.java | 6 ++++++ .../java/eu/siacs/conversations/entities/ListItem.java | 2 ++ .../eu/siacs/conversations/ui/adapter/ListItemAdapter.java | 4 ++++ src/main/java/eu/siacs/conversations/utils/UIHelper.java | 14 ++++++++++++++ src/main/res/layout/contact.xml | 11 +++++++++-- 6 files changed, 42 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/eu/siacs/conversations/entities/Bookmark.java b/src/main/java/eu/siacs/conversations/entities/Bookmark.java index f81f1a87..cc3d3424 100644 --- a/src/main/java/eu/siacs/conversations/entities/Bookmark.java +++ b/src/main/java/eu/siacs/conversations/entities/Bookmark.java @@ -1,5 +1,7 @@ package eu.siacs.conversations.entities; +import android.graphics.Color; + import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -74,6 +76,11 @@ public class Bookmark extends Element implements ListItem { return tags; } + @Override + public int getStatusColor() { + return Color.parseColor("#259B23"); + } + public String getNick() { Element nick = this.findChild("nick"); if (nick != null) { diff --git a/src/main/java/eu/siacs/conversations/entities/Contact.java b/src/main/java/eu/siacs/conversations/entities/Contact.java index cef03ebe..26145d82 100644 --- a/src/main/java/eu/siacs/conversations/entities/Contact.java +++ b/src/main/java/eu/siacs/conversations/entities/Contact.java @@ -2,6 +2,7 @@ package eu.siacs.conversations.entities; import android.content.ContentValues; import android.database.Cursor; +import android.graphics.Color; import org.json.JSONArray; import org.json.JSONException; @@ -147,6 +148,11 @@ public class Contact implements ListItem, Blockable { return tags; } + @Override + public int getStatusColor() { + return Color.parseColor(UIHelper.getStatusColor(getMostAvailableStatus())); + } + public boolean match(String needle) { if (needle == null || needle.isEmpty()) { return true; diff --git a/src/main/java/eu/siacs/conversations/entities/ListItem.java b/src/main/java/eu/siacs/conversations/entities/ListItem.java index efc1c2b9..aba2aef2 100644 --- a/src/main/java/eu/siacs/conversations/entities/ListItem.java +++ b/src/main/java/eu/siacs/conversations/entities/ListItem.java @@ -11,6 +11,8 @@ public interface ListItem extends Comparable { public List getTags(); + public int getStatusColor(); + public final class Tag { private final String name; private final int color; diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java index 7b20b55f..5bc67b8b 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/ListItemAdapter.java @@ -57,6 +57,10 @@ public class ListItemAdapter extends ArrayAdapter { if (view == null) { view = inflater.inflate(R.layout.contact, parent, false); } + + TextView tvStatus = (TextView) view.findViewById(R.id.contact_status); + tvStatus.setBackgroundColor(item.getStatusColor()); + TextView tvName = (TextView) view.findViewById(R.id.contact_display_name); TextView tvJid = (TextView) view.findViewById(R.id.contact_jid); ImageView picture = (ImageView) view.findViewById(R.id.contact_photo); diff --git a/src/main/java/eu/siacs/conversations/utils/UIHelper.java b/src/main/java/eu/siacs/conversations/utils/UIHelper.java index 0bea6e53..82e950ad 100644 --- a/src/main/java/eu/siacs/conversations/utils/UIHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/UIHelper.java @@ -357,6 +357,20 @@ public class UIHelper { } } + public static String getStatusColor(int status) { + switch (status) { + case Presences.ONLINE: + case Presences.CHAT: + return "#259B23"; + case Presences.AWAY: + case Presences.XA: + return "#FF9800"; + case Presences.DND: + return "#E51C23"; + } + return "#CCCCCC"; + } + private static String getDisplayedMucCounterpart(final Jid counterpart) { if (counterpart==null) { return ""; diff --git a/src/main/res/layout/contact.xml b/src/main/res/layout/contact.xml index 69545c25..f0ef5d94 100644 --- a/src/main/res/layout/contact.xml +++ b/src/main/res/layout/contact.xml @@ -11,8 +11,15 @@ android:layout_height="48dp" android:layout_alignParentLeft="true" android:scaleType="centerCrop" - android:src="@drawable/ic_profile" > - + android:src="@drawable/ic_profile" /> +