2018-03-12 09:42:01 +00:00
|
|
|
package eu.siacs.conversations.ui;
|
|
|
|
|
|
|
|
import android.app.Dialog;
|
2019-02-06 13:45:51 +00:00
|
|
|
import android.content.Context;
|
|
|
|
import android.os.Bundle;
|
2021-01-23 08:25:34 +00:00
|
|
|
import android.widget.Spinner;
|
|
|
|
|
2021-01-18 17:26:46 +00:00
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.appcompat.app.AlertDialog;
|
2021-01-23 08:25:34 +00:00
|
|
|
import androidx.databinding.DataBindingUtil;
|
|
|
|
import androidx.fragment.app.DialogFragment;
|
2018-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
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-06-24 09:23:10 +00:00
|
|
|
import eu.siacs.conversations.ui.util.DelayedHintHelper;
|
2018-03-12 09:42:01 +00:00
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
public class CreatePrivateGroupChatDialog extends DialogFragment {
|
2018-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
private static final String ACCOUNTS_LIST_KEY = "activated_accounts_list";
|
|
|
|
private CreateConferenceDialogListener mListener;
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
public static CreatePrivateGroupChatDialog newInstance(List<String> accounts) {
|
|
|
|
CreatePrivateGroupChatDialog dialog = new CreatePrivateGroupChatDialog();
|
|
|
|
Bundle bundle = new Bundle();
|
2018-03-12 09:42:01 +00:00
|
|
|
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());
|
2019-02-06 13:45:51 +00:00
|
|
|
builder.setTitle(R.string.create_private_group_chat);
|
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-06-24 09:23:10 +00:00
|
|
|
builder.setPositiveButton(R.string.choose_participants, (dialog, which) -> mListener.onCreateDialogPositiveClick(binding.account, binding.groupChatName.getText().toString().trim()));
|
2018-03-12 09:42:01 +00:00
|
|
|
builder.setNegativeButton(R.string.cancel, null);
|
2018-06-24 09:23:10 +00:00
|
|
|
DelayedHintHelper.setHint(R.string.providing_a_name_is_optional, binding.groupChatName);
|
2019-01-10 21:09:20 +00:00
|
|
|
binding.groupChatName.setOnEditorActionListener((v, actionId, event) -> {
|
|
|
|
mListener.onCreateDialogPositiveClick(binding.account, binding.groupChatName.getText().toString().trim());
|
|
|
|
return true;
|
|
|
|
});
|
2018-03-12 09:42:01 +00:00
|
|
|
return builder.create();
|
|
|
|
}
|
|
|
|
|
2019-02-06 13:45:51 +00:00
|
|
|
|
2018-03-12 09:42:01 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|