aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/thedevstack/conversationsplus/ui/BlockContactDialog.java
blob: 589f565cc0d9f84a99301c0ca26a19b8cd4bfb38 (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
package de.thedevstack.conversationsplus.ui;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import de.thedevstack.conversationsplus.R;
import de.thedevstack.conversationsplus.entities.Blockable;
import de.thedevstack.conversationsplus.services.XmppConnectionService;

public final class BlockContactDialog {
	public static void show(final Context context,
			final XmppConnectionService xmppConnectionService,
			final Blockable blockable) {
		final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		final boolean isBlocked = blockable.isBlocked();
		builder.setNegativeButton(R.string.cancel, null);

		if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) {
			builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
			builder.setMessage(context.getResources().getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text,
						blockable.getJid().toDomainJid()));
		} else {
			builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact);
			builder.setMessage(context.getResources().getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text,
						blockable.getJid().toBareJid()));
		}
		builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, new DialogInterface.OnClickListener() {

			@Override
			public void onClick(final DialogInterface dialog, final int which) {
				if (isBlocked) {
					xmppConnectionService.sendUnblockRequest(blockable);
				} else {
					xmppConnectionService.sendBlockRequest(blockable);
				}
			}
		});
		builder.create().show();
	}
}