From 449f09c9754a0a29c52db2c7c7fa46f4c1392427 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 15 Nov 2019 21:53:21 +0100 Subject: fix duplicate accounts in EnterJidDialog --- .../messenger/services/XmppConnectionService.java | 2 +- .../de/pixart/messenger/ui/EnterJidDialog.java | 66 +++++++++++----------- .../messenger/ui/StartConversationActivity.java | 14 +---- 3 files changed, 36 insertions(+), 46 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index ecf7d68b5..a65c8ef1b 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -4506,7 +4506,7 @@ public class XmppConnectionService extends Service { for (final Contact contact : account.getRoster().getContacts()) { if (contact.showInRoster()) { final String server = contact.getServer(); - if (server != null && !hosts.contains(server)) { + if (server != null) { hosts.add(server); } } diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java index 2b9a6b8e3..6a7b1e98b 100644 --- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java +++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java @@ -2,16 +2,17 @@ package de.pixart.messenger.ui; import android.app.Activity; import android.app.Dialog; -import androidx.databinding.DataBindingUtil; import android.os.Bundle; -import androidx.annotation.NonNull; -import androidx.fragment.app.DialogFragment; -import androidx.appcompat.app.AlertDialog; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.ArrayAdapter; +import androidx.annotation.NonNull; +import androidx.appcompat.app.AlertDialog; +import androidx.databinding.DataBindingUtil; +import androidx.fragment.app.DialogFragment; + import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -28,7 +29,11 @@ import rocks.xmpp.addr.Jid; public class EnterJidDialog extends DialogFragment implements OnBackendConnected, TextWatcher { + private static final List SUSPICIOUS_DOMAINS = Arrays.asList("conference", "muc", "room", "rooms", "chat"); + + private OnEnterJidDialogPositiveListener mListener = null; + private static final String TITLE_KEY = "title"; private static final String POSITIVE_BUTTON_KEY = "positive_button"; private static final String PREFILLED_JID_KEY = "prefilled_jid"; @@ -38,12 +43,9 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list"; private static final String SANITY_CHECK_JID = "sanity_check_jid"; - private OnEnterJidDialogPositiveListener mListener = null; - private KnownHostsAdapter knownHostsAdapter; private Collection whitelistedDomains = Collections.emptyList(); - private EnterJidDialogBinding binding; private AlertDialog dialog; private boolean sanityCheckJid = false; @@ -101,7 +103,6 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected binding.jid.setCursorVisible(false); } } - sanityCheckJid = getArguments().getBoolean(SANITY_CHECK_JID, false); DelayedHintHelper.setHint(R.string.account_settings_example_jabber_id, binding.jid); @@ -135,6 +136,7 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected View.OnClickListener dialogOnClick = v -> { handleEnter(binding, account); }; + binding.jid.setOnEditorActionListener((v, actionId, event) -> { handleEnter(binding, account); return true; @@ -195,25 +197,6 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected } } - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - - } - - @Override - public void afterTextChanged(Editable s) { - if (issuedWarning) { - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add); - binding.jidLayout.setError(null); - issuedWarning = false; - } - } - public void setOnEnterJidDialogPositiveListener(OnEnterJidDialogPositiveListener listener) { this.mListener = listener; } @@ -233,12 +216,22 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected } @Override - public void onDestroyView() { - Dialog dialog = getDialog(); - if (dialog != null && getRetainInstance()) { - dialog.setDismissMessage(null); + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + + } + + @Override + public void afterTextChanged(Editable s) { + if (issuedWarning) { + dialog.getButton(AlertDialog.BUTTON_POSITIVE).setText(R.string.add); + binding.jidLayout.setError(null); + issuedWarning = false; } - super.onDestroyView(); } public interface OnEnterJidDialogPositiveListener { @@ -257,6 +250,15 @@ public class EnterJidDialog extends DialogFragment implements OnBackendConnected } } + @Override + public void onDestroyView() { + Dialog dialog = getDialog(); + if (dialog != null && getRetainInstance()) { + dialog.setDismissMessage(null); + } + super.onDestroyView(); + } + private boolean suspiciousSubDomain(String domain) { if (this.whitelistedDomains.contains(domain)) { return false; diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 4cfd752b6..cabdfc8fa 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -51,7 +51,6 @@ import androidx.viewpager.widget.ViewPager; import com.google.android.material.textfield.TextInputLayout; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; @@ -215,9 +214,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne spinner.setAdapter(adapter); spinner.setEnabled(true); } else { - ArrayAdapter adapter = new ArrayAdapter<>(context, - R.layout.simple_list_item, - Arrays.asList(context.getString(R.string.no_accounts))); + ArrayAdapter adapter = new ArrayAdapter<>(context, R.layout.simple_list_item, Collections.singletonList(context.getString(R.string.no_accounts))); adapter.setDropDownViewResource(R.layout.simple_list_item); spinner.setAdapter(adapter); spinner.setEnabled(false); @@ -776,15 +773,6 @@ public class StartConversationActivity extends XmppActivity implements XmppConne this.mPostponedActivityResult = null; } this.mActivatedAccounts.addAll(AccountUtils.getEnabledAccounts(xmppConnectionService)); - for (Account account : xmppConnectionService.getAccounts()) { - if (account.getStatus() != Account.State.DISABLED) { - if (Config.DOMAIN_LOCK != null) { - this.mActivatedAccounts.add(account.getJid().getLocal()); - } else { - this.mActivatedAccounts.add(account.getJid().asBareJid().toString()); - } - } - } configureHomeButton(); Intent intent = pendingViewIntent.pop(); if (intent != null && processViewIntent(intent)) { -- cgit v1.2.3