aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ShowResourcesListDialogListener.java
blob: 1c16095c6945443d9b5a7dd17f97133c60b36ff2 (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
package de.thedevstack.conversationsplus.ui.listeners;

import android.content.Context;
import android.view.View;

import de.thedevstack.conversationsplus.ui.adapter.PresencesArrayAdapter;
import de.thedevstack.conversationsplus.ui.dialogs.AbstractAlertDialog;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact;

/**
 * This listener shows the dialog with the resources of a contact.
 * The resources are shown with the color of their current online mode.
 * This listener implements OnClickListener and OnLongClickListener.
 */
public class ShowResourcesListDialogListener extends AbstractAlertDialog implements View.OnClickListener, View.OnLongClickListener {
    private Contact contact;

    public ShowResourcesListDialogListener(Context context, Contact contact) {
        super(context, getTitle(context, contact));
        this.contact = contact;
        this.init();
    }

    private static final String getTitle(Context context, Contact contact) {
        if (null != contact && null != contact.getJid() && null != contact.getJid().toBareJid()) {
            int presenceCount = null != contact.getPresences() ? contact.getPresences().size() : 0;
            return context.getString(R.string.dlg_resources_title, contact.getJid().toBareJid().toString(), presenceCount);
        }
        return null != contact ? contact.toString() : "";
    }

    protected void init() {
        this.builder.setAdapter(new PresencesArrayAdapter(getContext(), this.contact.getPresences()), null);
    }

    @Override
    public void onClick(View v) {
        this.show();
    }

    @Override
    public boolean onLongClick(View view) {
        this.show();
        return true;
    }
}