add data binding and check in back stack for dialogs
This commit is contained in:
parent
b33725b435
commit
2af12afb64
|
@ -1,6 +1,8 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.text.Editable;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -62,6 +64,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),
|
||||
|
@ -76,7 +84,7 @@ public class BlocklistActivity extends AbstractSearchableListItemActivity implem
|
|||
return true;
|
||||
});
|
||||
|
||||
dialog.show(getSupportFragmentManager(), "block_contact_dialog");
|
||||
dialog.show(ft, "dialog");
|
||||
}
|
||||
|
||||
protected void refreshUiReal() {
|
||||
|
|
|
@ -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;
|
||||
|
@ -230,6 +232,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,
|
||||
|
@ -256,7 +264,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity {
|
|||
return true;
|
||||
});
|
||||
|
||||
dialog.show(getSupportFragmentManager(), "enter_contact_dialog");
|
||||
dialog.show(ft, "dialog");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
|
@ -15,6 +16,7 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.CreateConferenceDialogBinding;
|
||||
|
||||
public class CreateConferenceDialog extends DialogFragment {
|
||||
|
||||
|
@ -40,16 +42,14 @@ public class CreateConferenceDialog extends DialogFragment {
|
|||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.dialog_title_create_conference);
|
||||
final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.create_conference_dialog, null);
|
||||
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);
|
||||
ArrayList<String> mActivatedAccounts = getArguments().getStringArrayList(ACCOUNTS_LIST_KEY);
|
||||
StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, spinner);
|
||||
builder.setView(dialogView);
|
||||
StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, binding.account);
|
||||
builder.setView(binding.getRoot());
|
||||
builder.setPositiveButton(R.string.choose_participants, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mListener.onCreateDialogPositiveClick(spinner, subject.getText().toString());
|
||||
mListener.onCreateDialogPositiveClick(binding.account, binding.subject.getText().toString());
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton(R.string.cancel, null);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.os.Bundle;
|
||||
|
@ -17,6 +18,7 @@ import java.util.List;
|
|||
|
||||
import eu.siacs.conversations.Config;
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.EnterJidDialogBinding;
|
||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.ui.util.DelayedHintHelper;
|
||||
import rocks.xmpp.addr.Jid;
|
||||
|
@ -61,59 +63,57 @@ 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 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 (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) {
|
||||
return;
|
||||
}
|
||||
final Jid contactJid;
|
||||
try {
|
||||
contactJid = Jid.of(jid.getText().toString());
|
||||
contactJid = Jid.of(binding.jid.getText().toString());
|
||||
} catch (final IllegalArgumentException e) {
|
||||
jid.setError(getActivity().getString(R.string.invalid_jid));
|
||||
binding.jid.setError(getActivity().getString(R.string.invalid_jid));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class EnterJidDialog extends DialogFragment{
|
|||
dialog.dismiss();
|
||||
}
|
||||
} catch(JidError error) {
|
||||
jid.setError(error.toString());
|
||||
binding.jid.setError(error.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package eu.siacs.conversations.ui;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.databinding.DataBindingUtil;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
|
@ -19,6 +20,7 @@ import java.util.HashSet;
|
|||
import java.util.List;
|
||||
|
||||
import eu.siacs.conversations.R;
|
||||
import eu.siacs.conversations.databinding.JoinConferenceDialogBinding;
|
||||
import eu.siacs.conversations.ui.adapter.KnownHostsAdapter;
|
||||
import eu.siacs.conversations.ui.util.DelayedHintHelper;
|
||||
|
||||
|
@ -50,19 +52,15 @@ public class JoinConferenceDialog extends DialogFragment {
|
|||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setTitle(R.string.dialog_title_join_conference);
|
||||
final View dialogView = getActivity().getLayoutInflater().inflate(R.layout.join_conference_dialog, null);
|
||||
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);
|
||||
}
|
||||
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();
|
||||
|
@ -70,7 +68,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;
|
||||
|
|
|
@ -440,6 +440,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.dialog_title_create_contact), getString(R.string.create),
|
||||
|
@ -474,18 +480,30 @@ public class StartConversationActivity extends XmppActivity implements OnRosterU
|
|||
return true;
|
||||
}
|
||||
});
|
||||
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) {
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
@ -7,11 +8,13 @@
|
|||
android:paddingLeft="?attr/dialog_horizontal_padding"
|
||||
android:paddingRight="?attr/dialog_horizontal_padding"
|
||||
android:paddingTop="?attr/dialog_vertical_padding">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/your_account"
|
||||
style="@style/InputLabel" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/account"
|
||||
android:layout_width="fill_parent"
|
||||
|
@ -34,7 +37,6 @@
|
|||
android:nextFocusUp="@+id/subject"
|
||||
android:nextFocusDown="@+id/subject"
|
||||
android:hint="@string/edit_subject_hint"/>
|
||||
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
@ -31,5 +32,5 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:inputType="textEmailAddress"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
|
@ -7,6 +8,7 @@
|
|||
android:paddingLeft="24dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="16dp">
|
||||
|
||||
<TextView
|
||||
style="@style/InputLabel"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -31,7 +33,6 @@
|
|||
android:inputType="textEmailAddress"/>
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/bookmark"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -39,5 +40,5 @@
|
|||
android:layout_marginTop="8dp"
|
||||
android:checked="true"
|
||||
android:text="@string/save_as_bookmark"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
Loading…
Reference in New Issue