From 72537b76c5fff6f06e9e4b5b20a4dfbf14b02149 Mon Sep 17 00:00:00 2001 From: vikiCoder Date: Sun, 5 Mar 2017 01:01:41 +0530 Subject: [PATCH] fixes #2336 : added an option to directly add a jid to block list from blocklist activity --- .../conversations/ui/BlocklistActivity.java | 43 +++++++++++++++++++ .../conversations/ui/EditAccountActivity.java | 3 +- src/main/res/menu/choose_contact.xml | 7 +++ src/main/res/values/strings.xml | 1 + 4 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/BlocklistActivity.java b/src/main/java/eu/siacs/conversations/ui/BlocklistActivity.java index abec8ed76..083c7e725 100644 --- a/src/main/java/eu/siacs/conversations/ui/BlocklistActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/BlocklistActivity.java @@ -2,17 +2,23 @@ package eu.siacs.conversations.ui; import android.os.Bundle; import android.text.Editable; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import java.util.ArrayList; import java.util.Collections; +import java.util.List; +import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.jid.Jid; public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist { + private List mKnownHosts = new ArrayList(); private Account account = null; @@ -41,6 +47,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem } } filterContacts(); + this.mKnownHosts = xmppConnectionService.getKnownHosts(); } @Override @@ -58,6 +65,42 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem getListItemAdapter().notifyDataSetChanged(); } + @Override + public boolean onCreateOptionsMenu(final Menu menu) { + super.onCreateOptionsMenu(menu); + menu.findItem(R.id.action_add_contact).setVisible(true); + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.action_add_contact: + showEnterJidDialog(); + return true; + } + return super.onOptionsItemSelected(item); + } + + protected void showEnterJidDialog() { + EnterJidDialog dialog = new EnterJidDialog( + this, mKnownHosts, null, + getString(R.string.block_jabber_id), getString(R.string.block), + null, account.getJid().toBareJid().toString(), true + ); + + dialog.setOnEnterJidDialogPositiveListener(new EnterJidDialog.OnEnterJidDialogPositiveListener() { + @Override + public boolean onEnterJidDialogPositive(Jid accountJid, Jid contactJid) throws EnterJidDialog.JidError { + Contact contact = account.getRoster().getContact(contactJid); + xmppConnectionService.sendBlockRequest(contact, false); + return true; + } + }); + + dialog.show(); + } + protected void refreshUiReal() { final Editable editable = getSearchEditText().getText(); if (editable != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 2080ddc0b..f78482525 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -571,9 +571,8 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat if (mAccount != null && mAccount.isOnlineAndConnected()) { if (!mAccount.getXmppConnection().getFeatures().blocking()) { showBlocklist.setVisible(false); - } else { - showBlocklist.setEnabled(mAccount.getBlocklist().size() > 0); } + if (!mAccount.getXmppConnection().getFeatures().register()) { changePassword.setVisible(false); } diff --git a/src/main/res/menu/choose_contact.xml b/src/main/res/menu/choose_contact.xml index 94b6479be..3b16567e9 100644 --- a/src/main/res/menu/choose_contact.xml +++ b/src/main/res/menu/choose_contact.xml @@ -14,4 +14,11 @@ android:showAsAction="always" android:title="@string/create_contact" android:visible="false"/> + + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 11453a7c8..0a9e42177 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -177,6 +177,7 @@ If you delete your account your entire conversation history will be lost Record voice Jabber ID + Block Jabber ID Password username@example.com Confirm password