2018-03-12 09:42:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
2018-03-14 06:20:44 +00:00
|
|
|
import android.databinding.DataBindingUtil;
|
2018-03-12 09:42:01 +00:00
|
|
|
import android.support.annotation.NonNull;
|
|
|
|
import android.support.v4.app.DialogFragment;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.EditText;
|
|
|
|
import android.widget.Spinner;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import eu.siacs.conversations.R;
|
2018-03-14 06:20:44 +00:00
|
|
|
import eu.siacs.conversations.databinding.CreateConferenceDialogBinding;
|
2018-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
public class CreateConferenceDialog extends DialogFragment {
|
|
|
|
|
|
|
|
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
|
|
|
|
private CreateConferenceDialogListener mListener;
|
|
|
|
|
|
|
|
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.dialog_title_create_conference);
|
2018-03-14 06:20:44 +00:00
|
|
|
CreateConferenceDialogBinding binding = DataBindingUtil.inflate(getActivity().getLayoutInflater(), R.layout.create_conference_dialog, null, false);
|
2018-03-12 09:42:01 +00:00
|
|
|
ArrayList<String> mActivatedAccounts = getArguments().getStringArrayList(ACCOUNTS_LIST_KEY);
|
2018-03-14 06:20:44 +00:00
|
|
|
StartConversationActivity.populateAccountSpinner(getActivity(), mActivatedAccounts, binding.account);
|
|
|
|
builder.setView(binding.getRoot());
|
2018-03-12 09:42:01 +00:00
|
|
|
builder.setPositiveButton(R.string.choose_participants, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialog, int which) {
|
2018-03-14 06:20:44 +00:00
|
|
|
mListener.onCreateDialogPositiveClick(binding.account, binding.subject.getText().toString());
|
2018-03-12 09:42:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
|
|
|
public interface CreateConferenceDialogListener {
|
|
|
|
void onCreateDialogPositiveClick(Spinner spinner, String subject);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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();
|
|
|
|
}
|
|
|
|
}
|