Search in sources :

Example 1 with KnownHostsAdapter

use of eu.siacs.conversations.ui.adapter.KnownHostsAdapter in project Conversations by siacs.

the class EnterJidDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getArguments().getString(TITLE_KEY));
    binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.enter_jid_dialog, null, false);
    this.knownHostsAdapter = new KnownHostsAdapter(getActivity(), R.layout.simple_list_item);
    binding.jid.setAdapter(this.knownHostsAdapter);
    binding.jid.addTextChangedListener(this);
    String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
    if (prefilledJid != null) {
        binding.jid.append(prefilledJid);
        if (!getArguments().getBoolean(ALLOW_EDIT_JID_KEY)) {
            binding.jid.setFocusable(false);
            binding.jid.setFocusableInTouchMode(false);
            binding.jid.setClickable(false);
            binding.jid.setCursorVisible(false);
        }
    }
    sanityCheckJid = getArguments().getBoolean(SANITY_CHECK_JID, false);
    DelayedHintHelper.setHint(R.string.account_settings_example_jabber_id, binding.jid);
    String account = getArguments().getString(ACCOUNT_KEY);
    if (account == null) {
        StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account);
    } else {
        ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), R.layout.simple_list_item, new String[] { account });
        binding.account.setEnabled(false);
        adapter.setDropDownViewResource(R.layout.simple_list_item);
        binding.account.setAdapter(adapter);
    }
    builder.setView(binding.getRoot());
    builder.setNegativeButton(R.string.cancel, null);
    builder.setPositiveButton(getArguments().getString(POSITIVE_BUTTON_KEY), null);
    this.dialog = builder.create();
    View.OnClickListener dialogOnClick = v -> {
        handleEnter(binding, account);
    };
    binding.jid.setOnEditorActionListener((v, actionId, event) -> {
        handleEnter(binding, account);
        return true;
    });
    dialog.show();
    dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(dialogOnClick);
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) OnBackendConnected(eu.siacs.conversations.ui.interfaces.OnBackendConnected) Arrays(java.util.Arrays) Config(eu.siacs.conversations.Config) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) R(eu.siacs.conversations.R) NonNull(androidx.annotation.NonNull) Collection(java.util.Collection) Dialog(android.app.Dialog) Editable(android.text.Editable) ArrayList(java.util.ArrayList) ArrayAdapter(android.widget.ArrayAdapter) List(java.util.List) View(android.view.View) DelayedHintHelper(eu.siacs.conversations.ui.util.DelayedHintHelper) Activity(android.app.Activity) Collections(java.util.Collections) EnterJidDialogBinding(eu.siacs.conversations.databinding.EnterJidDialogBinding) Jid(eu.siacs.conversations.xmpp.Jid) TextWatcher(android.text.TextWatcher) DataBindingUtil(androidx.databinding.DataBindingUtil) DialogFragment(androidx.fragment.app.DialogFragment) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter) NonNull(androidx.annotation.NonNull)

Example 2 with KnownHostsAdapter

use of eu.siacs.conversations.ui.adapter.KnownHostsAdapter in project Conversations by siacs.

the class JoinConferenceDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.join_public_channel);
    DialogJoinConferenceBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.dialog_join_conference, null, false);
    DelayedHintHelper.setHint(R.string.channel_full_jid_example, binding.jid);
    this.knownHostsAdapter = new KnownHostsAdapter(getActivity(), R.layout.simple_list_item);
    binding.jid.setAdapter(knownHostsAdapter);
    String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
    if (prefilledJid != null) {
        binding.jid.append(prefilledJid);
    }
    StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account);
    builder.setView(binding.getRoot());
    builder.setPositiveButton(R.string.join, null);
    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.accountJidLayout, binding.jid, binding.bookmark.isChecked()));
    binding.jid.setOnEditorActionListener((v, actionId, event) -> {
        mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.accountJidLayout, binding.jid, binding.bookmark.isChecked());
        return true;
    });
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) DialogJoinConferenceBinding(eu.siacs.conversations.databinding.DialogJoinConferenceBinding) NonNull(androidx.annotation.NonNull)

Example 3 with KnownHostsAdapter

use of eu.siacs.conversations.ui.adapter.KnownHostsAdapter in project Conversations by siacs.

the class EditAccountActivity method onBackendConnected.

