diff options
Diffstat (limited to '')
-rw-r--r-- | src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java index e232ec813..21b6ff743 100644 --- a/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java +++ b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java @@ -1,5 +1,6 @@ package de.pixart.messenger.ui; +import android.app.Activity; import android.app.Dialog; import android.content.Context; import android.content.DialogInterface; @@ -14,29 +15,28 @@ import android.widget.Spinner; import java.util.ArrayList; import java.util.Collection; -import java.util.HashSet; import java.util.List; import de.pixart.messenger.R; import de.pixart.messenger.databinding.JoinConferenceDialogBinding; import de.pixart.messenger.services.XmppConnectionService; import de.pixart.messenger.ui.adapter.KnownHostsAdapter; +import de.pixart.messenger.ui.interfaces.OnBackendConnected; import de.pixart.messenger.ui.util.DelayedHintHelper; -public class JoinConferenceDialog extends DialogFragment { +public class JoinConferenceDialog extends DialogFragment implements OnBackendConnected { private static final String PREFILLED_JID_KEY = "prefilled_jid"; private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list"; - private static final String CONFERENCE_HOSTS_KEY = "known_conference_hosts"; - private JoinConferenceDialogListener mListener; public XmppConnectionService xmppConnectionService; + private JoinConferenceDialogListener mListener; + private KnownHostsAdapter knownHostsAdapter; - public static JoinConferenceDialog newInstance(String prefilledJid, List<String> accounts, Collection<String> conferenceHosts) { + 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); - bundle.putSerializable(CONFERENCE_HOSTS_KEY, (HashSet) conferenceHosts); dialog.setArguments(bundle); return dialog; } @@ -54,7 +54,8 @@ public class JoinConferenceDialog extends DialogFragment { builder.setTitle(R.string.join_conference); JoinConferenceDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.join_conference_dialog, null, false); DelayedHintHelper.setHint(R.string.conference_address_example, binding.jid); - binding.jid.setAdapter(new KnownHostsAdapter(getActivity(), R.layout.simple_list_item, (Collection<String>) getArguments().getSerializable(CONFERENCE_HOSTS_KEY))); + 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); @@ -72,16 +73,24 @@ public class JoinConferenceDialog extends DialogFragment { builder.setNegativeButton(R.string.cancel, null); AlertDialog dialog = builder.create(); dialog.show(); - dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked()); - } - }); + dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked())); return dialog; } @Override + public void onBackendConnected() { + refreshKnownHosts(); + } + + private void refreshKnownHosts() { + Activity activity = getActivity(); + if (activity instanceof XmppActivity) { + Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownConferenceHosts(); + this.knownHostsAdapter.refresh(hosts); + } + } + + @Override public void onAttach(Context context) { super.onAttach(context); try { @@ -101,6 +110,15 @@ public class JoinConferenceDialog extends DialogFragment { super.onDestroyView(); } + @Override + public void onStart() { + super.onStart(); + final Activity activity = getActivity(); + if (activity instanceof XmppActivity && ((XmppActivity) activity).xmppConnectionService != null) { + refreshKnownHosts(); + } + } + public interface JoinConferenceDialogListener { void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked); } |