channel search result long press to show join dialog

This commit is contained in:
Daniel Gultsch 2019-09-24 17:29:34 +02:00
parent 92e27a3649
commit 6c5b71440f
5 changed files with 37 additions and 10 deletions

View file

@ -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;

View file

@ -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);
}
}

View file

@ -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<Contact> 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);
}

View file

@ -3,4 +3,7 @@
<item
android:id="@+id/share_with"
android:title="@string/share_uri_with" />
<item
android:id="@+id/open_join_dialog"
android:title="@string/open_join_dialog"/>
</menu>

View file

@ -876,4 +876,5 @@
<string name="account_already_setup">This account has already been setup</string>
<string name="please_enter_password">Please enter the password for this account</string>
<string name="unable_to_perform_this_action">Unable to perform this action</string>
<string name="open_join_dialog">Join public channel…</string>
</resources>