1package eu.siacs.conversations.entities;
2
3import android.content.Context;
4import android.text.TextUtils;
5
6import java.util.Collections;
7import java.util.List;
8import java.util.Locale;
9
10import eu.siacs.conversations.utils.UIHelper;
11import eu.siacs.conversations.xmpp.Jid;
12
13public class RawBlockable implements ListItem, Blockable {
14
15 private final Account account;
16 private final Jid jid;
17
18 public RawBlockable(Account account, Jid jid) {
19 this.account = account;
20 this.jid = jid;
21 }
22
23 @Override
24 public boolean isBlocked() {
25 return true;
26 }
27
28 @Override
29 public boolean isDomainBlocked() {
30 throw new AssertionError("not implemented");
31 }
32
33 @Override
34 public Jid getBlockedJid() {
35 return this.jid;
36 }
37
38 @Override
39 public String getDisplayName() {
40 if (jid.isFullJid()) {
41 return jid.getResource();
42 } else {
43 return jid.toEscapedString();
44 }
45 }
46
47 @Override
48 public Jid getJid() {
49 return this.jid;
50 }
51
52 @Override
53 public List<Tag> getTags(Context context) {
54 return Collections.emptyList();
55 }
56
57 @Override
58 public boolean match(Context context, String needle) {
59 if (TextUtils.isEmpty(needle)) {
60 return true;
61 }
62 needle = needle.toLowerCase(Locale.US).trim();
63 String[] parts = needle.split("\\s+");
64 for (String part : parts) {
65 if (!jid.toEscapedString().contains(part)) {
66 return false;
67 }
68 }
69 return true;
70 }
71
72 @Override
73 public Account getAccount() {
74 return account;
75 }
76
77 @Override
78 public int getAvatarBackgroundColor() {
79 return UIHelper.getColorForName(jid.toEscapedString());
80 }
81
82 @Override
83 public String getAvatarName() {
84 return getDisplayName();
85 }
86
87 @Override
88 public int compareTo(ListItem o) {
89 return this.getDisplayName().compareToIgnoreCase(
90 o.getDisplayName());
91 }
92}