dynamically get known hosts in dialog

This commit is contained in:
Daniel Gultsch 2018-03-14 10:07:52 +01:00
parent 2af12afb64
commit acf0b995ab
7 changed files with 172 additions and 109 deletions

View file

@ -4,25 +4,18 @@ import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.text.Editable; import android.text.Editable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.xmpp.OnUpdateBlocklist; import eu.siacs.conversations.xmpp.OnUpdateBlocklist;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist { public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist {
private Collection<String> mKnownHosts = new ArrayList<>();
private Account account = null; private Account account = null;
@ -45,7 +38,10 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
} }
} }
filterContacts(); filterContacts();
this.mKnownHosts = xmppConnectionService.getKnownHosts(); Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (fragment != null && fragment instanceof OnBackendConnected) {
((OnBackendConnected) fragment).onBackendConnected();
}
} }
@Override @Override
@ -71,9 +67,12 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
} }
ft.addToBackStack(null); ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance( EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts, null, null,
getString(R.string.block_jabber_id), getString(R.string.block), getString(R.string.block_jabber_id),
null, account.getJid().asBareJid().toString(), true getString(R.string.block),
null,
account.getJid().asBareJid().toString(),
true
); );
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> { dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {

View file

@ -19,7 +19,6 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView; import android.widget.ListView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -32,6 +31,7 @@ import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.ListItem; import eu.siacs.conversations.entities.ListItem;
import eu.siacs.conversations.entities.MucOptions; import eu.siacs.conversations.entities.MucOptions;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.util.ActivityResult; import eu.siacs.conversations.ui.util.ActivityResult;
import eu.siacs.conversations.ui.util.PendingItem; import eu.siacs.conversations.ui.util.PendingItem;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
@ -40,7 +40,6 @@ import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity { public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id"; public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
private List<String> mActivatedAccounts = new ArrayList<>(); private List<String> mActivatedAccounts = new ArrayList<>();
private Collection<String> mKnownHosts;
private Set<Contact> selected; private Set<Contact> selected;
private Set<String> filterContacts; private Set<String> filterContacts;
@ -240,7 +239,6 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
ft.addToBackStack(null); ft.addToBackStack(null);
Jid jid = uri == null ? null : uri.getJid(); Jid jid = uri == null ? null : uri.getJid();
EnterJidDialog dialog = EnterJidDialog.newInstance( EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts,
mActivatedAccounts, mActivatedAccounts,
getString(R.string.enter_contact), getString(R.string.enter_contact),
getString(R.string.select), getString(R.string.select),
@ -301,11 +299,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
} }
} }
} }
this.mKnownHosts = xmppConnectionService.getKnownHosts();
ActivityResult activityResult = this.postponedActivityResult.pop(); ActivityResult activityResult = this.postponedActivityResult.pop();
if (activityResult != null) { if (activityResult != null) {
handleActivityResult(activityResult); handleActivityResult(activityResult);
} }
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (fragment != null && fragment instanceof OnBackendConnected) {
((OnBackendConnected) fragment).onBackendConnected();
}
} }
@Override @Override

View file

