diff --git a/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java b/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java index af96f700a..10bd4ced1 100644 --- a/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/ChannelDiscoveryActivity.java @@ -2,8 +2,10 @@ package eu.siacs.conversations.ui; import android.app.AlertDialog; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.databinding.DataBindingUtil; +import android.net.Uri; import android.os.Bundle; import android.support.v7.widget.Toolbar; import android.text.Html; @@ -203,6 +205,13 @@ public class ChannelDiscoveryActivity extends XmppActivity implements MenuItem.O case R.id.share_with: StartConversationActivity.shareAsChannel(this, room.address); return true; + case R.id.open_join_dialog: + final Intent intent = new Intent(this, StartConversationActivity.class); + intent.setAction(Intent.ACTION_VIEW); + intent.putExtra("force_dialog", true); + intent.setData(Uri.parse(String.format("xmpp:%s?join", room.address))); + startActivity(intent); + return true; } } return false; diff --git a/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java b/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java index b9c9b15b1..05dca588d 100644 --- a/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java +++ b/src/main/java/eu/siacs/conversations/ui/JoinConferenceDialog.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.app.Dialog; import android.databinding.DataBindingUtil; import android.support.annotation.NonNull; +import android.support.design.widget.TextInputLayout; import android.support.v4.app.DialogFragment; import android.content.Context; import android.content.DialogInterface; @@ -65,9 +66,9 @@ public class JoinConferenceDialog extends DialogFragment implements OnBackendCon builder.setNegativeButton(R.string.cancel, null); AlertDialog dialog = builder.create(); dialog.show(); - dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked())); + dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.accountJidLayout, binding.jid, binding.bookmark.isChecked())); binding.jid.setOnEditorActionListener((v, actionId, event) -> { - mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked()); + mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.accountJidLayout, binding.jid, binding.bookmark.isChecked()); return true; }); return dialog; @@ -116,6 +117,6 @@ public class JoinConferenceDialog extends DialogFragment implements OnBackendCon } public interface JoinConferenceDialogListener { - void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked); + void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout jidLayout, AutoCompleteTextView jid, boolean isBookmarkChecked); } } diff --git a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java index d1834e62a..9264d039e 100644 --- a/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/StartConversationActivity.java @@ -15,6 +15,7 @@ import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.support.design.widget.TextInputLayout; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; @@ -837,6 +838,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne if (uri != null) { Invite invite = new Invite(intent.getData(), intent.getBooleanExtra("scanned", false)); invite.account = intent.getStringExtra("account"); + invite.forceDialog = intent.getBooleanExtra("force_dialog", false); return invite.invite(); } else { return false; @@ -849,7 +851,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne List contacts = xmppConnectionService.findContacts(invite.getJid(), invite.account); if (invite.isAction(XmppUri.ACTION_JOIN)) { Conversation muc = xmppConnectionService.findFirstMuc(invite.getJid()); - if (muc != null) { + if (muc != null && !invite.forceDialog) { switchToConversationDoNotAppend(muc, invite.getBody()); return true; } else { @@ -1004,7 +1006,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } @Override - public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked) { + public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout layout, AutoCompleteTextView jid, boolean isBookmarkChecked) { if (!xmppConnectionServiceBound) { return; } @@ -1012,17 +1014,26 @@ public class StartConversationActivity extends XmppActivity implements XmppConne if (account == null) { return; } - final Jid conferenceJid; + final String input = jid.getText().toString(); + Jid conferenceJid; try { - conferenceJid = Jid.of(jid.getText().toString()); + conferenceJid = Jid.of(input); } catch (final IllegalArgumentException e) { - jid.setError(getString(R.string.invalid_jid)); - return; + final XmppUri xmppUri = new XmppUri(input); + if (xmppUri.isJidValid() && xmppUri.isAction(XmppUri.ACTION_JOIN)) { + final Editable editable = jid.getEditableText(); + editable.clear(); + editable.append(xmppUri.getJid().toEscapedString()); + conferenceJid = xmppUri.getJid(); + } else { + layout.setError(getString(R.string.invalid_jid)); + return; + } } if (isBookmarkChecked) { if (account.hasBookmarkFor(conferenceJid)) { - jid.setError(getString(R.string.bookmark_already_exists)); + layout.setError(getString(R.string.bookmark_already_exists)); } else { final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); bookmark.setAutojoin(getBooleanPreference("autojoin", R.bool.autojoin)); @@ -1278,6 +1289,8 @@ public class StartConversationActivity extends XmppActivity implements XmppConne public String account; + public boolean forceDialog = false; + public Invite(final Uri uri) { super(uri); } diff --git a/src/main/res/menu/channel_item_context.xml b/src/main/res/menu/channel_item_context.xml index 7d26a42dd..a274053e5 100644 --- a/src/main/res/menu/channel_item_context.xml +++ b/src/main/res/menu/channel_item_context.xml @@ -3,4 +3,7 @@ + \ No newline at end of file diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index cf949b85b..b818fad2e 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -876,4 +876,5 @@ This account has already been setup Please enter the password for this account Unable to perform this action + Join public channel…