aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-08 20:41:28 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-08 20:41:28 +0200
commit7f7d8b8fcd776a1a3eab5e38f924c55246d4dd1c (patch)
tree5475af912e571299c311b328b88f664617b8a797 /src/main/java/de/pixart/messenger
parent8886fade18b64d128aaa4b4bc0600f6afe964bd2 (diff)
dynamically get known hosts in dialog
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java19
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java9
-rw-r--r--src/main/java/de/pixart/messenger/ui/EnterJidDialog.java41
-rw-r--r--src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java44
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java36
-rw-r--r--src/main/java/de/pixart/messenger/ui/XmppActivity.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java11
7 files changed, 114 insertions, 48 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index c4d077c80..7163f77cc 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -6,18 +6,16 @@ import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.widget.Toast;
-import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import de.pixart.messenger.R;
import de.pixart.messenger.entities.Account;
import de.pixart.messenger.entities.Contact;
+import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import rocks.xmpp.addr.Jid;
public class BlocklistActivity extends AbstractSearchableListItemActivity implements OnUpdateBlocklist {
- private Collection<String> mKnownHosts = new ArrayList<>();
private Account account = null;
@Override
@@ -39,7 +37,10 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
}
}
filterContacts();
- this.mKnownHosts = xmppConnectionService.getKnownHosts();
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
+ if (fragment != null && fragment instanceof OnBackendConnected) {
+ ((OnBackendConnected) fragment).onBackendConnected();
+ }
}
@Override
@@ -65,9 +66,13 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
}
ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance(
- mKnownHosts, null,
- getString(R.string.block_jabber_id), getString(R.string.block),
- null, account.getJid().asBareJid().toString(), true, xmppConnectionService.multipleAccounts()
+ null,
+ getString(R.string.block_jabber_id),
+ getString(R.string.block),
+ null,
+ account.getJid().asBareJid().toString(),
+ true,
+ xmppConnectionService.multipleAccounts()
);
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index 46a60ef8c..a212ef78a 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -19,7 +19,6 @@ import android.widget.AbsListView.MultiChoiceModeListener;
import android.widget.ListView;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
@@ -32,6 +31,7 @@ import de.pixart.messenger.entities.Contact;
import de.pixart.messenger.entities.Conversation;
import de.pixart.messenger.entities.ListItem;
import de.pixart.messenger.entities.MucOptions;
+import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.ui.util.ActivityResult;
import de.pixart.messenger.ui.util.PendingItem;
import de.pixart.messenger.utils.XmppUri;
@@ -40,7 +40,6 @@ import rocks.xmpp.addr.Jid;
public class ChooseContactActivity extends AbstractSearchableListItemActivity {
public static final String EXTRA_TITLE_RES_ID = "extra_title_res_id";
private List<String> mActivatedAccounts = new ArrayList<>();
- private Collection<String> mKnownHosts;
private Set<Contact> selected;
private Set<String> filterContacts;
@@ -241,7 +240,6 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
ft.addToBackStack(null);
Jid jid = uri == null ? null : uri.getJid();
EnterJidDialog dialog = EnterJidDialog.newInstance(
- mKnownHosts,
mActivatedAccounts,
getString(R.string.enter_contact),
getString(R.string.select),
@@ -304,11 +302,14 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
}
}
- this.mKnownHosts = xmppConnectionService.getKnownHosts();
ActivityResult activityResult = this.postponedActivityResult.pop();
if (activityResult != null) {
handleActivityResult(activityResult);
}
+ Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
+ if (fragment != null && fragment instanceof OnBackendConnected) {
+ ((OnBackendConnected) fragment).onBackendConnected();
+ }
}
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
index 26e9017f9..d0c7980fd 100644
--- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
@@ -1,5 +1,6 @@
package de.pixart.messenger.ui;
+import android.app.Activity;
import android.app.Dialog;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
@@ -11,17 +12,17 @@ import android.widget.ArrayAdapter;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashSet;
import java.util.List;
import de.pixart.messenger.Config;
import de.pixart.messenger.R;
import de.pixart.messenger.databinding.EnterJidDialogBinding;
import de.pixart.messenger.ui.adapter.KnownHostsAdapter;
+import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.ui.util.DelayedHintHelper;
import rocks.xmpp.addr.Jid;
-public class EnterJidDialog extends DialogFragment {
+public class EnterJidDialog extends DialogFragment implements OnBackendConnected {
private static final String TITLE_KEY = "title";
private static final String POSITIVE_BUTTON_KEY = "positive_button";
@@ -30,13 +31,13 @@ public class EnterJidDialog extends DialogFragment {
private static final String ALLOW_EDIT_JID_KEY = "allow_edit_jid";
private static final String MULTIPLE_ACCOUNTS = "multiple_accounts_enabled";
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
- private static final String CONFERENCE_HOSTS_KEY = "known_conference_hosts";
private OnEnterJidDialogPositiveListener mListener = null;
- public static EnterJidDialog newInstance(
- Collection<String> knownHosts, final List<String> activatedAccounts,
- final String title, final String positiveButton,
- final String prefilledJid, final String account, boolean allowEditJid, boolean multipleAccounts) {
+ private KnownHostsAdapter knownHostsAdapter;
+
+ public static EnterJidDialog newInstance(final List<String> activatedAccounts,
+ final String title, final String positiveButton,
+ final String prefilledJid, final String account, boolean allowEditJid, boolean multipleAccounts) {
EnterJidDialog dialog = new EnterJidDialog();
Bundle bundle = new Bundle();
bundle.putString(TITLE_KEY, title);
@@ -46,7 +47,6 @@ public class EnterJidDialog extends DialogFragment {
bundle.putBoolean(ALLOW_EDIT_JID_KEY, allowEditJid);
bundle.putBoolean(MULTIPLE_ACCOUNTS, multipleAccounts);
bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) activatedAccounts);
- bundle.putSerializable(CONFERENCE_HOSTS_KEY, (HashSet) knownHosts);
dialog.setArguments(bundle);
return dialog;
}
@@ -57,13 +57,23 @@ public class EnterJidDialog extends DialogFragment {
setRetainInstance(true);
}
+ @Override
+ public void onStart() {
+ super.onStart();
+ final Activity activity = getActivity();
+ if (activity instanceof XmppActivity && ((XmppActivity) activity).xmppConnectionService != null) {
+ refreshKnownHosts();
+ }
+ }
+
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getArguments().getString(TITLE_KEY));
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);
if (prefilledJid != null) {
binding.jid.append(prefilledJid);
@@ -145,6 +155,19 @@ public class EnterJidDialog extends DialogFragment {
}
@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);
+ }
+ }
+
+ @Override
public void onDestroyView() {
Dialog dialog = getDialog();
if (dialog != null && getRetainInstance()) {
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);
}
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index ed1612044..f5abf2239 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -29,6 +29,7 @@ import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextWatcher;
import android.text.style.TypefaceSpan;
+import android.util.Log;
import android.util.Pair;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
@@ -51,7 +52,6 @@ import android.widget.Toast;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -68,6 +68,7 @@ import de.pixart.messenger.entities.Presence;
import de.pixart.messenger.services.EmojiService;
import de.pixart.messenger.services.XmppConnectionService.OnRosterUpdate;
import de.pixart.messenger.ui.adapter.ListItemAdapter;
+import de.pixart.messenger.ui.interfaces.OnBackendConnected;
import de.pixart.messenger.utils.XmppUri;
import de.pixart.messenger.xmpp.OnUpdateBlocklist;
import de.pixart.messenger.xmpp.XmppConnection;
@@ -87,8 +88,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
private List<ListItem> conferences = new ArrayList<>();
private ListItemAdapter mConferenceAdapter;
private List<String> mActivatedAccounts = new ArrayList<>();
- private Collection<String> mKnownHosts;
- private Collection<String> mKnownConferenceHosts;
private Invite mPendingInvite = null;
private EditText mSearchEditText;
private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false);
@@ -433,15 +432,19 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
@SuppressLint("InflateParams")
protected void showCreateContactDialog(final String prefilledJid, final Invite invite) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance(
- mKnownHosts, mActivatedAccounts,
- getString(R.string.create_contact), getString(R.string.create),
- prefilledJid, null, invite == null || !invite.hasFingerprints(), xmppConnectionService.multipleAccounts()
+ mActivatedAccounts,
+ getString(R.string.create_contact),
+ getString(R.string.create),
+ prefilledJid,
+ null,
+ invite == null || !invite.hasFingerprints(),
+ xmppConnectionService.multipleAccounts()
);
dialog.setOnEnterJidDialogPositiveListener((accountJid, contactJid) -> {
@@ -473,30 +476,30 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
});
- dialog.show(ft, "dialog");
+ dialog.show(ft, FRAGMENT_TAG_DIALOG);
}
@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
- JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts, mKnownConferenceHosts);
- joinConferenceFragment.show(ft, "dialog");
+ JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts);
+ joinConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
}
private void showCreateConferenceDialog() {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
- Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ Fragment prev = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG_DIALOG);
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
CreateConferenceDialog createConferenceFragment = CreateConferenceDialog.newInstance(mActivatedAccounts);
- createConferenceFragment.show(ft, "dialog");
+ createConferenceFragment.show(ft, FRAGMENT_TAG_DIALOG);
}
private Account getSelectedAccount(Spinner spinner) {
@@ -705,8 +708,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
ab.setDisplayHomeAsUpEnabled(false);
ab.setHomeButtonEnabled(false);
}
- this.mKnownHosts = xmppConnectionService.getKnownHosts();
- this.mKnownConferenceHosts = xmppConnectionService.getKnownConferenceHosts();
if (this.mPendingInvite != null) {
mPendingInvite.invite();
this.mPendingInvite = null;
@@ -721,6 +722,11 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
filter(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) {
diff --git a/src/main/java/de/pixart/messenger/ui/XmppActivity.java b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
index 5e2e4856b..48ddf8fdf 100644
--- a/src/main/java/de/pixart/messenger/ui/XmppActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/XmppActivity.java
@@ -100,6 +100,8 @@ public abstract class XmppActivity extends AppCompatActivity {
protected int mColorOrange;
protected int mColorGreen;
+ protected static final String FRAGMENT_TAG_DIALOG = "dialog";
+
private boolean isCameraFeatureAvailable = false;
protected boolean mUseSubject = true;
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
index 59255accd..9f4a52d95 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/KnownHostsAdapter.java
@@ -68,6 +68,7 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
} else {
domains = new ArrayList<>(mKnownHosts);
}
+
HashSet<String> hashSet = new HashSet<>();
// get servers from https://conversations.im/compliance/
@@ -197,6 +198,16 @@ public class KnownHostsAdapter extends ArrayAdapter<String> {
}).start();
}
+ 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
@NonNull
public Filter getFilter() {