@ -1,11 +1,13 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.Activity;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
@ -13,6 +15,7 @@ import android.widget.Spinner;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -20,10 +23,11 @@ import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.EnterJidDialogBinding; import eu.siacs.conversations.databinding.EnterJidDialogBinding;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.util.DelayedHintHelper; import eu.siacs.conversations.ui.util.DelayedHintHelper;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
public class EnterJidDialog extends DialogFragment{ public class EnterJidDialog extends DialogFragment implements OnBackendConnected {
private OnEnterJidDialogPositiveListener mListener = null; private OnEnterJidDialogPositiveListener mListener = null;
@ -33,21 +37,20 @@ public class EnterJidDialog extends DialogFragment{
private static final String ACCOUNT_KEY = "account"; private static final String ACCOUNT_KEY = "account";
private static final String ALLOW_EDIT_JID_KEY = "allow_edit_jid"; private static final String ALLOW_EDIT_JID_KEY = "allow_edit_jid";
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list"; private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
private static final String CONFERENCE_HOSTS_KEY = "known_conference_hosts";
public static EnterJidDialog newInstance( private KnownHostsAdapter knownHostsAdapter;
Collection<String> knownHosts, final List<String> activatedAccounts,
final String title, final String positiveButton, public static EnterJidDialog newInstance(final List<String> activatedAccounts,
final String prefilledJid, final String account, boolean allowEditJid) { final String title, final String positiveButton,
final String prefilledJid, final String account, boolean allowEditJid) {
EnterJidDialog dialog = new EnterJidDialog(); EnterJidDialog dialog = new EnterJidDialog();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(TITLE_KEY, title); bundle.putString(TITLE_KEY, title);
bundle.putString(POSITIVE_BUTTON_KEY, positiveButton); bundle.putString(POSITIVE_BUTTON_KEY, positiveButton);
bundle.putString(PREFILLED_JID_KEY, prefilledJid); bundle.putString(PREFILLED_JID_KEY, prefilledJid);
bundle.putString(ACCOUNT_KEY, account); bundle.putString(ACCOUNT_KEY, account);
bundle.putBoolean(ALLOW_EDIT_JID_KEY, allowEditJid); bundle.putBoolean(ALLOW_EDIT_JID_KEY, allowEditJid);
bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) activatedAccounts); bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) activatedAccounts);
bundle.putSerializable(CONFERENCE_HOSTS_KEY, (HashSet) knownHosts);
dialog.setArguments(bundle); dialog.setArguments(bundle);
return dialog; return dialog;
} }
@ -58,13 +61,23 @@ public class EnterJidDialog extends DialogFragment{
setRetainInstance(true); setRetainInstance(true);
} }
@Override
public void onStart() {
super.onStart();
final Activity activity = getActivity();
if (activity instanceof XmppActivity && ((XmppActivity) activity).xmppConnectionService != null) {
refreshKnownHosts();
}
}
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getArguments().getString(TITLE_KEY)); builder.setTitle(getArguments().getString(TITLE_KEY));
EnterJidDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.enter_jid_dialog, null, false); EnterJidDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.enter_jid_dialog, null, false);
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(this.knownHostsAdapter);
String prefilledJid = getArguments().getString(PREFILLED_JID_KEY); String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
if (prefilledJid != null) { if (prefilledJid != null) {
binding.jid.append(prefilledJid); binding.jid.append(prefilledJid);
@ -84,7 +97,7 @@ public class EnterJidDialog extends DialogFragment{
} else { } else {
ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(), ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
R.layout.simple_list_item, R.layout.simple_list_item,
new String[] { account }); new String[]{account});
binding.account.setEnabled(false); binding.account.setEnabled(false);
adapter.setDropDownViewResource(R.layout.simple_list_item); adapter.setDropDownViewResource(R.layout.simple_list_item);
binding.account.setAdapter(adapter); binding.account.setAdapter(adapter);
@ -117,12 +130,12 @@ public class EnterJidDialog extends DialogFragment{
return; return;
} }
if(mListener != null) { if (mListener != null) {
try { try {
if(mListener.onEnterJidDialogPositive(accountJid, contactJid)) { if (mListener.onEnterJidDialogPositive(accountJid, contactJid)) {
dialog.dismiss(); dialog.dismiss();
} }
} catch(JidError error) { } catch (JidError error) {
binding.jid.setError(error.toString()); binding.jid.setError(error.toString());
} }
} }
@ -136,6 +149,19 @@ public class EnterJidDialog extends DialogFragment{
this.mListener = listener; this.mListener = listener;
} }
@Override
public void onBackendConnected() {
refreshKnownHosts();
}
private void refreshKnownHosts() {
Activity activity = getActivity();
if (activity instanceof XmppActivity) {
Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownHosts();
this.knownHostsAdapter.refresh(hosts);
}
}
public interface OnEnterJidDialogPositiveListener { public interface OnEnterJidDialogPositiveListener {
boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError; boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError;
} }

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.app.Activity;
import android.app.Dialog; import android.app.Dialog;
import android.databinding.DataBindingUtil; import android.databinding.DataBindingUtil;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -22,79 +23,97 @@ import java.util.List;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.databinding.JoinConferenceDialogBinding; import eu.siacs.conversations.databinding.JoinConferenceDialogBinding;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.util.DelayedHintHelper; import eu.siacs.conversations.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 PREFILLED_JID_KEY = "prefilled_jid";
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list"; private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
private static final String CONFERENCE_HOSTS_KEY = "known_conference_hosts"; private JoinConferenceDialogListener mListener;
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(); JoinConferenceDialog dialog = new JoinConferenceDialog();
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString(PREFILLED_JID_KEY, prefilledJid); bundle.putString(PREFILLED_JID_KEY, prefilledJid);
bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) accounts); bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) accounts);
bundle.putSerializable(CONFERENCE_HOSTS_KEY, (HashSet) conferenceHosts); dialog.setArguments(bundle);
dialog.setArguments(bundle); return dialog;
return dialog; }
}
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
setRetainInstance(true); setRetainInstance(true);
} }
@NonNull @NonNull
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.dialog_title_join_conference); builder.setTitle(R.string.dialog_title_join_conference);
JoinConferenceDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.join_conference_dialog, null, false); JoinConferenceDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.join_conference_dialog, null, false);
DelayedHintHelper.setHint(R.string.conference_address_example, binding.jid); 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);
String prefilledJid = getArguments().getString(PREFILLED_JID_KEY); binding.jid.setAdapter(knownHostsAdapter);
if (prefilledJid != null) { String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
binding.jid.append(prefilledJid); if (prefilledJid != null) {
} binding.jid.append(prefilledJid);
StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account); }
builder.setView(binding.getRoot()); StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account);
builder.setPositiveButton(R.string.join, null); builder.setView(binding.getRoot());
builder.setNegativeButton(R.string.cancel, null); builder.setPositiveButton(R.string.join, null);
AlertDialog dialog = builder.create(); builder.setNegativeButton(R.string.cancel, null);
dialog.show(); AlertDialog dialog = builder.create();
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() { dialog.show();
@Override dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(view -> mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked()));
public void onClick(View view) { return dialog;
mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked()); }
}
});
return dialog;
}
public interface JoinConferenceDialogListener { @Override
void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked); public void onBackendConnected() {
} refreshKnownHosts();
}
@Override private void refreshKnownHosts() {
public void onAttach(Context context) { Activity activity = getActivity();
super.onAttach(context); if (activity instanceof XmppActivity) {
try { Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownConferenceHosts();
mListener = (JoinConferenceDialogListener) context; this.knownHostsAdapter.refresh(hosts);
} catch (ClassCastException e) { }
throw new ClassCastException(context.toString() }
+ " must implement JoinConferenceDialogListener");
}
}
@Override @Override
public void onDestroyView() { public void onAttach(Context context) {
Dialog dialog = getDialog(); super.onAttach(context);
if (dialog != null && getRetainInstance()) { try {
dialog.setDismissMessage(null); mListener = (JoinConferenceDialogListener) context;
} } catch (ClassCastException e) {
super.onDestroyView(); 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 {
void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked);
}
} }

