2018-03-12 09:42:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
import android.app.Activity;
|
2018-03-12 09:42:01 +00:00
|
|
|
import android.app.Dialog;
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import com.google.android.material.textfield.TextInputLayout;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2018-03-12 09:42:01 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.os.Bundle;
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2019-01-10 21:09:20 +00:00
|
|
|
import android.view.KeyEvent;
|
2018-03-12 09:42:01 +00:00
|
|
|
import android.widget.AutoCompleteTextView;
|
|
|
|
import android.widget.Spinner;
|
2019-01-10 21:09:20 +00:00
|
|
|
import android.widget.TextView;
|
2018-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
2018-04-01 07:18:12 +00:00
|
|
|
import eu.siacs.conversations.databinding.DialogJoinConferenceBinding;
|
2018-03-12 09:42:01 +00:00
|
|
|
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
2018-03-14 09:07:52 +00:00
|
|
|
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
2018-03-12 09:42:01 +00:00
|
|
|
import eu.siacs.conversations.ui.util.DelayedHintHelper;
|
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
public class JoinConferenceDialog extends DialogFragment implements OnBackendConnected {
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
private static final String PREFILLED_JID_KEY = "prefilled_jid";
|
|
|
|
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
|
|
|
|
private JoinConferenceDialogListener mListener;
|
|
|
|
private KnownHostsAdapter knownHostsAdapter;
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
public static JoinConferenceDialog newInstance(String prefilledJid, List<String> accounts) {
|
|
|
|
JoinConferenceDialog dialog = new JoinConferenceDialog();
|
|
|
|
Bundle bundle = new Bundle();
|
|
|
|
bundle.putString(PREFILLED_JID_KEY, prefilledJid);
|
|
|
|
bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) accounts);
|
|
|
|
dialog.setArguments(bundle);
|
|
|
|
return dialog;
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
@Override
|
|
|
|
public void onActivityCreated(Bundle savedInstanceState) {
|
|
|
|
super.onActivityCreated(savedInstanceState);
|
|
|
|
setRetainInstance(true);
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
@NonNull
|
|
|
|
@Override
|
|
|
|
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
|
|
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
2019-02-06 13:45:51 +00:00
|
|
|
builder.setTitle(R.string.join_public_channel);
|
2018-04-01 07:18:12 +00:00
|
|
|
DialogJoinConferenceBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.dialog_join_conference, null, false);
|
2019-02-06 13:45:51 +00:00
|
|
|
DelayedHintHelper.setHint(R.string.channel_full_jid_example, binding.jid);
|
2018-03-14 09:07:52 +00:00
|
|
|
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();
|
2019-09-24 15:29:34 +00:00
|
|
|
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.accountJidLayout, binding.jid, binding.bookmark.isChecked()));
|
2019-01-10 21:09:20 +00:00
|
|
|
binding.jid.setOnEditorActionListener((v, actionId, event) -> {
|
2019-09-24 15:29:34 +00:00
|
|
|
mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.accountJidLayout, binding.jid, binding.bookmark.isChecked());
|
2019-01-10 21:09:20 +00:00
|
|
|
return true;
|
|
|
|
});
|
2018-03-14 09:07:52 +00:00
|
|
|
return dialog;
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
@Override
|
|
|
|
public void onBackendConnected() {
|
|
|
|
refreshKnownHosts();
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
private void refreshKnownHosts() {
|
|
|
|
Activity activity = getActivity();
|
|
|
|
if (activity instanceof XmppActivity) {
|
|
|
|
Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownConferenceHosts();
|
|
|
|
this.knownHostsAdapter.refresh(hosts);
|
|
|
|
}
|
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2018-03-14 09:07:52 +00:00
|
|
|
@Override
|
|
|
|
public void onAttach(Context context) {
|
|
|
|
super.onAttach(context);
|
|
|
|
try {
|
|
|
|
mListener = (JoinConferenceDialogListener) context;
|
|
|
|
} catch (ClassCastException e) {
|
|
|
|
throw new ClassCastException(context.toString()
|
|
|
|
+ " must implement JoinConferenceDialogListener");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDestroyView() {
|
|
|
|
Dialog dialog = getDialog();
|
|
|
|
if (dialog != null && getRetainInstance()) {
|
|
|
|
dialog.setDismissMessage(null);
|
|
|
|
}
|
|
|
|
super.onDestroyView();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onStart() {
|
|
|
|
super.onStart();
|
|
|
|
final Activity activity = getActivity();
|
|
|
|
if (activity instanceof XmppActivity && ((XmppActivity) activity).xmppConnectionService != null) {
|
|
|
|
refreshKnownHosts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface JoinConferenceDialogListener {
|
2019-09-24 15:29:34 +00:00
|
|
|
void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, TextInputLayout jidLayout, AutoCompleteTextView jid, boolean isBookmarkChecked);
|
2018-03-14 09:07:52 +00:00
|
|
|
}
|
2018-03-12 09:42:01 +00:00
|
|
|
}
|