Skip to content

Commit

Permalink
Expose numColumns directly in the sample app.
Browse files Browse the repository at this point in the history
  • Loading branch information
colinrtwhite committed Aug 16, 2019
1 parent bab47e3 commit ceee5a6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions coil-sample/src/main/java/coil/sample/ImageListAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ImageListAdapter(

private val maxColumnWidth = 320.dp(context)
private val displayWidth = context.getDisplaySize().width
private val numColumns = ceil(displayWidth / maxColumnWidth).toInt()
val numColumns = ceil(displayWidth / maxColumnWidth).toInt()
private val columnWidth = (displayWidth / numColumns.toDouble()).roundToInt()

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
Expand All @@ -49,8 +49,6 @@ class ImageListAdapter(
}
}

fun numColumns() = numColumns

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val image = itemView as ImageView
}
Expand Down
2 changes: 1 addition & 1 deletion coil-sample/src/main/java/coil/sample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MainActivity : AppCompatActivity() {
val listAdapter = ImageListAdapter(this, viewModel.screenLiveData::setValue)
list.apply {
setHasFixedSize(true)
layoutManager = StaggeredGridLayoutManager(listAdapter.numColumns(), StaggeredGridLayoutManager.VERTICAL)
layoutManager = StaggeredGridLayoutManager(listAdapter.numColumns, StaggeredGridLayoutManager.VERTICAL)
adapter = listAdapter
}

Expand Down

0 comments on commit ceee5a6

Please sign in to comment.