Skip to content

Commit

Permalink
♻️ reflect code reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
kmkim2689 authored and Hogu59 committed Jul 25, 2024
1 parent 27235be commit dc15f94
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package net.pengcook.android.presentation.category

interface CategoryEventListener {
fun onNavigateToRecipesByCategory(categoryId: Long)
fun onCategorySelect(categoryId: Long)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion android/app/src/main/res/layout/item_category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="@{() -> categoryEventListener.onNavigateToRecipesByCategory(category.id)}">
android:onClick="@{() -> categoryEventListener.onCategorySelect(category.id)}">

<ImageView
android:id="@+id/iv_category"
Expand Down

0 comments on commit dc15f94

Please sign in to comment.