From 6031af86062757f86701e08962aa86121877fbf4 Mon Sep 17 00:00:00 2001 From: iNPUTmice Date: Mon, 14 Jul 2014 17:13:59 +0200 Subject: use proper picture on bookmarked conferences when joined. use bookmark title when no subject is set --- src/eu/siacs/conversations/entities/Bookmark.java | 40 ++++++++++++++++------ src/eu/siacs/conversations/entities/Contact.java | 8 +++++ .../siacs/conversations/entities/Conversation.java | 9 +++++ src/eu/siacs/conversations/entities/ListItem.java | 5 ++- .../services/XmppConnectionService.java | 14 ++++---- .../siacs/conversations/ui/StartConversation.java | 4 +-- src/eu/siacs/conversations/utils/UIHelper.java | 2 +- 7 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/eu/siacs/conversations/entities/Bookmark.java b/src/eu/siacs/conversations/entities/Bookmark.java index 1b97c573..6c1d7258 100644 --- a/src/eu/siacs/conversations/entities/Bookmark.java +++ b/src/eu/siacs/conversations/entities/Bookmark.java @@ -2,6 +2,9 @@ package eu.siacs.conversations.entities; import java.util.Locale; +import android.content.Context; +import android.graphics.Bitmap; +import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; public class Bookmark implements ListItem { @@ -9,8 +12,9 @@ public class Bookmark implements ListItem { private Account account; private String jid; private String nick; - private String displayName; + private String name; private boolean autojoin; + private Conversation mJoinedConversation; public Bookmark(Account account) { this.account = account; @@ -19,7 +23,7 @@ public class Bookmark implements ListItem { public static Bookmark parse(Element element, Account account) { Bookmark bookmark = new Bookmark(account); bookmark.setJid(element.getAttribute("jid")); - bookmark.setDisplayName(element.getAttribute("name")); + bookmark.setName(element.getAttribute("name")); String autojoin = element.getAttribute("autojoin"); if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) { bookmark.setAutojoin(true); @@ -37,8 +41,8 @@ public class Bookmark implements ListItem { this.autojoin = autojoin; } - public void setDisplayName(String name) { - this.displayName = name; + public void setName(String name) { + this.name = name; } public void setJid(String jid) { @@ -56,8 +60,10 @@ public class Bookmark implements ListItem { @Override public String getDisplayName() { - if (displayName!=null) { - return displayName; + if (this.mJoinedConversation!=null) { + return this.mJoinedConversation.getName(true); + } else if (name!=null) { + return name; } else { return this.jid.split("@")[0]; } @@ -76,11 +82,6 @@ public class Bookmark implements ListItem { return autojoin; } - @Override - public String getProfilePhoto() { - return null; - } - public boolean match(String needle) { return needle == null || getJid().contains(needle.toLowerCase(Locale.US)) @@ -91,4 +92,21 @@ public class Bookmark implements ListItem { public Account getAccount() { return this.account; } + + @Override + public Bitmap getImage(int dpSize, Context context) { + if (this.mJoinedConversation==null) { + return UIHelper.getContactPicture(getDisplayName(), dpSize, context, false); + } else { + return UIHelper.getContactPicture(this.mJoinedConversation, dpSize, context, false); + } + } + + public void setConversation(Conversation conversation) { + this.mJoinedConversation = conversation; + } + + public String getName() { + return name; + } } diff --git a/src/eu/siacs/conversations/entities/Contact.java b/src/eu/siacs/conversations/entities/Contact.java index fc990274..8f8e38a5 100644 --- a/src/eu/siacs/conversations/entities/Contact.java +++ b/src/eu/siacs/conversations/entities/Contact.java @@ -8,9 +8,12 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; +import eu.siacs.conversations.utils.UIHelper; import eu.siacs.conversations.xml.Element; import android.content.ContentValues; +import android.content.Context; import android.database.Cursor; +import android.graphics.Bitmap; public class Contact implements ListItem { public static final String TABLENAME = "contacts"; @@ -311,4 +314,9 @@ public class Contact implements ListItem { return null; } } + + @Override + public Bitmap getImage(int dpSize, Context context) { + return UIHelper.getContactPicture(this, dpSize, context, false); + } } diff --git a/src/eu/siacs/conversations/entities/Conversation.java b/src/eu/siacs/conversations/entities/Conversation.java index fbd87f3f..8e2c1784 100644 --- a/src/eu/siacs/conversations/entities/Conversation.java +++ b/src/eu/siacs/conversations/entities/Conversation.java @@ -144,6 +144,8 @@ public class Conversation extends AbstractEntity { if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) && useSubject) { return getMucOptions().getSubject(); + } else if (getMode() == MODE_MULTI && bookmark!=null && bookmark.getName() != null) { + return bookmark.getName(); } else { return this.getContact().getDisplayName(); } @@ -380,5 +382,12 @@ public class Conversation extends AbstractEntity { public void setBookmark(Bookmark bookmark) { this.bookmark = bookmark; + this.bookmark.setConversation(this); + } + + public void deregisterWithBookmark() { + if (this.bookmark != null) { + this.bookmark.setConversation(null); + } } } diff --git a/src/eu/siacs/conversations/entities/ListItem.java b/src/eu/siacs/conversations/entities/ListItem.java index ba47dff2..c89c85d9 100644 --- a/src/eu/siacs/conversations/entities/ListItem.java +++ b/src/eu/siacs/conversations/entities/ListItem.java @@ -1,7 +1,10 @@ package eu.siacs.conversations.entities; +import android.content.Context; +import android.graphics.Bitmap; + public interface ListItem extends Comparable { public String getDisplayName(); public String getJid(); - public String getProfilePhoto(); + public Bitmap getImage(int dpSize, Context context); } diff --git a/src/eu/siacs/conversations/services/XmppConnectionService.java b/src/eu/siacs/conversations/services/XmppConnectionService.java index 3fa263ab..aa62b8a1 100644 --- a/src/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/eu/siacs/conversations/services/XmppConnectionService.java @@ -684,14 +684,11 @@ public class XmppConnectionService extends Service { Log.d(LOGTAG,item.toString()); Bookmark bookmark = Bookmark.parse(item,account); bookmarks.add(bookmark); - if (bookmark.autojoin()) { - Log.d(LOGTAG,"has autojoin"); - Conversation conversation = findMuc(bookmark); - if (conversation!=null) { - Log.d(LOGTAG,"conversation existed. adding bookmark"); - conversation.setBookmark(bookmark); - } else { - Log.d(LOGTAG,"creating new conversation"); + Conversation conversation = findMuc(bookmark); + if (conversation!=null) { + conversation.setBookmark(bookmark); + } else { + if (bookmark.autojoin()) { conversation = findOrCreateConversation(account, bookmark.getJid(), true); conversation.setBookmark(bookmark); } @@ -1011,6 +1008,7 @@ public class XmppConnectionService extends Service { Log.d(LOGTAG, "send leaving muc " + packet); sendPresencePacket(conversation.getAccount(),packet); conversation.getMucOptions().setOffline(); + conversation.deregisterWithBookmark(); } public void disconnect(Account account, boolean force) { diff --git a/src/eu/siacs/conversations/ui/StartConversation.java b/src/eu/siacs/conversations/ui/StartConversation.java index 99b3385c..e1186858 100644 --- a/src/eu/siacs/conversations/ui/StartConversation.java +++ b/src/eu/siacs/conversations/ui/StartConversation.java @@ -221,6 +221,7 @@ public class StartConversation extends XmppActivity { protected void openConversationForBookmark(int position) { Bookmark bookmark = (Bookmark) conferences.get(position); Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), bookmark.getJid(), true); + conversation.setBookmark(bookmark); switchToConversation(conversation); } @@ -445,8 +446,7 @@ public class StartConversation extends XmppActivity { jid.setText(item.getJid()); name.setText(item.getDisplayName()); - picture.setImageBitmap(UIHelper.getContactPicture(item, 48, - this.getContext(), false)); + picture.setImageBitmap(item.getImage(48, getApplicationContext())); return view; } diff --git a/src/eu/siacs/conversations/utils/UIHelper.java b/src/eu/siacs/conversations/utils/UIHelper.java index 8ee7448d..ede43830 100644 --- a/src/eu/siacs/conversations/utils/UIHelper.java +++ b/src/eu/siacs/conversations/utils/UIHelper.java @@ -238,7 +238,7 @@ public class UIHelper { } } - public static Bitmap getContactPicture(ListItem contact, int dpSize, + public static Bitmap getContactPicture(Contact contact, int dpSize, Context context, boolean notification) { String uri = contact.getProfilePhoto(); if (uri == null) { -- cgit v1.2.3