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 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;
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -1,7 +1,10 @@
package eu.siacs.conversations.entities;
import android.content.Context;
import android.graphics.Bitmap;
public interface ListItem extends Comparable<ListItem> {
public String getDisplayName();
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());
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) {

View file

@ -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;
}

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) {
String uri = contact.getProfilePhoto();
if (uri == null) {