aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2019-06-08 14:17:01 +0200
committerChristian Schneppe <christian@pix-art.de>2019-06-08 14:17:01 +0200
commit48b484ca4c81e9916ebde24a71dabd2e99fbfb22 (patch)
treef45d02a275f8eaa4afc306457fcc3cd8d1702a87 /src/main/java/de/pixart/messenger
parent76e1e86165e6d7fc6850d4be0bd8624c9bd3b8c0 (diff)
show error messages in text layout not edittext
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/EnterJidDialog.java20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
index 5375c7373..05b234e6f 100644
--- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
@@ -15,6 +15,7 @@ import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.List;
import de.pixart.messenger.Config;
@@ -40,6 +41,8 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
private OnEnterJidDialogPositiveListener mListener = null;
private KnownHostsAdapter knownHostsAdapter;
+ private Collection<String> whitelistedDomains = Collections.emptyList();
+
private EnterJidDialogBinding binding;
private AlertDialog dialog;
@@ -160,19 +163,19 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
try {
contactJid = Jid.of(binding.jid.getText().toString());
} catch (final IllegalArgumentException e) {
- binding.jid.setError(getActivity().getString(R.string.invalid_jid));
+ binding.jidLayout.setError(getActivity().getString(R.string.invalid_jid));
return;
}
if (!issuedWarning && sanityCheckJid) {
if (contactJid.isDomainJid()) {
- binding.jid.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())) {
- binding.jid.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;
@@ -185,7 +188,9 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
dialog.dismiss();
}
} catch (JidError error) {
- binding.jid.setError(error.toString());
+ binding.jidLayout.setError(error.toString());
+ dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add);
+ issuedWarning = false;
}
}
}
@@ -204,6 +209,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
public void afterTextChanged(Editable s) {
if (issuedWarning) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add);
+ binding.jidLayout.setError(null);
issuedWarning = false;
}
}
@@ -222,6 +228,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
if (activity instanceof XmppActivity) {
Collection<String> hosts = ((XmppActivity) activity).xmppConnectionService.getKnownHosts();
this.knownHostsAdapter.refresh(hosts);
+ this.whitelistedDomains = hosts;
}
}
@@ -250,7 +257,10 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected
}
}
- private static boolean suspiciousSubDomain(String domain) {
+ private boolean suspiciousSubDomain(String domain) {
+ if (this.whitelistedDomains.contains(domain)) {
+ return false;
+ }
final String[] parts = domain.split("\\.");
return parts.length >= 3 && SUSPICIOUS_DOMAINS.contains(parts[0]);
}