diff --git a/WordPress/src/main/java/org/wordpress/android/ui/posts/AddCategoryFragment.java b/WordPress/src/main/java/org/wordpress/android/ui/posts/AddCategoryFragment.java index 55ff486ace81..4b4e1e7455f6 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/posts/AddCategoryFragment.java +++ b/WordPress/src/main/java/org/wordpress/android/ui/posts/AddCategoryFragment.java @@ -5,8 +5,6 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; -import android.widget.EditText; -import android.widget.Spinner; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; @@ -17,6 +15,7 @@ import org.wordpress.android.R; import org.wordpress.android.WordPress; +import org.wordpress.android.databinding.AddCategoryBinding; import org.wordpress.android.fluxc.model.SiteModel; import org.wordpress.android.fluxc.model.TermModel; import org.wordpress.android.fluxc.store.TaxonomyStore; @@ -29,8 +28,7 @@ public class AddCategoryFragment extends AppCompatDialogFragment { private SiteModel mSite; - private EditText mCategoryEditText; - private Spinner mParentSpinner; + private AddCategoryBinding binding; @Inject TaxonomyStore mTaxonomyStore; @@ -53,16 +51,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) { new MaterialAlertDialogBuilder(new ContextThemeWrapper(getActivity(), R.style.PostSettingsTheme)); // Get the layout inflater LayoutInflater inflater = requireActivity().getLayoutInflater(); - - // Inflate view //noinspection InflateParams - View view = inflater.inflate(R.layout.add_category, null); - mCategoryEditText = (EditText) view.findViewById(R.id.category_name); - mParentSpinner = (Spinner) view.findViewById(R.id.parent_category); + binding = AddCategoryBinding.inflate(inflater,null,false); loadCategories(); - builder.setView(view) + builder.setView(binding.getRoot()) .setPositiveButton(android.R.string.ok, null) .setNegativeButton(android.R.string.cancel, null); @@ -101,12 +95,12 @@ private void initSite(Bundle savedInstanceState) { } private boolean addCategory() { - String categoryName = mCategoryEditText.getText().toString(); - CategoryNode selectedCategory = (CategoryNode) mParentSpinner.getSelectedItem(); + String categoryName = binding.categoryName.getText().toString(); + CategoryNode selectedCategory = (CategoryNode) binding.parentCategory.getSelectedItem(); long parentId = (selectedCategory != null) ? selectedCategory.getCategoryId() : 0; if (categoryName.replaceAll(" ", "").equals("")) { - mCategoryEditText.setError(getText(R.string.cat_name_required)); + binding.categoryName.setError(getText(R.string.cat_name_required)); return false; } @@ -127,7 +121,7 @@ private void loadCategories() { if (categoryLevels.size() > 0) { ParentCategorySpinnerAdapter categoryAdapter = new ParentCategorySpinnerAdapter(getActivity(), R.layout.categories_row_parent, categoryLevels); - mParentSpinner.setAdapter(categoryAdapter); + binding.parentCategory.setAdapter(categoryAdapter); } }