Bookmark.java

 1package eu.siacs.conversations.entities;
 2
 3import java.util.Locale;
 4
 5import eu.siacs.conversations.xml.Element;
 6
 7public class Bookmark implements ListItem {
 8	
 9	private Account account;
10	private String jid;
11	private String nick;
12	private String displayName;
13	private boolean autojoin;
14	
15	public Bookmark(Account account) {
16		this.account = account;
17	}
18
19	public static Bookmark parse(Element element, Account account) {
20		Bookmark bookmark = new Bookmark(account);
21		bookmark.setJid(element.getAttribute("jid"));
22		bookmark.setDisplayName(element.getAttribute("name"));
23		String autojoin = element.getAttribute("autojoin");
24		if (autojoin!=null && (autojoin.equals("true")||autojoin.equals("1"))) {
25			bookmark.setAutojoin(true);
26		} else {
27			bookmark.setAutojoin(false);
28		}
29		Element nick = element.findChild("nick");
30		if (nick!=null) {
31			bookmark.setNick(nick.getContent());
32		}
33		return bookmark;
34	}
35
36	public void setAutojoin(boolean autojoin) {
37		this.autojoin = autojoin;
38	}
39	
40	public void setDisplayName(String name) {
41		this.displayName = name;
42	}
43	
44	public void setJid(String jid) {
45		this.jid = jid;
46	}
47	
48	public void setNick(String nick) {
49		this.nick = nick;
50	}
51
52	@Override
53	public int compareTo(ListItem another) {
54		return this.getDisplayName().compareToIgnoreCase(another.getDisplayName());
55	}
56
57	@Override
58	public String getDisplayName() {
59		if (displayName!=null) {
60			return displayName;
61		} else {
62			return this.jid.split("@")[0];
63		}
64	}
65
66	@Override
67	public String getJid() {
68		return this.jid.toLowerCase(Locale.US);
69	}
70	
71	public String getNick() {
72		return this.nick;
73	}
74	
75	public boolean autojoin() {
76		return autojoin;
77	}
78
79	@Override
80	public String getProfilePhoto() {
81		return null;
82	}
83
84	public boolean match(String needle) {
85		return needle == null
86				|| getJid().contains(needle.toLowerCase(Locale.US))
87				|| getDisplayName().toLowerCase(Locale.US)
88						.contains(needle.toLowerCase(Locale.US));
89	}
90
91	public Account getAccount() {
92		return this.account;
93	}
94}