2014-07-14 09:47:42 +00:00
|
|
|
package eu.siacs.conversations.entities;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-07-14 15:13:59 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Bitmap;
|
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
2014-07-14 09:47:42 +00:00
|
|
|
import eu.siacs.conversations.xml.Element;
|
|
|
|
|
|
|
|
public class Bookmark implements ListItem {
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-14 09:47:42 +00:00
|
|
|
private Account account;
|
|
|
|
private String jid;
|
|
|
|
private String nick;
|
2014-07-14 15:13:59 +00:00
|
|
|
private String name;
|
2014-07-14 09:47:42 +00:00
|
|
|
private boolean autojoin;
|
2014-07-14 15:13:59 +00:00
|
|
|
private Conversation mJoinedConversation;
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-15 12:32:19 +00:00
|
|
|
public Bookmark(Account account, String jid) {
|
2014-07-14 09:47:42 +00:00
|
|
|
this.account = account;
|
2014-07-15 12:32:19 +00:00
|
|
|
this.jid = jid;
|
2014-07-14 09:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static Bookmark parse(Element element, Account account) {
|
2014-08-31 14:28:21 +00:00
|
|
|
Bookmark bookmark = new Bookmark(account, element.getAttribute("jid"));
|
2014-07-14 15:13:59 +00:00
|
|
|
bookmark.setName(element.getAttribute("name"));
|
2014-07-14 09:47:42 +00:00
|
|
|
String autojoin = element.getAttribute("autojoin");
|
2014-08-31 14:28:21 +00:00
|
|
|
if (autojoin != null
|
|
|
|
&& (autojoin.equals("true") || autojoin.equals("1"))) {
|
2014-07-14 09:47:42 +00:00
|
|
|
bookmark.setAutojoin(true);
|
|
|
|
} else {
|
|
|
|
bookmark.setAutojoin(false);
|
|
|
|
}
|
|
|
|
Element nick = element.findChild("nick");
|
2014-08-31 14:28:21 +00:00
|
|
|
if (nick != null) {
|
2014-07-14 09:47:42 +00:00
|
|
|
bookmark.setNick(nick.getContent());
|
|
|
|
}
|
|
|
|
return bookmark;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAutojoin(boolean autojoin) {
|
|
|
|
this.autojoin = autojoin;
|
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-14 15:13:59 +00:00
|
|
|
public void setName(String name) {
|
|
|
|
this.name = name;
|
2014-07-14 09:47:42 +00:00
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-14 09:47:42 +00:00
|
|
|
public void setNick(String nick) {
|
|
|
|
this.nick = nick;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int compareTo(ListItem another) {
|
2014-08-31 14:28:21 +00:00
|
|
|
return this.getDisplayName().compareToIgnoreCase(
|
|
|
|
another.getDisplayName());
|
2014-07-14 09:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDisplayName() {
|
2014-08-31 14:28:21 +00:00
|
|
|
if (this.mJoinedConversation != null
|
|
|
|
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
|
2014-07-15 12:32:19 +00:00
|
|
|
return this.mJoinedConversation.getMucOptions().getSubject();
|
2014-08-31 14:28:21 +00:00
|
|
|
} else if (name != null) {
|
2014-07-14 15:13:59 +00:00
|
|
|
return name;
|
2014-07-14 09:47:42 +00:00
|
|
|
} else {
|
|
|
|
return this.jid.split("@")[0];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getJid() {
|
|
|
|
return this.jid.toLowerCase(Locale.US);
|
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-14 09:47:42 +00:00
|
|
|
public String getNick() {
|
|
|
|
return this.nick;
|
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-14 09:47:42 +00:00
|
|
|
public boolean autojoin() {
|
|
|
|
return autojoin;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean match(String needle) {
|
|
|
|
return needle == null
|
|
|
|
|| getJid().contains(needle.toLowerCase(Locale.US))
|
2014-08-31 14:28:21 +00:00
|
|
|
|| getDisplayName().toLowerCase(Locale.US).contains(
|
|
|
|
needle.toLowerCase(Locale.US));
|
2014-07-14 09:47:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Account getAccount() {
|
|
|
|
return this.account;
|
|
|
|
}
|
2014-07-14 15:13:59 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Bitmap getImage(int dpSize, Context context) {
|
2014-08-31 14:28:21 +00:00
|
|
|
if (this.mJoinedConversation == null) {
|
|
|
|
return UIHelper.getContactPicture(getDisplayName(), dpSize,
|
|
|
|
context, false);
|
2014-07-14 15:13:59 +00:00
|
|
|
} else {
|
2014-08-31 14:28:21 +00:00
|
|
|
return UIHelper.getContactPicture(this.mJoinedConversation, dpSize,
|
|
|
|
context, false);
|
2014-07-14 15:13:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setConversation(Conversation conversation) {
|
|
|
|
this.mJoinedConversation = conversation;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getName() {
|
|
|
|
return name;
|
|
|
|
}
|
2014-08-31 14:28:21 +00:00
|
|
|
|
2014-07-15 12:32:19 +00:00
|
|
|
public Element toElement() {
|
|
|
|
Element element = new Element("conference");
|
|
|
|
element.setAttribute("jid", this.getJid());
|
|
|
|
if (this.getName() != null) {
|
|
|
|
element.setAttribute("name", this.getName());
|
|
|
|
}
|
|
|
|
if (this.autojoin) {
|
|
|
|
element.setAttribute("autojoin", "true");
|
|
|
|
} else {
|
|
|
|
element.setAttribute("autojoin", "false");
|
|
|
|
}
|
|
|
|
if (this.nick != null) {
|
|
|
|
element.addChild("nick").setContent(this.nick);
|
|
|
|
}
|
|
|
|
return element;
|
|
|
|
}
|
2014-07-15 18:41:10 +00:00
|
|
|
|
|
|
|
public void unregisterConversation() {
|
|
|
|
if (this.mJoinedConversation != null) {
|
|
|
|
this.mJoinedConversation.deregisterWithBookmark();
|
|
|
|
}
|
|
|
|
}
|
2014-07-14 09:47:42 +00:00
|
|
|
}
|