diff --git a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryEventListener.kt b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryEventListener.kt index 1724c36e..65433104 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryEventListener.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryEventListener.kt @@ -1,5 +1,5 @@ package net.pengcook.android.presentation.category interface CategoryEventListener { - fun onNavigateToRecipesByCategory(categoryId: Long) + fun onCategorySelect(categoryId: Long) } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryFragment.kt b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryFragment.kt index 95a2fe42..3f7071ab 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryFragment.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryFragment.kt @@ -41,13 +41,12 @@ class CategoryFragment : Fragment() { ) } adapter.submitList(categories) - val spacingInPixels = resources.getDimensionPixelSize(R.dimen.item_spacing_category) - binding.rvCategory.addItemDecoration(GridSpacingItemDecoration(3, spacingInPixels, false)) + binding.rvCategory.addItemDecoration(GridSpacingItemDecoration(3, spacingInPixels)) } - override fun onDestroy() { - super.onDestroy() + override fun onDestroyView() { + super.onDestroyView() _binding = null } } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryViewModel.kt b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryViewModel.kt index 06feb32b..8550fe6e 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryViewModel.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/category/CategoryViewModel.kt @@ -3,6 +3,6 @@ package net.pengcook.android.presentation.category import androidx.lifecycle.ViewModel class CategoryViewModel : ViewModel(), CategoryEventListener { - override fun onNavigateToRecipesByCategory(categoryId: Long) { + override fun onCategorySelect(categoryId: Long) { } } diff --git a/android/app/src/main/java/net/pengcook/android/presentation/core/style/GridSpacingItemDecoration.kt b/android/app/src/main/java/net/pengcook/android/presentation/core/style/GridSpacingItemDecoration.kt index 408f6bf1..c91629ae 100644 --- a/android/app/src/main/java/net/pengcook/android/presentation/core/style/GridSpacingItemDecoration.kt +++ b/android/app/src/main/java/net/pengcook/android/presentation/core/style/GridSpacingItemDecoration.kt @@ -7,7 +7,6 @@ import androidx.recyclerview.widget.RecyclerView class GridSpacingItemDecoration( private val spanCount: Int, private val spacing: Int, - private val includeEdge: Boolean, ) : RecyclerView.ItemDecoration() { override fun getItemOffsets( outRect: Rect, @@ -18,21 +17,11 @@ class GridSpacingItemDecoration( val position = parent.getChildAdapterPosition(view) val column = position % spanCount - if (includeEdge) { - outRect.left = spacing - column * spacing / spanCount - outRect.right = (column + 1) * spacing / spanCount - - if (position < spanCount) { - outRect.top = spacing - } - outRect.bottom = spacing / 2 - } else { - outRect.left = column * spacing / spanCount - outRect.right = spacing - (column + 1) * spacing / spanCount - if (position >= spanCount) { - outRect.top = spacing - } - outRect.bottom = spacing + outRect.left = column * spacing / spanCount + outRect.right = spacing - (column + 1) * spacing / spanCount + if (position >= spanCount) { + outRect.top = spacing } + outRect.bottom = spacing } } diff --git a/android/app/src/main/res/layout/item_category.xml b/android/app/src/main/res/layout/item_category.xml index 5a557983..571aa687 100644 --- a/android/app/src/main/res/layout/item_category.xml +++ b/android/app/src/main/res/layout/item_category.xml @@ -17,7 +17,7 @@ + android:onClick="@{() -> categoryEventListener.onCategorySelect(category.id)}">