aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/entities/RawBlockable.java
blob: 0c8befc064206f10d27c377a4785e5902099d484 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package de.pixart.messenger.entities;

import android.content.Context;
import android.text.TextUtils;

import java.util.Collections;
import java.util.List;
import java.util.Locale;

import de.pixart.messenger.utils.UIHelper;
import rocks.xmpp.addr.Jid;

public class RawBlockable implements ListItem, Blockable {

    private final Account account;
    private final Jid jid;

    public RawBlockable(Account account, Jid jid) {
        this.account = account;
        this.jid = jid;
    }

    @Override
    public boolean isBlocked() {
        return true;
    }

    @Override
    public boolean isDomainBlocked() {
        throw new AssertionError("not implemented");
    }

    @Override
    public Jid getBlockedJid() {
        return this.jid;
    }

    @Override
    public String getDisplayName() {
        if (jid.isFullJid()) {
            return jid.getResource();
        } else {
            return jid.toEscapedString();
        }
    }

    @Override
    public int getOffline() {
        return 0;
    }

    @Override
    public Jid getJid() {
        return this.jid;
    }

    @Override
    public List<Tag> getTags(Context context) {
        return Collections.emptyList();
    }

    @Override
    public boolean match(Context context, String needle) {
        if (TextUtils.isEmpty(needle)) {
            return true;
        }
        needle = needle.toLowerCase(Locale.US).trim();
        String[] parts = needle.split("\\s+");
        for (String part : parts) {
            if (!jid.toEscapedString().contains(part)) {
                return false;
            }
        }
        return true;
    }

    @Override
    public Account getAccount() {
        return account;
    }

    @Override
    public int getAvatarBackgroundColor() {
        return UIHelper.getColorForName(jid.toEscapedString());
    }

    @Override
    public int compareTo(ListItem o) {
        return this.getDisplayName().compareToIgnoreCase(
                o.getDisplayName());
    }
}