aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-08 20:18:50 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-08 20:18:50 +0200
commit8886fade18b64d128aaa4b4bc0600f6afe964bd2 (patch)
treeb7a2951232c2137d0222b7892b70adcaef741b6e /src/main/java/de/pixart/messenger
parenteb773489d6c08ca336095688a8deda039c09c080 (diff)
add data binding and check in back stack for dialogs
Diffstat (limited to 'src/main/java/de/pixart/messenger')
-rw-r--r--src/main/java/de/pixart/messenger/ui/BlocklistActivity.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java10
-rw-r--r--src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java35
-rw-r--r--src/main/java/de/pixart/messenger/ui/EnterJidDialog.java94
-rw-r--r--src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java32
-rw-r--r--src/main/java/de/pixart/messenger/ui/StartConversationActivity.java28
6 files changed, 114 insertions, 95 deletions
diff --git a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
index 422803487..c4d077c80 100644
--- a/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/BlocklistActivity.java
@@ -1,6 +1,8 @@
package de.pixart.messenger.ui;
import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.widget.Toast;
@@ -56,6 +58,12 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
}
protected void showEnterJidDialog() {
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts, null,
getString(R.string.block_jabber_id), getString(R.string.block),
@@ -69,7 +77,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
}
return true;
});
- dialog.show(getSupportFragmentManager(), "block_contact_dialog");
+ dialog.show(ft, "dialog");
}
protected void refreshUiReal() {
diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
index ae836ee2a..46a60ef8c 100644
--- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java
@@ -6,6 +6,8 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StringRes;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.ActionBar;
import android.view.ActionMode;
import android.view.Menu;
@@ -231,6 +233,12 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
}
protected void showEnterJidDialog(XmppUri uri) {
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
Jid jid = uri == null ? null : uri.getJid();
EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts,
@@ -258,7 +266,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
return true;
});
- dialog.show(getSupportFragmentManager(), "enter_contact_dialog");
+ dialog.show(ft, "dialog");
}
@Override
diff --git a/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java b/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java
index c872ccb2f..0cb6e294f 100644
--- a/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/CreateConferenceDialog.java
@@ -2,28 +2,27 @@ package de.pixart.messenger.ui;
import android.app.Dialog;
import android.content.Context;
-import android.content.DialogInterface;
+import android.databinding.DataBindingUtil;
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.databinding.CreateConferenceDialogBinding;
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;
+ private CreateConferenceDialogListener mListener;
public static CreateConferenceDialog newInstance(List<String> accounts) {
CreateConferenceDialog dialog = new CreateConferenceDialog();
@@ -44,26 +43,22 @@ public class CreateConferenceDialog extends DialogFragment {
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);
+ //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);
+ CreateConferenceDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.create_conference_dialog, null, false);
if (xmppConnectionService != null && xmppConnectionService.multipleAccounts()) {
- yourAccount.setVisibility(View.VISIBLE);
- spinner.setVisibility(View.VISIBLE);
+ binding.yourAccount.setVisibility(View.VISIBLE);
+ binding.account.setVisibility(View.VISIBLE);
} else {
- yourAccount.setVisibility(View.GONE);
- spinner.setVisibility(View.GONE);
+ binding.yourAccount.setVisibility(View.GONE);
+ binding.account.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());
- }
- });
+ StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, binding.account);
+ builder.setView(binding.getRoot());
+ builder.setPositiveButton(R.string.choose_participants, (dialog, which) -> mListener.onCreateDialogPositiveClick(binding.account, binding.subject.getText().toString()));
builder.setNegativeButton(R.string.cancel, null);
return builder.create();
}
diff --git a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
index 604bfc8d2..26e9017f9 100644
--- a/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/EnterJidDialog.java
@@ -1,15 +1,13 @@
package de.pixart.messenger.ui;
import android.app.Dialog;
+import android.databinding.DataBindingUtil;
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.ArrayAdapter;
-import android.widget.AutoCompleteTextView;
-import android.widget.Spinner;
-import android.widget.TextView;
import java.util.ArrayList;
import java.util.Collection;
@@ -18,21 +16,22 @@ 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.util.DelayedHintHelper;
import rocks.xmpp.addr.Jid;
public class EnterJidDialog extends DialogFragment {
- 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";
- private static final String ACCOUNT_KEY = "account";
- private static final String ALLOW_EDIT_JID_KEY = "allow_edit_jid";
+ private static final String POSITIVE_BUTTON_KEY = "positive_button";
+ private static final String PREFILLED_JID_KEY = "prefilled_jid";
+ private static final String ACCOUNT_KEY = "account";
+ 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 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,
@@ -63,79 +62,76 @@ public class EnterJidDialog extends DialogFragment {
public Dialog onCreateDialog(Bundle savedInstanceState) {
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(getArguments().getString(TITLE_KEY));
- View dialogView = getActivity().getLayoutInflater().inflate(R.layout.enter_jid_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);
- jid.setAdapter(new KnownHostsAdapter(getActivity(), R.layout.simple_list_item, (Collection<String>) getArguments().getSerializable(CONFERENCE_HOSTS_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)));
String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
if (prefilledJid != null) {
- jid.append(prefilledJid);
+ binding.jid.append(prefilledJid);
if (!getArguments().getBoolean(ALLOW_EDIT_JID_KEY)) {
- jid.setFocusable(false);
- jid.setFocusableInTouchMode(false);
- jid.setClickable(false);
- jid.setCursorVisible(false);
+ binding.jid.setFocusable(false);
+ binding.jid.setFocusableInTouchMode(false);
+ binding.jid.setClickable(false);
+ binding.jid.setCursorVisible(false);
}
}
- DelayedHintHelper.setHint(R.string.account_settings_example_jabber_id, jid);
+ DelayedHintHelper.setHint(R.string.account_settings_example_jabber_id, binding.jid);
String account = getArguments().getString(ACCOUNT_KEY);
if (getArguments().getBoolean(MULTIPLE_ACCOUNTS)) {
- yourAccount.setVisibility(View.VISIBLE);
- spinner.setVisibility(View.VISIBLE);
+ binding.yourAccount.setVisibility(View.VISIBLE);
+ binding.account.setVisibility(View.VISIBLE);
} else {
- yourAccount.setVisibility(View.GONE);
- spinner.setVisibility(View.GONE);
+ binding.yourAccount.setVisibility(View.GONE);
+ binding.account.setVisibility(View.GONE);
}
if (account == null) {
- StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), spinner);
+ 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});
- spinner.setEnabled(false);
+ binding.account.setEnabled(false);
adapter.setDropDownViewResource(R.layout.simple_list_item);
- spinner.setAdapter(adapter);
+ binding.account.setAdapter(adapter);
}
- builder.setView(dialogView);
+ builder.setView(binding.getRoot());
builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(getArguments().getString(POSITIVE_BUTTON_KEY), null);
AlertDialog dialog = builder.create();
View.OnClickListener dialogOnClick = v -> {
final Jid accountJid;
- if (!spinner.isEnabled() && account == null) {
+ if (!binding.account.isEnabled() && account == null) {
return;
}
try {
if (Config.DOMAIN_LOCK != null) {
- accountJid = Jid.of((String) spinner.getSelectedItem(), Config.DOMAIN_LOCK, null);
+ accountJid = Jid.of((String) binding.account.getSelectedItem(), Config.DOMAIN_LOCK, null);
} else {
- accountJid = Jid.of((String) spinner.getSelectedItem());
+ accountJid = Jid.of((String) binding.account.getSelectedItem());
}
- } catch (final IllegalArgumentException e) {
+ } catch (final IllegalArgumentException e) {
return;
}
final Jid contactJid;
try {
- contactJid = Jid.of(jid.getText().toString());
- } catch (final IllegalArgumentException e) {
- jid.setError(getActivity().getString(R.string.invalid_jid));
+ contactJid = Jid.of(binding.jid.getText().toString());
+ } catch (final IllegalArgumentException e) {
+ binding.jid.setError(getActivity().getString(R.string.invalid_jid));
return;
}
- if(mListener != null) {
+ if (mListener != null) {
try {
- if(mListener.onEnterJidDialogPositive(accountJid, contactJid)) {
+ if (mListener.onEnterJidDialogPositive(accountJid, contactJid)) {
dialog.dismiss();
}
- } catch(JidError error) {
- jid.setError(error.toString());
+ } catch (JidError error) {
+ binding.jid.setError(error.toString());
}
}
};
@@ -148,6 +144,15 @@ public class EnterJidDialog extends DialogFragment {
this.mListener = listener;
}
+ @Override
+ public void onDestroyView() {
+ Dialog dialog = getDialog();
+ if (dialog != null && getRetainInstance()) {
+ dialog.setDismissMessage(null);
+ }
+ super.onDestroyView();
+ }
+
public interface OnEnterJidDialogPositiveListener {
boolean onEnterJidDialogPositive(Jid account, Jid contact) throws EnterJidDialog.JidError;
}
@@ -163,13 +168,4 @@ public class EnterJidDialog extends DialogFragment {
return msg;
}
}
-
- @Override
- public void onDestroyView() {
- Dialog dialog = getDialog();
- if (dialog != null && getRetainInstance()) {
- dialog.setDismissMessage(null);
- }
- super.onDestroyView();
- }
}
diff --git a/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java
index ec806236f..e232ec813 100644
--- a/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java
+++ b/src/main/java/de/pixart/messenger/ui/JoinConferenceDialog.java
@@ -3,16 +3,14 @@ package de.pixart.messenger.ui;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
+import android.databinding.DataBindingUtil;
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;
@@ -20,6 +18,7 @@ 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.util.DelayedHintHelper;
@@ -53,27 +52,22 @@ public class JoinConferenceDialog extends DialogFragment {
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)));
+ 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)));
String prefilledJid = getArguments().getString(PREFILLED_JID_KEY);
if (prefilledJid != null) {
- jid.append(prefilledJid);
+ binding.jid.append(prefilledJid);
}
if (xmppConnectionService != null && xmppConnectionService.multipleAccounts()) {
- yourAccount.setVisibility(View.VISIBLE);
- spinner.setVisibility(View.VISIBLE);
+ binding.yourAccount.setVisibility(View.VISIBLE);
+ binding.account.setVisibility(View.VISIBLE);
} else {
- yourAccount.setVisibility(View.GONE);
- spinner.setVisibility(View.GONE);
+ binding.yourAccount.setVisibility(View.GONE);
+ binding.account.setVisibility(View.GONE);
}
- final Checkable bookmarkCheckBox = (CheckBox) dialogView
- .findViewById(R.id.bookmark);
- StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), spinner);
- builder.setView(dialogView);
+ StartConversationActivity.populateAccountSpinner(getActivity(), getArguments().getStringArrayList(ACCOUNTS_LIST_KEY), binding.account);
+ builder.setView(binding.getRoot());
builder.setPositiveButton(R.string.join, null);
builder.setNegativeButton(R.string.cancel, null);
AlertDialog dialog = builder.create();
@@ -81,7 +75,7 @@ public class JoinConferenceDialog extends DialogFragment {
dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- mListener.onJoinDialogPositiveClick(dialog, spinner, jid, bookmarkCheckBox.isChecked());
+ mListener.onJoinDialogPositiveClick(dialog, binding.account, binding.jid, binding.bookmark.isChecked());
}
});
return dialog;
diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
index d3d6d2d2a..ed1612044 100644
--- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
+++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java
@@ -432,6 +432,12 @@ 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");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
EnterJidDialog dialog = EnterJidDialog.newInstance(
mKnownHosts, mActivatedAccounts,
getString(R.string.create_contact), getString(R.string.create),
@@ -467,18 +473,30 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
}
});
- dialog.show(getSupportFragmentManager(), "create_contact_dialog");
+ dialog.show(ft, "dialog");
}
@SuppressLint("InflateParams")
protected void showJoinConferenceDialog(final String prefilledJid) {
- JoinConferenceDialog dialog = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts, mKnownConferenceHosts);
- dialog.show(getSupportFragmentManager(), "join_conference_dialog");
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
+ JoinConferenceDialog joinConferenceFragment = JoinConferenceDialog.newInstance(prefilledJid, mActivatedAccounts, mKnownConferenceHosts);
+ joinConferenceFragment.show(ft, "dialog");
}
private void showCreateConferenceDialog() {
- CreateConferenceDialog dialog = CreateConferenceDialog.newInstance(mActivatedAccounts);
- dialog.show(getSupportFragmentManager(), "create_conference_dialog");
+ FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
+ Fragment prev = getSupportFragmentManager().findFragmentByTag("dialog");
+ if (prev != null) {
+ ft.remove(prev);
+ }
+ ft.addToBackStack(null);
+ CreateConferenceDialog createConferenceFragment = CreateConferenceDialog.newInstance(mActivatedAccounts);
+ createConferenceFragment.show(ft, "dialog");
}
private Account getSelectedAccount(Spinner spinner) {