RawBlockable.java

 1package eu.siacs.conversations.entities;
 2
 3import android.content.Context;
 4import android.text.TextUtils;
 5import androidx.annotation.NonNull;
 6import eu.siacs.conversations.utils.UIHelper;
 7import eu.siacs.conversations.xmpp.Jid;
 8import java.util.Collections;
 9import java.util.List;
10import java.util.Locale;
11
12public class RawBlockable implements ListItem, Blockable {
13
14    private final Account account;
15    private final Jid jid;
16
17    public RawBlockable(@NonNull Account account, @NonNull Jid jid) {
18        this.account = account;
19        this.jid = jid;
20    }
21
22    @Override
23    public boolean isBlocked() {
24        return true;
25    }
26
27    @Override
28    public boolean isDomainBlocked() {
29        throw new AssertionError("not implemented");
30    }
31
32    @Override
33    @NonNull
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.toString();
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.toString().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.toString());
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(o.getDisplayName());
90    }
91}