Add FreeGridLayoutManager

This commit is contained in:
Lucas Lima 2020-06-19 21:40:28 -03:00
parent 16c770b7c2
commit bc4c30e6af
No known key found for this signature in database
GPG key ID: 0259A3F43EC1027A
2 changed files with 18 additions and 1 deletions

View file

@ -19,6 +19,7 @@ import dev.lucasnlm.antimine.common.level.view.SpaceItemDecoration
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModelFactory
import dev.lucasnlm.antimine.common.level.widget.FixedGridLayoutManager
import dev.lucasnlm.antimine.common.level.widget.FreeGridLayoutManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
@ -166,7 +167,7 @@ open class LevelFragment : DaggerFragment() {
}
private fun makeNewLayoutManager(boardWidth: Int, boardHeight: Int) =
FixedGridLayoutManager(boardWidth, calcHorizontalPadding(boardWidth), calcVerticalPadding(boardHeight))
FreeGridLayoutManager(boardWidth)
private fun calcHorizontalPadding(boardWidth: Int): Int =
((recyclerGrid.measuredWidth - dimensionRepository.areaSizeWithPadding() * boardWidth) / 2)

View file

@ -0,0 +1,16 @@
package dev.lucasnlm.antimine.common.level.widget
import androidx.recyclerview.widget.RecyclerView
class FreeGridLayoutManager(
private val maxColumnCount: Int
) : RecyclerView.LayoutManager() {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
return RecyclerView.LayoutParams(
RecyclerView.LayoutParams.MATCH_PARENT,
RecyclerView.LayoutParams.MATCH_PARENT
)
}
}