diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt
index 9502d07e84b..ca68868339f 100644
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryFragment.kt
@@ -106,6 +106,10 @@ class AddProductCategoryFragment :
}
}
+ binding.clearParentCategory.setOnClickListener {
+ viewModel.onClearParentCategoryClicked()
+ }
+
with(binding.productCategoryParent) {
viewModel.getSelectedParentCategoryName()?.let { setText(it) }
setClickListener {
@@ -160,11 +164,18 @@ class AddProductCategoryFragment :
}
new.selectedParentId.takeIfNotEqualTo(old?.selectedParentId) {
val parentCategoryName = viewModel.getSelectedParentCategoryName()
- parentCategoryName?.let { binding.productCategoryParent.setHtmlText(it) }
+ if (parentCategoryName != null) {
+ binding.productCategoryParent.setHtmlText(parentCategoryName)
+ } else {
+ binding.productCategoryParent.setHtmlText("")
+ }
}
new.isEditingMode.takeIfNotEqualTo(old?.isEditingMode) {
deleteMenuItem?.isVisible = it
}
+ new.selectedParentId.takeIfNotEqualTo(old?.selectedParentId) {
+ binding.clearParentCategory.isEnabled = it != 0L && it != null
+ }
}
viewModel.event.observe(viewLifecycleOwner) { event ->
diff --git a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryViewModel.kt b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryViewModel.kt
index 63d8b7959e3..0b1e19454be 100644
--- a/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryViewModel.kt
+++ b/WooCommerce/src/main/kotlin/com/woocommerce/android/ui/products/categories/AddProductCategoryViewModel.kt
@@ -84,6 +84,10 @@ class AddProductCategoryViewModel @Inject constructor(
}
}
+ fun onClearParentCategoryClicked() {
+ addProductCategoryViewState = addProductCategoryViewState.copy(selectedParentId = 0L)
+ }
+
fun onCategoryNameChanged(categoryName: String) {
addProductCategoryViewState = if (categoryName.isEmpty()) {
addProductCategoryViewState.copy(
diff --git a/WooCommerce/src/main/res/layout/fragment_add_product_category.xml b/WooCommerce/src/main/res/layout/fragment_add_product_category.xml
index 919aa198d0d..46aa019c9ae 100644
--- a/WooCommerce/src/main/res/layout/fragment_add_product_category.xml
+++ b/WooCommerce/src/main/res/layout/fragment_add_product_category.xml
@@ -20,7 +20,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:paddingBottom="@dimen/major_100"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar">
@@ -53,5 +52,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/product_category_name" />
+
+
+
diff --git a/WooCommerce/src/main/res/values/strings.xml b/WooCommerce/src/main/res/values/strings.xml
index a37dbf3f2de..8ab5bf8a32e 100644
--- a/WooCommerce/src/main/res/values/strings.xml
+++ b/WooCommerce/src/main/res/values/strings.xml
@@ -2050,6 +2050,7 @@
No price set
Categories
Add category
+ Clear parent category
Add your first category
Organise your products in categories
Add category