AbstractContact.java 3.12 KB
Newer Older
Alexander Ivanov's avatar
Alexander Ivanov committed
1 2
/**
 * Copyright (c) 2013, Redsolution LTD. All rights reserved.
3
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
4 5
 * This file is part of Xabber project; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License, Version 3.
6
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
7 8 9 10
 * Xabber is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
11
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
 * You should have received a copy of the GNU General Public License,
 * along with this program. If not, see http://www.gnu.org/licenses/.
 */
package com.xabber.android.data.roster;

import java.util.Collection;
import java.util.Collections;

import android.graphics.drawable.Drawable;

import com.xabber.android.data.account.AccountManager;
import com.xabber.android.data.account.StatusMode;
import com.xabber.android.data.entity.BaseEntity;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.extension.capability.CapabilitiesManager;
import com.xabber.android.data.extension.capability.ClientInfo;
import com.xabber.android.data.extension.capability.ClientSoftware;
import com.xabber.android.data.extension.vcard.VCardManager;

/**
 * Basic contact representation.
33
 *
Alexander Ivanov's avatar
Alexander Ivanov committed
34 35 36 37
 * @author alexander.ivanov
 */
public class AbstractContact extends BaseEntity {

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 93 94 95 96 97 98 99 100 101 102
    public AbstractContact(String account, String user) {
        super(account, user);
    }

    /**
     * vCard and roster can be used for name resolving.
     *
     * @return Verbose name.
     */
    public String getName() {
        String vCardName = VCardManager.getInstance().getName(user);
        if (!"".equals(vCardName))
            return vCardName;
        return user;
    }

    public StatusMode getStatusMode() {
        return PresenceManager.getInstance().getStatusMode(account, user);
    }

    public String getStatusText() {
        return PresenceManager.getInstance().getStatusText(account, user);
    }

    public ClientSoftware getClientSoftware() {
        ResourceItem resourceItem = PresenceManager.getInstance()
                .getResourceItem(account, user);
        if (resourceItem == null)
            return ClientSoftware.unknown;
        ClientInfo clientInfo = CapabilitiesManager.getInstance()
                .getClientInfo(account, resourceItem.getUser(user));
        if (clientInfo == null)
            return ClientSoftware.unknown;
        return clientInfo.getClientSoftware();
    }

    public Collection<? extends Group> getGroups() {
        return Collections.emptyList();
    }

    public Drawable getAvatar() {
        return AvatarManager.getInstance().getUserAvatar(user);

    }

    /**
     * @return Cached avatar's drawable for contact list.
     */
    public Drawable getAvatarForContactList() {
        return AvatarManager.getInstance().getUserAvatarForContactList(user);
    }

    /**
     * @return Account's color level.
     */
    public int getColorLevel() {
        return AccountManager.getInstance().getColorLevel(account);
    }

    /**
     * @return Whether contact is connected.
     */
    public boolean isConnected() {
        return true;
    }
Alexander Ivanov's avatar
Alexander Ivanov committed
103 104

}