Skip to content

Commit

Permalink
Fix for grid layout crash
Browse files Browse the repository at this point in the history
  • Loading branch information
SamAmco committed Aug 19, 2021
1 parent bad50e2 commit 097e8d0
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import org.threeten.bp.Instant
import org.threeten.bp.OffsetDateTime
import java.lang.Float.min

/**
* The group fragment is used on the home page and in any nested group to display the contents of
Expand Down Expand Up @@ -292,8 +293,11 @@ class GroupFragment : Fragment(), YesCancelDialogFragment.YesCancelDialogListene
private fun initializeGridLayout() {
val dm = resources.displayMetrics
val screenWidth = dm.widthPixels / dm.density
val itemSize = 180f
val gridLayout = GridLayoutManager(context, (screenWidth / itemSize).toInt())
val itemSize = (screenWidth / 2f).coerceAtMost(180f)
val gridLayout = GridLayoutManager(
context,
(screenWidth / itemSize).coerceAtLeast(2f).toInt()
)
gridLayout.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() {
override fun getSpanSize(position: Int): Int {
return adapter.getSpanSizeAtPosition(position)
Expand Down

0 comments on commit 097e8d0

Please sign in to comment.