Skip to content

Commit

Permalink
Migrated AddCategoryFragment to ViewBinding
Browse files Browse the repository at this point in the history
  • Loading branch information
neeldoshii committed Jun 6, 2024
1 parent db47af2 commit 5095884
Showing 1 changed file with 8 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -29,8 +28,7 @@

public class AddCategoryFragment extends AppCompatDialogFragment {
private SiteModel mSite;
private EditText mCategoryEditText;
private Spinner mParentSpinner;
private AddCategoryBinding binding;

@Inject TaxonomyStore mTaxonomyStore;

Expand All @@ -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);

Expand Down Expand Up @@ -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;
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 5095884

Please sign in to comment.