Search in sources :

Example 1 with CreatePublicChannelDialogBinding

use of eu.siacs.conversations.databinding.CreatePublicChannelDialogBinding 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

Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 NonNull (androidx.annotation.NonNull)1 AlertDialog (androidx.appcompat.app.AlertDialog)1 CreatePublicChannelDialogBinding (eu.siacs.conversations.databinding.CreatePublicChannelDialogBinding)1 KnownHostsAdapter (eu.siacs.conversations.ui.adapter.KnownHostsAdapter)1