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