61 lines
No EOL
1.7 KiB
Kotlin
61 lines
No EOL
1.7 KiB
Kotlin
package com.example.palto
|
|
|
|
import android.os.Bundle
|
|
import androidx.fragment.app.Fragment
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
import androidx.recyclerview.widget.LinearLayoutManager
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
import android.view.LayoutInflater
|
|
import android.view.View
|
|
import android.view.ViewGroup
|
|
import com.example.palto.placeholder.PlaceholderContent
|
|
|
|
/**
|
|
* A fragment representing a list of Items.
|
|
*/
|
|
class ItemFragment : Fragment() {
|
|
|
|
private var columnCount = 1
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
super.onCreate(savedInstanceState)
|
|
|
|
arguments?.let {
|
|
columnCount = it.getInt(ARG_COLUMN_COUNT)
|
|
}
|
|
}
|
|
|
|
override fun onCreateView(
|
|
inflater: LayoutInflater, container: ViewGroup?,
|
|
savedInstanceState: Bundle?
|
|
): View? {
|
|
val view = inflater.inflate(R.layout.fragment_item_list, container, false)
|
|
|
|
// Set the adapter
|
|
if (view is RecyclerView) {
|
|
with(view) {
|
|
layoutManager = when {
|
|
columnCount <= 1 -> LinearLayoutManager(context)
|
|
else -> GridLayoutManager(context, columnCount)
|
|
}
|
|
adapter = MyItemRecyclerViewAdapter(PlaceholderContent.ITEMS)
|
|
}
|
|
}
|
|
return view
|
|
}
|
|
|
|
companion object {
|
|
|
|
// TODO: Customize parameter argument names
|
|
const val ARG_COLUMN_COUNT = "column-count"
|
|
|
|
// TODO: Customize parameter initialization
|
|
@JvmStatic
|
|
fun newInstance(columnCount: Int) =
|
|
ItemFragment().apply {
|
|
arguments = Bundle().apply {
|
|
putInt(ARG_COLUMN_COUNT, columnCount)
|
|
}
|
|
}
|
|
}
|
|
} |