From 340027896c0d4e2417abfca891039ac38e5aca92 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Thu, 6 Jun 2024 17:29:02 +0530 Subject: [PATCH 1/3] Migrated `PostSettingsInputDialogFragment` to ViewBinding --- .../PostSettingsInputDialogFragment.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java index af749db0878c..981a32338872 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java @@ -8,9 +8,6 @@ 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; @@ -18,11 +15,12 @@ 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 { public static final String TAG = "post_settings_input_dialog_fragment"; @@ -35,6 +33,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; @@ -94,34 +93,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(); //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); } From 6a13711360a84f9a1bdd1c3aadd1a6680960fa29 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Thu, 13 Jun 2024 16:14:17 +0530 Subject: [PATCH 2/3] Redundant : Extra Line Commit Removed --- .../android/ui/posts/PostSettingsInputDialogFragment.java | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java index 981a32338872..be35b4896aec 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java @@ -20,7 +20,6 @@ import org.wordpress.android.databinding.PostSettingsInputDialogBinding; import org.wordpress.android.util.ActivityUtils; - public class PostSettingsInputDialogFragment extends DialogFragment implements TextWatcher { public static final String TAG = "post_settings_input_dialog_fragment"; From 48d7fdfc2a13069106381af529159f08aae24009 Mon Sep 17 00:00:00 2001 From: Neel Doshi Date: Tue, 18 Jun 2024 10:15:59 +0530 Subject: [PATCH 3/3] Changed mbinding to binding --- .../PostSettingsInputDialogFragment.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java index be35b4896aec..63d5fa824d13 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/PostSettingsInputDialogFragment.java @@ -94,31 +94,32 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { new MaterialAlertDialogBuilder(new ContextThemeWrapper(getActivity(), R.style.PostSettingsTheme)); LayoutInflater layoutInflater = requireActivity().getLayoutInflater(); //noinspection InflateParams - PostSettingsInputDialogBinding mBinding = + PostSettingsInputDialogBinding binding = PostSettingsInputDialogBinding.inflate(layoutInflater, null, false); - builder.setView(mBinding.getRoot()); + builder.setView(binding.getRoot()); if (mIsMultilineInput) { - mBinding.postSettingsInputDialogEditText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); + binding.postSettingsInputDialogEditText.setRawInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); } else { - mBinding.postSettingsInputDialogEditText.setInputType(InputType.TYPE_CLASS_TEXT); + binding.postSettingsInputDialogEditText.setInputType(InputType.TYPE_CLASS_TEXT); } if (!TextUtils.isEmpty(mCurrentInput)) { - mBinding.postSettingsInputDialogEditText.setText(mCurrentInput); + binding.postSettingsInputDialogEditText.setText(mCurrentInput); // move the cursor to the end - mBinding.postSettingsInputDialogEditText.setSelection(mCurrentInput.length()); + binding.postSettingsInputDialogEditText.setSelection(mCurrentInput.length()); } - mBinding.postSettingsInputDialogEditText.addTextChangedListener(this); + binding.postSettingsInputDialogEditText.addTextChangedListener(this); - mBinding.postSettingsInputDialogInputLayout.setHint(mTitle); + binding.postSettingsInputDialogInputLayout.setHint(mTitle); - mBinding.postSettingsInputDialogHint.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 = mBinding.postSettingsInputDialogEditText.getText().toString(); - if (mListener != null) { + Editable text = binding.postSettingsInputDialogEditText.getText(); + if (mListener != null && text != null) { + mCurrentInput = text.toString(); mListener.onInputUpdated(mCurrentInput); } }