Skip to content

Commit

Permalink
Merge pull request #20941 from neeldoshii/Migrated-`PostSettingsInput…
Browse files Browse the repository at this point in the history
…DialogFragment`-to-ViewBinding

Migrated `PostSettingsInputDialogFragment` to ViewBinding
  • Loading branch information
ParaskP7 authored Jun 18, 2024
2 parents ff17d3b + 48d7fdf commit 3b1e418
Showing 1 changed file with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.fragment.app.DialogFragment;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.textfield.TextInputLayout;

import org.wordpress.android.R;
import org.wordpress.android.databinding.PostSettingsInputDialogBinding;
import org.wordpress.android.util.ActivityUtils;

public class PostSettingsInputDialogFragment extends DialogFragment implements TextWatcher {
Expand All @@ -35,6 +32,7 @@ public interface PostSettingsInputDialogListener {
private static final String HINT_TAG = "hint";
private static final String DISABLE_EMPTY_INPUT_TAG = "disable_empty_input";
private static final String MULTILINE_INPUT_TAG = "is_multiline_input";

private String mCurrentInput;
private String mTitle;
private String mHint;
Expand Down Expand Up @@ -94,35 +92,34 @@ public void onDismiss(DialogInterface dialog) {
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder =
new MaterialAlertDialogBuilder(new ContextThemeWrapper(getActivity(), R.style.PostSettingsTheme));
LayoutInflater layoutInflater = getActivity().getLayoutInflater();
LayoutInflater layoutInflater = requireActivity().getLayoutInflater();
//noinspection InflateParams
View dialogView = layoutInflater.inflate(R.layout.post_settings_input_dialog, null);
builder.setView(dialogView);
final EditText editText = dialogView.findViewById(R.id.post_settings_input_dialog_edit_text);
PostSettingsInputDialogBinding binding =
PostSettingsInputDialogBinding.inflate(layoutInflater, null, false);
builder.setView(binding.getRoot());
if (mIsMultilineInput) {
editText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
binding.postSettingsInputDialogEditText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
} else {
editText.setInputType(InputType.TYPE_CLASS_TEXT);
binding.postSettingsInputDialogEditText.setInputType(InputType.TYPE_CLASS_TEXT);
}
if (!TextUtils.isEmpty(mCurrentInput)) {
editText.setText(mCurrentInput);
binding.postSettingsInputDialogEditText.setText(mCurrentInput);
// move the cursor to the end
editText.setSelection(mCurrentInput.length());
binding.postSettingsInputDialogEditText.setSelection(mCurrentInput.length());
}
editText.addTextChangedListener(this);
binding.postSettingsInputDialogEditText.addTextChangedListener(this);

TextInputLayout textInputLayout = dialogView.findViewById(R.id.post_settings_input_dialog_input_layout);
textInputLayout.setHint(mTitle);
binding.postSettingsInputDialogInputLayout.setHint(mTitle);

TextView hintTextView = dialogView.findViewById(R.id.post_settings_input_dialog_hint);
hintTextView.setText(mHint);
binding.postSettingsInputDialogHint.setText(mHint);

builder.setNegativeButton(R.string.cancel, null);
builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mCurrentInput = editText.getText().toString();
if (mListener != null) {
Editable text = binding.postSettingsInputDialogEditText.getText();
if (mListener != null && text != null) {
mCurrentInput = text.toString();
mListener.onInputUpdated(mCurrentInput);
}
}
Expand Down

0 comments on commit 3b1e418

Please sign in to comment.