use proper picture on bookmarked conferences when joined. use bookmark title when no subject is set

This commit is contained in:
iNPUTmice 2014-07-14 17:13:59 +02:00
parent 3fa3d5f02b
commit 6031af8606
7 changed files with 59 additions and 23 deletions

View file

@ -2,6 +2,9 @@ package eu.siacs.conversations.entities;
import java.util.Locale; import java.util.Locale;
import android.content.Context;
import android.graphics.Bitmap;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
public class Bookmark implements ListItem { public class Bookmark implements ListItem {
@ -9,8 +12,9 @@ public class Bookmark implements ListItem {
private Account account; private Account account;
private String jid; private String jid;
private String nick; private String nick;
private String displayName; private String name;
private boolean autojoin; private boolean autojoin;
private Conversation mJoinedConversation;
public Bookmark(Account account) { public Bookmark(Account account) {
this.account = account; this.account = account;
@ -19,7 +23,7 @@ public class Bookmark implements ListItem {
public static Bookmark parse(Element element, Account account) { public static Bookmark parse(Element element, Account account) {
Bookmark bookmark = new Bookmark(account); Bookmark bookmark = new Bookmark(account);
bookmark.setJid(element.getAttribute("jid")); bookmark.setJid(element.getAttribute("jid"));
bookmark.setDisplayName(element.getAttribute("name")); bookmark.setName(element.getAttribute("name"));
String autojoin = element.getAttribute("autojoin"); String autojoin = element.getAttribute("autojoin");
if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) { if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) {
bookmark.setAutojoin(true); bookmark.setAutojoin(true);
@ -37,8 +41,8 @@ public class Bookmark implements ListItem {
this.autojoin = autojoin; this.autojoin = autojoin;
} }
public void setDisplayName(String name) { public void setName(String name) {
this.displayName = name; this.name = name;
} }
public void setJid(String jid) { public void setJid(String jid) {
@ -56,8 +60,10 @@ public class Bookmark implements ListItem {
@Override @Override
public String getDisplayName() { public String getDisplayName() {
if (displayName!=null) { if (this.mJoinedConversation!=null) {
return displayName; return this.mJoinedConversation.getName(true);
} else if (name!=null) {
return name;
} else { } else {
return this.jid.split("@")[0]; return this.jid.split("@")[0];
} }
@ -76,11 +82,6 @@ public class Bookmark implements ListItem {
return autojoin; return autojoin;
} }
@Override
public String getProfilePhoto() {
return null;
}
public boolean match(String needle) { public boolean match(String needle) {
return needle == null return needle == null
|| getJid().contains(needle.toLowerCase(Locale.US)) || getJid().contains(needle.toLowerCase(Locale.US))
@ -91,4 +92,21 @@ public class Bookmark implements ListItem {
public Account getAccount() { public Account getAccount() {
return this.account; 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;
}
} }

View file

@ -8,9 +8,12 @@ import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import eu.siacs.conversations.utils.UIHelper;
import eu.siacs.conversations.xml.Element; import eu.siacs.conversations.xml.Element;
import android.content.ContentValues; import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap;
public class Contact implements ListItem { public class Contact implements ListItem {
public static final String TABLENAME = "contacts"; public static final String TABLENAME = "contacts";
@ -311,4 +314,9 @@ public class Contact implements ListItem {
return null; return null;
} }
} }
@Override
public Bitmap getImage(int dpSize, Context context) {
return UIHelper.getContactPicture(this, dpSize, context, false);
}
} }

View file

@ -144,6 +144,8 @@ public class Conversation extends AbstractEntity {
if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null) if ((getMode() == MODE_MULTI) && (getMucOptions().getSubject() != null)
&& useSubject) { && useSubject) {
return getMucOptions().getSubject(); return getMucOptions().getSubject();
} else if (getMode() == MODE_MULTI && bookmark!=null && bookmark.getName() != null) {
return bookmark.getName();
} else { } else {
return this.getContact().getDisplayName(); return this.getContact().getDisplayName();
} }
@ -380,5 +382,12 @@ public class Conversation extends AbstractEntity {
public void setBookmark(Bookmark bookmark) { public void setBookmark(Bookmark bookmark) {
this.bookmark = bookmark; this.bookmark = bookmark;
this.bookmark.setConversation(this);
}
public void deregisterWithBookmark() {
if (this.bookmark != null) {
this.bookmark.setConversation(null);
}
} }
} }

View file

@ -1,7 +1,10 @@
package eu.siacs.conversations.entities; package eu.siacs.conversations.entities;
import android.content.Context;
import android.graphics.Bitmap;
public interface ListItem extends Comparable<ListItem> { public interface ListItem extends Comparable<ListItem> {
public String getDisplayName(); public String getDisplayName();
public String getJid(); public String getJid();
public String getProfilePhoto(); public Bitmap getImage(int dpSize, Context context);
} }

View file

@ -684,14 +684,11 @@ public class XmppConnectionService extends Service {
Log.d(LOGTAG,item.toString()); Log.d(LOGTAG,item.toString());
Bookmark bookmark = Bookmark.parse(item,account); Bookmark bookmark = Bookmark.parse(item,account);
bookmarks.add(bookmark); bookmarks.add(bookmark);
if (bookmark.autojoin()) { Conversation conversation = findMuc(bookmark);
Log.d(LOGTAG,"has autojoin"); if (conversation!=null) {
Conversation conversation = findMuc(bookmark); conversation.setBookmark(bookmark);
if (conversation!=null) { } else {
Log.d(LOGTAG,"conversation existed. adding bookmark"); if (bookmark.autojoin()) {
conversation.setBookmark(bookmark);
} else {
Log.d(LOGTAG,"creating new conversation");
conversation = findOrCreateConversation(account, bookmark.getJid(), true); conversation = findOrCreateConversation(account, bookmark.getJid(), true);
conversation.setBookmark(bookmark); conversation.setBookmark(bookmark);
} }
@ -1011,6 +1008,7 @@ public class XmppConnectionService extends Service {
Log.d(LOGTAG, "send leaving muc " + packet); Log.d(LOGTAG, "send leaving muc " + packet);
sendPresencePacket(conversation.getAccount(),packet); sendPresencePacket(conversation.getAccount(),packet);
conversation.getMucOptions().setOffline(); conversation.getMucOptions().setOffline();
conversation.deregisterWithBookmark();
} }
public void disconnect(Account account, boolean force) { public void disconnect(Account account, boolean force) {

View file

@ -221,6 +221,7 @@ public class StartConversation extends XmppActivity {
protected void openConversationForBookmark(int position) { protected void openConversationForBookmark(int position) {
Bookmark bookmark = (Bookmark) conferences.get(position); Bookmark bookmark = (Bookmark) conferences.get(position);
Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), bookmark.getJid(), true); Conversation conversation = xmppConnectionService.findOrCreateConversation(bookmark.getAccount(), bookmark.getJid(), true);
conversation.setBookmark(bookmark);
switchToConversation(conversation); switchToConversation(conversation);
} }
@ -445,8 +446,7 @@ public class StartConversation extends XmppActivity {
jid.setText(item.getJid()); jid.setText(item.getJid());
name.setText(item.getDisplayName()); name.setText(item.getDisplayName());
picture.setImageBitmap(UIHelper.getContactPicture(item, 48, picture.setImageBitmap(item.getImage(48, getApplicationContext()));
this.getContext(), false));
return view; return view;
} }

View file

@ -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) { Context context, boolean notification) {
String uri = contact.getProfilePhoto(); String uri = contact.getProfilePhoto();
if (uri == null) { if (uri == null) {