Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated PostSettingsInputDialogFragment to ViewBinding #20941

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,34 +92,32 @@ 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor (🔍): Although this change is perfectly valid, consider avoid adding an unrelated change on a single commit. If you need to make this change, add a separate targeted commit on top of the main set of commits on a PR. Then, explaining the reasoning behind that change, even maybe group other such changes to make this change more impactful. How does this sound? 🙏

PS: No need for you to do anything here, this is just for educational purposes only.

//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 mBinding =
PostSettingsInputDialogBinding.inflate(layoutInflater, null, false);
builder.setView(mBinding.getRoot());
if (mIsMultilineInput) {
editText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
mBinding.postSettingsInputDialogEditText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE);
} else {
editText.setInputType(InputType.TYPE_CLASS_TEXT);
mBinding.postSettingsInputDialogEditText.setInputType(InputType.TYPE_CLASS_TEXT);
}
if (!TextUtils.isEmpty(mCurrentInput)) {
editText.setText(mCurrentInput);
mBinding.postSettingsInputDialogEditText.setText(mCurrentInput);
// move the cursor to the end
editText.setSelection(mCurrentInput.length());
mBinding.postSettingsInputDialogEditText.setSelection(mCurrentInput.length());
}
editText.addTextChangedListener(this);
mBinding.postSettingsInputDialogEditText.addTextChangedListener(this);

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

TextView hintTextView = dialogView.findViewById(R.id.post_settings_input_dialog_hint);
hintTextView.setText(mHint);
mBinding.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();
mCurrentInput = mBinding.postSettingsInputDialogEditText.getText().toString();
if (mListener != null) {
mListener.onInputUpdated(mCurrentInput);
}
Expand Down