af7a64491f
Fixes #791 Squash of commits: 534f25d7dae3ce6852243e28fdd0a69ac01e9463 808fdf5147f27a912a60bee39aa4bf1ddd4f43b4 1eaf8a8330710ad35ba7c368e04f909af623ae4c 31585242c2359efdcd0eeddb9745077f54dbc9eb 2e69bd0bd0286ed1e98a42f4c3421ba4d8cf524b e904fb5015bf3a1904ab941a1957edf3b1e7abd2 eebbadf3b3816bbf8fcccb763e419fed252d266f 7c5b87724ce494e5a6e8026557ed50a8fd9f23e8 b0eaaf446937794fe19cbdb4f8309c3ff83d4e42 8c652f9e8bb3512958d9ad8c6f1326505f2d98c8 ad0ea1ad948ff6f8fde7b0b10f5163dc8852032f f5d49897e0dba691ef53a0eddb9ed34d129ad442 a08fa64c505bd895b7c626cfad182380373be20b de67079113e08394a276048c31f6b21baa300829 9069f342173ba30c2b20c67529c7ff497a6a257d 0169fa79d161ee898c4b6762e207087682a952d8 8585a5bd75a5d56927fed8317729bd15fffe4dcc 0053528a078369e0b65dcf71bda251072a1299c7 e901a9c3554bd7cca193e92919b463991eadfea7 c5c78257434813c69ab9b7558bcc8f7cbe858433 e905af348d46d77bc46b5f7211527684acc02fab 13a0f9a10c7892b0f90f5fabd2f2615701b0fd66 2cfba1e24b0139839e4453b92be7e20634d150cf 58e074fb5bb44b05a8104250fccd7c024c808c1a 0d6cf98fc8eab212d798ac79b336f9b70a14f06d e23620f56b85bcab9f3b5d9ce1c01524cd9674dc d72cd2fcc8d54176c3ff53411a69b9bb4642eff3 195143dff8836623a37094a6b8fa6aa01ef31580 5f5f3caf3a1e480a99d27ee5c34ba516419c52e4 1dee3d5861c9f9c710da4cbda3688d94c622ca93 23949b8aa32c78b27bab49bb3c4f3ff588925ce1 9bf97f8ae522796e0dacb7f6fe7a7f90f86a93a1
161 lines
3.6 KiB
Java
161 lines
3.6 KiB
Java
package eu.siacs.conversations.entities;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
|
|
import eu.siacs.conversations.utils.UIHelper;
|
|
import eu.siacs.conversations.xml.Element;
|
|
import eu.siacs.conversations.xmpp.jid.Jid;
|
|
|
|
public class Bookmark extends Element implements ListItem {
|
|
|
|
private Account account;
|
|
private Conversation mJoinedConversation;
|
|
|
|
public Bookmark(final Account account, final Jid jid) {
|
|
super("conference");
|
|
this.setAttribute("jid", jid.toString());
|
|
this.account = account;
|
|
}
|
|
|
|
private Bookmark(Account account) {
|
|
super("conference");
|
|
this.account = account;
|
|
}
|
|
|
|
public static Bookmark parse(Element element, Account account) {
|
|
Bookmark bookmark = new Bookmark(account);
|
|
bookmark.setAttributes(element.getAttributes());
|
|
bookmark.setChildren(element.getChildren());
|
|
return bookmark;
|
|
}
|
|
|
|
public void setAutojoin(boolean autojoin) {
|
|
if (autojoin) {
|
|
this.setAttribute("autojoin", "true");
|
|
} else {
|
|
this.setAttribute("autojoin", "false");
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(final ListItem another) {
|
|
return this.getDisplayName().compareToIgnoreCase(
|
|
another.getDisplayName());
|
|
}
|
|
|
|
@Override
|
|
public String getDisplayName() {
|
|
if (this.mJoinedConversation != null
|
|
&& (this.mJoinedConversation.getMucOptions().getSubject() != null)) {
|
|
return this.mJoinedConversation.getMucOptions().getSubject();
|
|
} else if (getName() != null) {
|
|
return getName();
|
|
} else {
|
|
return this.getJid().getLocalpart();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public Jid getJid() {
|
|
return this.getAttributeAsJid("jid");
|
|
}
|
|
|
|
@Override
|
|
public List<Tag> getTags() {
|
|
ArrayList<Tag> tags = new ArrayList<Tag>();
|
|
for (Element element : getChildren()) {
|
|
if (element.getName().equals("group") && element.getContent() != null) {
|
|
String group = element.getContent();
|
|
tags.add(new Tag(group, UIHelper.getColorForName(group)));
|
|
}
|
|
}
|
|
return tags;
|
|
}
|
|
|
|
public String getNick() {
|
|
Element nick = this.findChild("nick");
|
|
if (nick != null) {
|
|
return nick.getContent();
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void setNick(String nick) {
|
|
Element element = this.findChild("nick");
|
|
if (element == null) {
|
|
element = this.addChild("nick");
|
|
}
|
|
element.setContent(nick);
|
|
}
|
|
|
|
public boolean autojoin() {
|
|
return this.getAttributeAsBoolean("autojoin");
|
|
}
|
|
|
|
public String getPassword() {
|
|
Element password = this.findChild("password");
|
|
if (password != null) {
|
|
return password.getContent();
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public void setPassword(String password) {
|
|
Element element = this.findChild("password");
|
|
if (element != null) {
|
|
element.setContent(password);
|
|
}
|
|
}
|
|
|
|
public boolean match(String needle) {
|
|
if (needle == null) {
|
|
return true;
|
|
}
|
|
needle = needle.toLowerCase(Locale.US);
|
|
final Jid jid = getJid();
|
|
return (jid != null && jid.toString().contains(needle)) ||
|
|
getDisplayName().toLowerCase(Locale.US).contains(needle) ||
|
|
matchInTag(needle);
|
|
}
|
|
|
|
private boolean matchInTag(String needle) {
|
|
needle = needle.toLowerCase(Locale.US);
|
|
for (Tag tag : getTags()) {
|
|
if (tag.getName().toLowerCase(Locale.US).contains(needle)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public Account getAccount() {
|
|
return this.account;
|
|
}
|
|
|
|
public Conversation getConversation() {
|
|
return this.mJoinedConversation;
|
|
}
|
|
|
|
public void setConversation(Conversation conversation) {
|
|
this.mJoinedConversation = conversation;
|
|
}
|
|
|
|
public String getName() {
|
|
return this.getAttribute("name");
|
|
}
|
|
|
|
public void setName(String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
public void unregisterConversation() {
|
|
if (this.mJoinedConversation != null) {
|
|
this.mJoinedConversation.deregisterWithBookmark();
|
|
}
|
|
}
|
|
}
|