Add FreeGridLayoutManager
This commit is contained in:
parent
16c770b7c2
commit
bc4c30e6af
2 changed files with 18 additions and 1 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue