diff options
Diffstat (limited to '')
3 files changed, 274 insertions, 116 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java b/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java new file mode 100644 index 000000000..c872ccb2f --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java @@ -0,0 +1,94 @@ +package de.pixart.messenger.ui; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.EditText; +import android.widget.Spinner; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.List; + +import de.pixart.messenger.R; +import de.pixart.messenger.services.XmppConnectionService; + + +public class CreateConferenceDialog extends DialogFragment { + + private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list"; + private CreateConferenceDialogListener mListener; + public XmppConnectionService xmppConnectionService; + + public static CreateConferenceDialog newInstance(List<String> accounts) { + CreateConferenceDialog dialog = new CreateConferenceDialog(); + Bundle bundle = new Bundle(); + bundle.putStringArrayList(ACCOUNTS_LIST_KEY, (ArrayList<String>) accounts); + dialog.setArguments(bundle); + return dialog; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + setRetainInstance(true); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.create_conference); + final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.create_conference_dialog, null); + final TextView yourAccount = dialogView.findViewById(R.id.your_account); + final Spinner spinner = dialogView.findViewById(R.id.account); + final EditText subject = dialogView.findViewById(R.id.subject); + if (xmppConnectionService != null && xmppConnectionService.multipleAccounts()) { + yourAccount.setVisibility(View.VISIBLE); + spinner.setVisibility(View.VISIBLE); + } else { + yourAccount.setVisibility(View.GONE); + spinner.setVisibility(View.GONE); + } + ArrayList<String> mActivatedAccounts = getArguments().getStringArrayList(ACCOUNTS_LIST_KEY); + StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, spinner); + builder.setView(dialogView); + builder.setPositiveButton(R.string.choose_participants, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + mListener.onCreateDialogPositiveClick(spinner, subject.getText().toString()); + } + }); + builder.setNegativeButton(R.string.cancel, null); + return builder.create(); + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + try { + mListener = (CreateConferenceDialogListener) context; + } catch (ClassCastException e) { + throw new ClassCastException(context.toString() + + " must implement CreateConferenceDialogListener"); + } + } + + @Override + public void onDestroyView() { + Dialog dialog = getDialog(); + if (dialog != null && getRetainInstance()) { + dialog.setDismissMessage(null); + } + super.onDestroyView(); + } + + public interface CreateConferenceDialogListener { + void onCreateDialogPositiveClick(Spinner spinner, String subject); + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java new file mode 100644 index 000000000..ec806236f --- /dev/null +++ b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java @@ -0,0 +1,113 @@ +package de.pixart.messenger.ui; + +import android.app.Dialog; +import android.content.Context; +import android.content.DialogInterface; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.DialogFragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.AutoCompleteTextView; +import android.widget.CheckBox; +import android.widget.Checkable; +import android.widget.Spinner; +import android.widget.TextView; + +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.services.XmppConnectionService; +import de.pixart.messenger.ui.adapter.KnownHostsAdapter; +import de.pixart.messenger.ui.util.DelayedHintHelper; + +public class JoinConferenceDialog extends DialogFragment { + + 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; + + public static JoinConferenceDialog newInstance(String prefilledJid, List<String> accounts, Collection<String> conferenceHosts) { + 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; + } + + @Override + public void onActivityCreated(Bundle savedInstanceState) { + super.onActivityCreated(savedInstanceState); + setRetainInstance(true); + } + + @NonNull + @Override + public Dialog onCreateDialog(Bundle savedInstanceState) { + final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.join_conference); + final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.join_conference_dialog, null); + final TextView yourAccount = dialogView.findViewById(R.id.your_account); + final Spinner spinner = dialogView.findViewById(R.id.account); + final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); + DelayedHintHelper.setHint(R.string.conference_address_example, jid); + jid.setAdapter(new KnownHostsAdapter(getActivity(), R.layout.simple_list_item, (Collection<String>) getArguments().getSerializable(CONFERENCE_HOSTS_KEY))); + String prefilledJid = getArguments().getString(PREFILLED_JID_KEY); + if (prefilledJid != null) { + jid.append(prefilledJid); + } + if (xmppConnectionService != null && xmppConnectionService.multipleAccounts()) { + yourAccount.setVisibility(View.VISIBLE); + spinner.setVisibility(View.VISIBLE); + } else { + yourAccount.setVisibility(View.GONE); + spinner.setVisibility(View.GONE); + } + final Checkable bookmarkCheckBox = (CheckBox) dialogView + .findViewById(R.id.bookmark); + StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), spinner); + builder.setView(dialogView); + builder.setPositiveButton(R.string.join, null); + 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, spinner, jid, bookmarkCheckBox.isChecked()); + } + }); + return dialog; + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + try { + mListener = (JoinConferenceDialogListener) context; + } catch (ClassCastException e) { + throw new ClassCastException(context.toString() + + " must implement JoinConferenceDialogListener"); + } + } + + @Override + public void onDestroyView() { + Dialog dialog = getDialog(); + if (dialog != null && getRetainInstance()) { + dialog.setDismissMessage(null); + } + super.onDestroyView(); + } + + public interface JoinConferenceDialogListener { + void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked); + } +}
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 3660ddf81..0de147361 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -43,7 +43,6 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.CheckBox; -import android.widget.Checkable; import android.widget.EditText; import android.widget.ListView; import android.widget.Spinner; @@ -68,9 +67,7 @@ import de.pixart.messenger.entities.ListItem; 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.KnownHostsAdapter; import de.pixart.messenger.ui.adapter.ListItemAdapter; -import de.pixart.messenger.ui.util.DelayedHintHelper; import de.pixart.messenger.utils.XmppUri; import de.pixart.messenger.xmpp.OnUpdateBlocklist; import de.pixart.messenger.xmpp.XmppConnection; @@ -78,7 +75,7 @@ import rocks.xmpp.addr.Jid; import static de.pixart.messenger.ui.SettingsActivity.USE_BUNDLED_EMOJIS; -public class StartConversationActivity extends XmppActivity implements OnRosterUpdate, OnUpdateBlocklist { +public class StartConversationActivity extends XmppActivity implements OnRosterUpdate, OnUpdateBlocklist, CreateConferenceDialog.CreateConferenceDialogListener, JoinConferenceDialog.JoinConferenceDialogListener { private final int REQUEST_SYNC_CONTACTS = 0x28cf; private final int REQUEST_CREATE_CONFERENCE = 0x39da; @@ -95,7 +92,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU private Invite mPendingInvite = null; private EditText mSearchEditText; private AtomicBoolean mRequestedContactsPermission = new AtomicBoolean(false); - private Dialog mCurrentDialog = null; private boolean mHideOfflineContacts = false; private MenuItem.OnActionExpandListener mOnActionExpandListener = new MenuItem.OnActionExpandListener() { @@ -316,14 +312,6 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } @Override - public void onStop() { - if (mCurrentDialog != null) { - mCurrentDialog.dismiss(); - } - super.onStop(); - } - - @Override public void onNewIntent(Intent intent) { if (xmppConnectionServiceBound) { handleIntent(intent); @@ -479,116 +467,18 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU } }); - mCurrentDialog = dialog.show(); + dialog.show(); } @SuppressLint("InflateParams") protected void showJoinConferenceDialog(final String prefilledJid) { - final AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.join_conference); - final View dialogView = getLayoutInflater().inflate(R.layout.join_conference_dialog, null); - final TextView yourAccount = dialogView.findViewById(R.id.your_account); - final Spinner spinner = dialogView.findViewById(R.id.account); - final AutoCompleteTextView jid = dialogView.findViewById(R.id.jid); - DelayedHintHelper.setHint(R.string.conference_address_example, jid); - jid.setAdapter(new KnownHostsAdapter(this, R.layout.simple_list_item, mKnownConferenceHosts)); - if (prefilledJid != null) { - jid.append(prefilledJid); - } - if (xmppConnectionService.multipleAccounts()) { - yourAccount.setVisibility(View.VISIBLE); - spinner.setVisibility(View.VISIBLE); - } else { - yourAccount.setVisibility(View.GONE); - spinner.setVisibility(View.GONE); - } - populateAccountSpinner(this, mActivatedAccounts, spinner); - final Checkable bookmarkCheckBox = (CheckBox) dialogView - .findViewById(R.id.bookmark); - builder.setView(dialogView); - builder.setNegativeButton(R.string.cancel, null); - builder.setPositiveButton(R.string.join, null); - final AlertDialog dialog = builder.create(); - dialog.show(); - mCurrentDialog = dialog; - dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> { - if (!xmppConnectionServiceBound) { - return; - } - final Account account = getSelectedAccount(spinner); - if (account == null) { - return; - } - final Jid conferenceJid; - try { - conferenceJid = Jid.of(jid.getText().toString()); - } catch (final IllegalArgumentException e) { - jid.setError(getString(R.string.invalid_jid)); - return; - } - - if (bookmarkCheckBox.isChecked()) { - if (account.hasBookmarkFor(conferenceJid)) { - jid.setError(getString(R.string.bookmark_already_exists)); - } else { - final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); - bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))); - String nick = conferenceJid.getResource(); - if (nick != null && !nick.isEmpty()) { - bookmark.setNick(nick); - } - account.getBookmarks().add(bookmark); - xmppConnectionService.pushBookmarks(account); - final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true); - bookmark.setConversation(conversation); - dialog.dismiss(); - mCurrentDialog = null; - switchToConversation(conversation); - } - } else { - final Conversation conversation = xmppConnectionService.findOrCreateConversation(account, conferenceJid, true, true, true); - dialog.dismiss(); - mCurrentDialog = null; - switchToConversation(conversation); - } - }); + JoinConferenceDialog dialog = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts, mKnownConferenceHosts); + dialog.show(getSupportFragmentManager(), "join_conference_dialog"); } private void showCreateConferenceDialog() { - final AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setTitle(R.string.create_conference); - final View dialogView = getLayoutInflater().inflate(R.layout.create_conference_dialog, null); - final TextView yourAccount = dialogView.findViewById(R.id.your_account); - final Spinner spinner = dialogView.findViewById(R.id.account); - final EditText subject = dialogView.findViewById(R.id.subject); - populateAccountSpinner(this, mActivatedAccounts, spinner); - if (xmppConnectionService.multipleAccounts()) { - yourAccount.setVisibility(View.VISIBLE); - spinner.setVisibility(View.VISIBLE); - } else { - yourAccount.setVisibility(View.GONE); - spinner.setVisibility(View.GONE); - } - builder.setView(dialogView); - builder.setPositiveButton(R.string.choose_participants, (dialog, which) -> { - if (!xmppConnectionServiceBound) { - return; - } - final Account account = getSelectedAccount(spinner); - if (account == null) { - return; - } - Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class); - intent.putExtra("multiple", true); - intent.putExtra("show_enter_jid", true); - intent.putExtra("subject", subject.getText().toString()); - intent.putExtra(EXTRA_ACCOUNT, account.getJid().asBareJid().toString()); - intent.putExtra(ChooseContactActivity.EXTRA_TITLE_RES_ID, R.string.choose_participants); - startActivityForResult(intent, REQUEST_CREATE_CONFERENCE); - }); - builder.setNegativeButton(R.string.cancel, null); - mCurrentDialog = builder.create(); - mCurrentDialog.show(); + CreateConferenceDialog dialog = CreateConferenceDialog.newInstance(mActivatedAccounts); + dialog.show(getSupportFragmentManager(), "create_conference_dialog"); } private Account getSelectedAccount(Spinner spinner) { @@ -982,6 +872,67 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU return getPreferences().getBoolean(USE_BUNDLED_EMOJIS, getResources().getBoolean(R.bool.use_bundled_emoji)); } + @Override + public void onCreateDialogPositiveClick(Spinner spinner, String subject) { + if (!xmppConnectionServiceBound) { + return; + } + final Account account = getSelectedAccount(spinner); + if (account == null) { + return; + } + Intent intent = new Intent(getApplicationContext(), ChooseContactActivity.class); + intent.putExtra("multiple", true); + intent.putExtra("show_enter_jid", true); + intent.putExtra("subject", subject); + intent.putExtra(EXTRA_ACCOUNT, account.getJid().asBareJid().toString()); + intent.putExtra(ChooseContactActivity.EXTRA_TITLE_RES_ID, R.string.choose_participants); + startActivityForResult(intent, REQUEST_CREATE_CONFERENCE); + } + + @Override + public void onJoinDialogPositiveClick(Dialog dialog, Spinner spinner, AutoCompleteTextView jid, boolean isBookmarkChecked) { + if (!xmppConnectionServiceBound) { + return; + } + final Account account = getSelectedAccount(spinner); + if (account == null) { + return; + } + final Jid conferenceJid; + try { + conferenceJid = Jid.of(jid.getText().toString()); + } catch (final IllegalArgumentException e) { + jid.setError(getString(R.string.invalid_jid)); + return; + } + + if (isBookmarkChecked) { + if (account.hasBookmarkFor(conferenceJid)) { + jid.setError(getString(R.string.bookmark_already_exists)); + } else { + final Bookmark bookmark = new Bookmark(account, conferenceJid.asBareJid()); + bookmark.setAutojoin(getPreferences().getBoolean("autojoin", getResources().getBoolean(R.bool.autojoin))); + String nick = conferenceJid.getResource(); + if (nick != null && !nick.isEmpty()) { + bookmark.setNick(nick); + } + account.getBookmarks().add(bookmark); + xmppConnectionService.pushBookmarks(account); + final Conversation conversation = xmppConnectionService + .findOrCreateConversation(account, conferenceJid, true, true, true); + bookmark.setConversation(conversation); + dialog.dismiss(); + switchToConversation(conversation); + } + } else { + final Conversation conversation = xmppConnectionService + .findOrCreateConversation(account, conferenceJid, true, true, true); + dialog.dismiss(); + switchToConversation(conversation); + } + } + public static class MyListFragment extends ListFragment { private AdapterView.OnItemClickListener mOnItemClickListener; private int mResContextMenu; |