View file

@ -35,6 +35,7 @@ import android.text.SpannableString;
import android.text.Spanned; import android.text.Spanned;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.style.TypefaceSpan; import android.text.style.TypefaceSpan;
import android.util.Log;
import android.util.Pair; import android.util.Pair;
import android.view.ContextMenu; import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo; import android.view.ContextMenu.ContextMenuInfo;
@ -76,6 +77,7 @@ import eu.siacs.conversations.entities.Presence;
import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate; import eu.siacs.conversations.services.XmppConnectionService.OnRosterUpdate;
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter; import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
import eu.siacs.conversations.ui.adapter.ListItemAdapter; import eu.siacs.conversations.ui.adapter.ListItemAdapter;
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
import eu.siacs.conversations.ui.service.EmojiService; import eu.siacs.conversations.ui.service.EmojiService;
import eu.siacs.conversations.ui.util.DelayedHintHelper; import eu.siacs.conversations.ui.util.DelayedHintHelper;
import eu.siacs.conversations.utils.XmppUri; import eu.siacs.conversations.utils.XmppUri;
@ -95,8 +97,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private List<ListItem> conferences = new ArrayList<>(); private List<ListItem> conferences = new ArrayList<>();
private ListItemAdapter mConferenceAdapter; private ListItemAdapter mConferenceAdapter;
private List<String> mActivatedAccounts = new ArrayList<>(); private List<String> mActivatedAccounts = new ArrayList<>();
private Collection<String> mKnownHosts;
private Collection<String> mKnownConferenceHosts;
private Invite mPendingInvite = null; private Invite mPendingInvite = null;
private EditText mSearchEditText; private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false); private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
@ -441,15 +441,18 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final Invite invite) { protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog"); Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) { if (prev != null) {
ft.remove(prev); ft.remove(prev);
} }
ft.addToBackStack(null); ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance( EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts, mActivatedAccounts, mActivatedAccounts,
getString(R.string.dialog_title_create_contact), getString(R.string.create), getString(R.string.dialog_title_create_contact),
prefilledJid, null, invite == null || !invite.hasFingerprints() getString(R.string.create),
prefilledJid,
null,
invite == null || !invite.hasFingerprints()
); );
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> { dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@ -480,30 +483,30 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
return true; return true;
} }
}); });
dialog.show(ft, "dialog"); dialog.show(ft, FRAGMENT_TAG_DIALOG);
} }
@SuppressLint("InflateParams") @SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) { protected void showJoinConferenceDialog(final String prefilledJid) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog"); Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) { if (prev != null) {
ft.remove(prev); ft.remove(prev);
} }
ft.addToBackStack(null); ft.addToBackStack(null);
JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts, mKnownConferenceHosts); JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts);
joinConferenceFragment.show(ft, "dialog"); joinConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
} }
private void showCreateConferenceDialog() { private void showCreateConferenceDialog() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog"); Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) { if (prev != null) {
ft.remove(prev); ft.remove(prev);
} }
ft.addToBackStack(null); ft.addToBackStack(null);
CreateConferenceDialog createConferenceFragment = CreateConferenceDialog.newInstance(mActivatedAccounts); CreateConferenceDialog createConferenceFragment = CreateConferenceDialog.newInstance(mActivatedAccounts);
createConferenceFragment.show(ft, "dialog"); createConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
} }
private Account getSelectedAccount(Spinner spinner) { private Account getSelectedAccount(Spinner spinner) {
@ -707,8 +710,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
ab.setDisplayHomeAsUpEnabled(false); ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false); ab.setHomeButtonEnabled(false);
} }
this.mKnownHosts = xmppConnectionService.getKnownHosts();
this.mKnownConferenceHosts = xmppConnectionService.getKnownConferenceHosts();
if (this.mPendingInvite != null) { if (this.mPendingInvite != null) {
mPendingInvite.invite(); mPendingInvite.invite();
this.mPendingInvite = null; this.mPendingInvite = null;
@ -723,6 +724,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
filter(null); filter(null);
} }
setIntent(null); setIntent(null);
Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (fragment != null && fragment instanceof OnBackendConnected) {
Log.d(Config.LOGTAG,"calling on backend connected on dialog");
((OnBackendConnected) fragment).onBackendConnected();
}
} }
protected boolean handleIntent(Intent intent) { protected boolean handleIntent(Intent intent) {

View file

@ -87,6 +87,8 @@ public abstract class XmppActivity extends AppCompatActivity {
protected int mColorOrange; protected int mColorOrange;
protected int mColorGreen; protected int mColorGreen;
protected static final String FRAGMENT_TAG_DIALOG = "dialog";
private boolean isCameraFeatureAvailable = false; private boolean isCameraFeatureAvailable = false;
protected boolean mUseSubject = true; protected boolean mUseSubject = true;

View file

@ -64,6 +64,16 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
domains = new ArrayList<>(mKnownHosts); domains = new ArrayList<>(mKnownHosts);
} }
public KnownHostsAdapter(Context context, int viewResourceId) {
super(context, viewResourceId, new ArrayList<>());
domains = new ArrayList<>();
}
public void refresh(Collection<String> knownHosts) {
domains = new ArrayList<>(knownHosts);
notifyDataSetChanged();
}
@Override @Override
@NonNull @NonNull
public Filter getFilter() { public Filter getFilter() {