/
ItemsSelectionFragment.kt
65 lines (55 loc) · 1.93 KB
/
ItemsSelectionFragment.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package fhuyakou.godot.app.android.gltfviewer
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
/**
* A fragment representing a list of Items.
*/
class ItemsSelectionFragment : Fragment(), GLTFItemRecyclerViewAdapter.Listener {
private var columnCount = 1
companion object {
const val ARG_COLUMN_COUNT = "column-count"
@JvmStatic
fun newInstance(columnCount: Int) =
ItemsSelectionFragment().apply {
arguments = Bundle().apply {
putInt(ARG_COLUMN_COUNT, columnCount)
}
}
}
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_items_selection_list, container, false)
// Set the adapter
if (view is RecyclerView) {
with(view) {
layoutManager = when {
columnCount <= 1 -> LinearLayoutManager(context)
else -> GridLayoutManager(context, columnCount)
}
adapter = GLTFItemRecyclerViewAdapter(context, GLTFContent.ITEMS,
this@ItemsSelectionFragment)
}
}
return view
}
override fun onItemSelected(item: GLTFContent.GLTFItem) {
val parentActivity = activity
if (parentActivity is MainActivity) {
parentActivity.appPlugin?.showGLTF(item.glbFilepath)
}
}
}