Search in sources :

Example 1 with KnownHostsAdapter

use of de.pixart.messenger.ui.adapter.KnownHostsAdapter in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method showJoinConferenceDialog.

@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(R.string.join_conference);
    final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
    final TextView yourAccount = dialogView.findViewById(R.id.your_account);
    final Spinner spinner = dialogView.findViewById(R.id.account);
    final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid);
    DelayedHintHelper.setHint(R.string.conference_address_example, jid);
    jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts));
    if (prefilledJid != null) {
        jid.append(prefilledJid);
    }
    if (xmppConnectionService.multipleAccounts()) {
        yourAccount.setVisibility(View.VISIBLE);
        spinner.setVisibility(View.VISIBLE);
    } else {
        yourAccount.setVisibility(View.GONE);
        spinner.setVisibility(View.GONE);
    }
    populateAccountSpinner(this, mActivatedAccounts, spinner);
    final Checkable bookmarkCheckBox = (CheckBox) dialogView.findViewById(R.id.bookmark);
    builder.setView(dialogView);
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(R.string.join, null);
    final AlertDialog dialog = builder.create();
    dialog.show();
    mCurrentDialog = dialog;
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
        if (!xmppConnectionServiceBound) {
            return;
        }
        final Account account = getSelectedAccount(spinner);
        if (account == null) {
            return;
        }
        final Jid conferenceJid;
        try {
            conferenceJid = Jid.fromString(jid.getText().toString());
        } catch (final InvalidJidException e) {
            jid.setError(getString(R.string.invalid_jid));
            return;
        }
        if (bookmarkCheckBox.isChecked()) {
            if (account.hasBookmarkFor(conferenceJid)) {
                jid.setError(getString(R.string.bookmark_already_exists));
            } else {
                final Bookmark bookmark = new Bookmark(account, conferenceJid.toBareJid());
                bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin)));
                String nick = conferenceJid.getResourcepart();
                if (nick != null && !nick.isEmpty()) {
                    bookmark.setNick(nick);
                }
                account.getBookmarks().add(bookmark);
                xmppConnectionService.pushBookmarks(account);
                final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
                bookmark.setConversation(conversation);
                dialog.dismiss();
                mCurrentDialog = null;
                switchToConversation(conversation);
            }
        } else {
            final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true);
            dialog.dismiss();
            mCurrentDialog = null;
            switchToConversation(conversation);
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) KnownHostsAdapter(de.pixart.messenger.ui.adapter.KnownHostsAdapter) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) Spinner(android.widget.Spinner) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException) Conversation(de.pixart.messenger.entities.Conversation) SpannableString(android.text.SpannableString) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Bookmark(de.pixart.messenger.entities.Bookmark) CheckBox(android.widget.CheckBox) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) Checkable(android.widget.Checkable) AutoCompleteTextView(android.widget.AutoCompleteTextView) SuppressLint(android.annotation.SuppressLint)

Example 2 with KnownHostsAdapter

use of de.pixart.messenger.ui.adapter.KnownHostsAdapter in project Pix-Art-Messenger by kriztan.

the class EditAccountActivity method onBackendConnected.

protected void onBackendConnected() {
    boolean init = true;
    if (mSavedInstanceAccount != null) {
        try {
            this.mAccount = xmppConnectionService.findAccountByJid(Jid.fromString(mSavedInstanceAccount));
            this.mInitMode = mSavedInstanceInit;
            init = false;
        } catch (InvalidJidException e) {
            this.mAccount = null;
        }
    } else if (this.jidToEdit != null) {
        this.mAccount = xmppConnectionService.findAccountByJid(jidToEdit);
    }
    if (mAccount != null) {
        this.mInitMode |= this.mAccount.isOptionSet(Account.OPTION_REGISTER);
        this.mUsernameMode |= mAccount.isOptionSet(Account.OPTION_MAGIC_CREATE) && mAccount.isOptionSet(Account.OPTION_REGISTER);
        if (this.mAccount.getPrivateKeyAlias() != null) {
            this.mPassword.setHint(R.string.authenticate_with_certificate);
            if (this.mInitMode) {
                this.mPassword.requestFocus();
            }
        }
        if (mPendingFingerprintVerificationUri != null) {
            processFingerprintVerification(mPendingFingerprintVerificationUri, false);
            mPendingFingerprintVerificationUri = null;
        }
        updateAccountInformation(init);
    }
    if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
        this.mCancelButton.setEnabled(false);
    }
    if (mUsernameMode) {
        this.binding.accountJid.setHint(R.string.username_hint);
    } else {
        final KnownHostsAdapter mKnownHostsAdapter = new KnownHostsAdapter(this, R.layout.simple_list_item, xmppConnectionService.getKnownHosts());
        this.binding.accountJid.setAdapter(mKnownHostsAdapter);
    }
    if (pendingUri != null) {
        processFingerprintVerification(pendingUri, false);
        pendingUri = null;
    }
    updateSaveButton();
    invalidateOptionsMenu();
}
Also used : KnownHostsAdapter(de.pixart.messenger.ui.adapter.KnownHostsAdapter) InvalidJidException(de.pixart.messenger.xmpp.jid.InvalidJidException)

Aggregations

KnownHostsAdapter (de.pixart.messenger.ui.adapter.KnownHostsAdapter)2 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)2 SuppressLint (android.annotation.SuppressLint)1 AlertDialog (android.support.v7.app.AlertDialog)1 SpannableString (android.text.SpannableString)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 AutoCompleteTextView (android.widget.AutoCompleteTextView)1 CheckBox (android.widget.CheckBox)1 Checkable (android.widget.Checkable)1 ListView (android.widget.ListView)1 Spinner (android.widget.Spinner)1 TextView (android.widget.TextView)1 Account (de.pixart.messenger.entities.Account)1 Bookmark (de.pixart.messenger.entities.Bookmark)1 Conversation (de.pixart.messenger.entities.Conversation)1 Jid (de.pixart.messenger.xmpp.jid.Jid)1