protected void onBackendConnected() {
    boolean init = true;
    if (mSavedInstanceAccount != null) {
        try {
            this.mAccount = xmppConnectionService.findAccountByJid(Jid.ofEscaped(mSavedInstanceAccount));
            this.mInitMode = mSavedInstanceInit;
            init = false;
        } catch (IllegalArgumentException 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 (mPendingFingerprintVerificationUri != null) {
            processFingerprintVerification(mPendingFingerprintVerificationUri, false);
            mPendingFingerprintVerificationUri = null;
        }
        updateAccountInformation(init);
    }
    if (Config.MAGIC_CREATE_DOMAIN == null && this.xmppConnectionService.getAccounts().size() == 0) {
        this.binding.cancelButton.setEnabled(false);
    }
    if (mUsernameMode) {
        this.binding.accountJidLayout.setHint(getString(R.string.username_hint));
        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;
    }
    updatePortLayout();
    updateSaveButton();
    invalidateOptionsMenu();
}
Also used : KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter)

Example 4 with KnownHostsAdapter

use of eu.siacs.conversations.ui.adapter.KnownHostsAdapter in project Conversations by siacs.

the class CreatePublicChannelDialog method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    jidWasModified = savedInstanceState != null && savedInstanceState.getBoolean("jid_was_modified_false", false);
    nameEntered = savedInstanceState != null && savedInstanceState.getBoolean("name_entered", false);
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.create_public_channel);
    final CreatePublicChannelDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.create_public_channel_dialog, null, false);
    binding.account.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            updateJidSuggestion(binding);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    binding.jid.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (skipTetxWatcher) {
                return;
            }
            if (jidWasModified) {
                jidWasModified = !TextUtils.isEmpty(s);
            } else {
                jidWasModified = !s.toString().equals(getJidSuggestion(binding));
            }
        }
    });
    updateInputs(binding, false);
    ArrayList<String> mActivatedAccounts = getArguments().getStringArrayList(ACCOUNTS_LIST_KEY);
    StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, binding.account);
    builder.setView(binding.getRoot());
    builder.setPositiveButton(nameEntered ? R.string.create : R.string.next, null);
    builder.setNegativeButton(nameEntered ? R.string.back : R.string.cancel, null);
    DelayedHintHelper.setHint(R.string.channel_bare_jid_example, binding.jid);
    this.knownHostsAdapter = new KnownHostsAdapter(getActivity(), R.layout.simple_list_item);
    binding.jid.setAdapter(knownHostsAdapter);
    final AlertDialog dialog = builder.create();
    binding.groupChatName.setOnEditorActionListener((v, actionId, event) -> {
        submit(dialog, binding);
        return true;
    });
    dialog.setOnShowListener(dialogInterface -> {
        dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(v -> goBack(dialog, binding));
        dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(v -> submit(dialog, binding));
    });
    return dialog;
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) KnownHostsAdapter(eu.siacs.conversations.ui.adapter.KnownHostsAdapter) View(android.view.View) AdapterView(android.widget.AdapterView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) AdapterView(android.widget.AdapterView) CreatePublicChannelDialogBinding(eu.siacs.conversations.databinding.CreatePublicChannelDialogBinding) NonNull(androidx.annotation.NonNull)

Aggregations

KnownHostsAdapter (eu.siacs.conversations.ui.adapter.KnownHostsAdapter)4 NonNull (androidx.annotation.NonNull)3 AlertDialog (androidx.appcompat.app.AlertDialog)3 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 Bundle (android.os.Bundle)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 DataBindingUtil (androidx.databinding.DataBindingUtil)1 DialogFragment (androidx.fragment.app.DialogFragment)1 Config (eu.siacs.conversations.Config)1 R (eu.siacs.conversations.R)1 CreatePublicChannelDialogBinding (eu.siacs.conversations.databinding.CreatePublicChannelDialogBinding)1 DialogJoinConferenceBinding (eu.siacs.conversations.databinding.DialogJoinConferenceBinding)1 EnterJidDialogBinding (eu.siacs.conversations.databinding.EnterJidDialogBinding)1 OnBackendConnected (eu.siacs.conversations.ui.interfaces.OnBackendConnected)1 DelayedHintHelper (eu.siacs.conversations.ui.util.DelayedHintHelper)1