55import android .os .Bundle ;
66import android .view .LayoutInflater ;
77import android .view .View ;
8- import android .widget .EditText ;
9- import android .widget .Spinner ;
108
119import androidx .annotation .NonNull ;
1210import androidx .appcompat .app .AlertDialog ;
1715
1816import org .wordpress .android .R ;
1917import org .wordpress .android .WordPress ;
18+ import org .wordpress .android .databinding .AddCategoryBinding ;
2019import org .wordpress .android .fluxc .model .SiteModel ;
2120import org .wordpress .android .fluxc .model .TermModel ;
2221import org .wordpress .android .fluxc .store .TaxonomyStore ;
2928
3029public class AddCategoryFragment extends AppCompatDialogFragment {
3130 private SiteModel mSite ;
32- private EditText mCategoryEditText ;
33- private Spinner mParentSpinner ;
31+ private AddCategoryBinding mBinding ;
3432
3533 @ Inject TaxonomyStore mTaxonomyStore ;
3634
@@ -53,16 +51,12 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
5351 new MaterialAlertDialogBuilder (new ContextThemeWrapper (getActivity (), R .style .PostSettingsTheme ));
5452 // Get the layout inflater
5553 LayoutInflater inflater = requireActivity ().getLayoutInflater ();
56-
57- // Inflate view
5854 //noinspection InflateParams
59- View view = inflater .inflate (R .layout .add_category , null );
60- mCategoryEditText = (EditText ) view .findViewById (R .id .category_name );
61- mParentSpinner = (Spinner ) view .findViewById (R .id .parent_category );
55+ mBinding = AddCategoryBinding .inflate (inflater , null , false );
6256
6357 loadCategories ();
6458
65- builder .setView (view )
59+ builder .setView (mBinding . getRoot () )
6660 .setPositiveButton (android .R .string .ok , null )
6761 .setNegativeButton (android .R .string .cancel , null );
6862
@@ -101,12 +95,12 @@ private void initSite(Bundle savedInstanceState) {
10195 }
10296
10397 private boolean addCategory () {
104- String categoryName = mCategoryEditText .getText ().toString ();
105- CategoryNode selectedCategory = (CategoryNode ) mParentSpinner .getSelectedItem ();
98+ String categoryName = mBinding . categoryName .getText ().toString ();
99+ CategoryNode selectedCategory = (CategoryNode ) mBinding . parentCategory .getSelectedItem ();
106100 long parentId = (selectedCategory != null ) ? selectedCategory .getCategoryId () : 0 ;
107101
108102 if (categoryName .replaceAll (" " , "" ).equals ("" )) {
109- mCategoryEditText .setError (getText (R .string .cat_name_required ));
103+ mBinding . categoryName .setError (getText (R .string .cat_name_required ));
110104 return false ;
111105 }
112106
@@ -127,7 +121,7 @@ private void loadCategories() {
127121 if (categoryLevels .size () > 0 ) {
128122 ParentCategorySpinnerAdapter categoryAdapter =
129123 new ParentCategorySpinnerAdapter (getActivity (), R .layout .categories_row_parent , categoryLevels );
130- mParentSpinner .setAdapter (categoryAdapter );
124+ mBinding . parentCategory .setAdapter (categoryAdapter );
131125 }
132126 }
133127
@@ -136,4 +130,10 @@ public void onSaveInstanceState(Bundle outState) {
136130 super .onSaveInstanceState (outState );
137131 outState .putSerializable (WordPress .SITE , mSite );
138132 }
133+
134+ @ Override
135+ public void onDestroy () {
136+ super .onDestroy ();
137+ mBinding = null ;
138+ }
139139}
0 commit comments