1package eu.siacs.conversations.ui;
2
3import android.app.AlertDialog;
4import android.content.Context;
5import android.content.DialogInterface;
6import android.view.LayoutInflater;
7import android.view.View;
8import android.widget.CheckBox;
9import android.widget.LinearLayout;
10import android.widget.TextView;
11
12import eu.siacs.conversations.R;
13import eu.siacs.conversations.entities.Blockable;
14import eu.siacs.conversations.services.XmppConnectionService;
15
16public final class BlockContactDialog {
17 public static void show(final Context context,
18 final XmppConnectionService xmppConnectionService,
19 final Blockable blockable) {
20 final AlertDialog.Builder builder = new AlertDialog.Builder(context);
21 final boolean isBlocked = blockable.isBlocked();
22 builder.setNegativeButton(R.string.cancel, null);
23 LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
24 LinearLayout view = (LinearLayout) inflater.inflate(R.layout.dialog_block_contact,null);
25 TextView message = (TextView) view.findViewById(R.id.text);
26 final CheckBox report = (CheckBox) view.findViewById(R.id.report_spam);
27 final boolean reporting = blockable.getAccount().getXmppConnection().getFeatures().spamReporting();
28 report.setVisibility(!isBlocked && reporting ? View.VISIBLE : View.GONE);
29 builder.setView(view);
30
31 if (blockable.getJid().isDomainJid() || blockable.getAccount().isBlocked(blockable.getJid().toDomainJid())) {
32 builder.setTitle(isBlocked ? R.string.action_unblock_domain : R.string.action_block_domain);
33 message.setText(context.getResources().getString(isBlocked ? R.string.unblock_domain_text : R.string.block_domain_text,
34 blockable.getJid().toDomainJid()));
35 } else {
36 builder.setTitle(isBlocked ? R.string.action_unblock_contact : R.string.action_block_contact);
37 message.setText(context.getResources().getString(isBlocked ? R.string.unblock_contact_text : R.string.block_contact_text,
38 blockable.getJid().toBareJid()));
39 }
40 builder.setPositiveButton(isBlocked ? R.string.unblock : R.string.block, new DialogInterface.OnClickListener() {
41
42 @Override
43 public void onClick(final DialogInterface dialog, final int which) {
44 if (isBlocked) {
45 xmppConnectionService.sendUnblockRequest(blockable);
46 } else {
47 xmppConnectionService.sendBlockRequest(blockable, report.isChecked());
48 }
49 }
50 });
51 builder.create().show();
52 }
53}