fix rare npe
This commit is contained in:
parent
0b470534f1
commit
4129ca6af8
|
@ -22,6 +22,7 @@ import java.util.List;
|
|||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.EnterJidDialogBinding;
|
||||
import eu.siacs.conversations.services.XmppConnectionService;
|
||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.ui.interfaces.OnBackendConnected;
|
||||
import eu.siacs.conversations.ui.util.DelayedHintHelper;
|
||||
|
@ -29,8 +30,8 @@ import eu.siacs.conversations.xmpp.Jid;
|
|||
|
||||
public class EnterJidDialog extends DialogFragment implements OnBackendConnected, TextWatcher {
|
||||
|
||||
|
||||
private static final List<String> SUSPICIOUS_DOMAINS = Arrays.asList("conference","muc","room","rooms","chat");
|
||||
private static final List<String> SUSPICIOUS_DOMAINS =
|
||||
Arrays.asList("conference", "muc", "room", "rooms", "chat");
|
||||
|
||||
private OnEnterJidDialogPositiveListener mListener = null;
|
||||
|
||||
|
@ -49,13 +50,16 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
private AlertDialog dialog;
|
||||
private boolean sanityCheckJid = false;
|
||||
|
||||
|
||||
private boolean issuedWarning = false;
|
||||
|
||||
public static EnterJidDialog newInstance(final List<String> activatedAccounts,
|
||||
final String title, final String positiveButton,
|
||||
final String prefilledJid, final String account,
|
||||
boolean allowEditJid, final boolean sanity_check_jid) {
|
||||
public static EnterJidDialog newInstance(
|
||||
final List<String> activatedAccounts,
|
||||
final String title,
|
||||
final String positiveButton,
|
||||
final String prefilledJid,
|
||||
final String account,
|
||||
boolean allowEditJid,
|
||||
final boolean sanity_check_jid) {
|
||||
EnterJidDialog dialog = new EnterJidDialog();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(TITLE_KEY, title);
|
||||
|
@ -79,7 +83,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
public void onStart() {
|
||||
super.onStart();
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof XmppActivity && ((XmppActivity) activity).xmppConnectionService != null) {
|
||||
if (activity instanceof XmppActivity
|
||||
&& ((XmppActivity) activity).xmppConnectionService != null) {
|
||||
refreshKnownHosts();
|
||||
}
|
||||
}
|
||||
|
@ -89,7 +94,9 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
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);
|
||||
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);
|
||||
|
@ -109,28 +116,31 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
|
||||
String account = getArguments().getString(ACCOUNT_KEY);
|
||||
if (account == null) {
|
||||
StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account);
|
||||
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});
|
||||
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 -> {
|
||||
View.OnClickListener dialogOnClick =
|
||||
v -> {
|
||||
handleEnter(binding, account);
|
||||
};
|
||||
|
||||
binding.jid.setOnEditorActionListener((v, actionId, event) -> {
|
||||
binding.jid.setOnEditorActionListener(
|
||||
(v, actionId, event) -> {
|
||||
handleEnter(binding, account);
|
||||
return true;
|
||||
});
|
||||
|
@ -147,7 +157,11 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
}
|
||||
try {
|
||||
if (Config.DOMAIN_LOCK != null) {
|
||||
accountJid = Jid.ofEscaped((String) binding.account.getSelectedItem(), Config.DOMAIN_LOCK, null);
|
||||
accountJid =
|
||||
Jid.ofEscaped(
|
||||
(String) binding.account.getSelectedItem(),
|
||||
Config.DOMAIN_LOCK,
|
||||
null);
|
||||
} else {
|
||||
accountJid = Jid.ofEscaped((String) binding.account.getSelectedItem());
|
||||
}
|
||||
|
@ -164,13 +178,15 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
|
||||
if (!issuedWarning && sanityCheckJid) {
|
||||
if (contactJid.isDomainJid()) {
|
||||
binding.jidLayout.setError(getActivity().getString(R.string.this_looks_like_a_domain));
|
||||
binding.jidLayout.setError(
|
||||
getActivity().getString(R.string.this_looks_like_a_domain));
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add_anway);
|
||||
issuedWarning = true;
|
||||
return;
|
||||
}
|
||||
if (suspiciousSubDomain(contactJid.getDomain().toEscapedString())) {
|
||||
binding.jidLayout.setError(getActivity().getString(R.string.this_looks_like_channel));
|
||||
binding.jidLayout.setError(
|
||||
getActivity().getString(R.string.this_looks_like_channel));
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add_anway);
|
||||
issuedWarning = true;
|
||||
return;
|
||||
|
@ -200,23 +216,23 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
}
|
||||
|
||||
private void refreshKnownHosts() {
|
||||
Activity activity = getActivity();
|
||||
final Activity activity = getActivity();
|
||||
if (activity instanceof XmppActivity) {
|
||||
Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownHosts();
|
||||
final XmppConnectionService service = ((XmppActivity) activity).xmppConnectionService;
|
||||
if (service == null) {
|
||||
return;
|
||||
}
|
||||
final Collection<String> hosts = service.getKnownHosts();
|
||||
this.knownHostsAdapter.refresh(hosts);
|
||||
this.whitelistedDomains = hosts;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
|
@ -238,6 +254,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
|
|||
this.msg = msg;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return msg;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue