@@ -15,44 +15,38 @@ import com.google.android.material.button.MaterialButton
15
15
import com.harunbekcan.sampleandroidproject.BR
16
16
import com.harunbekcan.sampleandroidproject.R
17
17
import com.harunbekcan.sampleandroidproject.data.BottomSheetModel
18
+ import com.harunbekcan.sampleandroidproject.databinding.BottomSheetLayoutBinding
18
19
import com.harunbekcan.sampleandroidproject.databinding.ItemBottomSheetLayoutBinding
19
20
20
21
class BottomSheetDialog : BottomSheetDialogFragment () {
21
22
22
23
var adapter: LastAdapter ? = null
23
24
private var titleText: String = " "
24
25
private lateinit var titleTextView: TextView
25
- var listener : BottomSheetListener ? = null
26
+ var itemClickListener : BottomSheetItemClickListener ? = null
26
27
var approveButtonListener: BottomSheetApproveButtonListener ? = null
27
- private lateinit var recyclerView: RecyclerView
28
- private lateinit var approveButton: MaterialButton
29
28
var bottomSheetAdapterList = ArrayList <Any >()
30
29
31
30
@Nullable
32
31
override fun onCreateView (
33
- @NonNull inflater : LayoutInflater ,
34
- @Nullable container : ViewGroup ? ,
35
- @Nullable savedInstanceState : Bundle ? ,
32
+ inflater : LayoutInflater ,
33
+ container : ViewGroup ? ,
34
+ savedInstanceState : Bundle ? ,
36
35
): View {
37
- return inflater.inflate(R .layout.bottom_sheet_layout, container, false )
36
+ val rootView = BottomSheetLayoutBinding .inflate(inflater,container,false )
37
+ initAdapter(rootView)
38
+ titleTextView = rootView.bottomSheetTitleTextView
39
+ titleTextView.text = titleText
40
+ return rootView.root
38
41
}
39
42
40
43
companion object {
41
44
val instance: BottomSheetDialog
42
45
get() = BottomSheetDialog ()
43
46
}
44
47
45
- override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
46
- super .onViewCreated(view, savedInstanceState)
47
- recyclerView = view.findViewById(R .id.bottomSheetRecyclerView)
48
- titleTextView = view.findViewById(R .id.bottomSheetTitleTextView)
49
- titleTextView.text = titleText
50
- approveButton = view.findViewById(R .id.approveButton)
51
- initAdapter()
52
- }
53
-
54
- private fun initAdapter () {
55
- adapter = view?.findViewById<RecyclerView >(R .id.bottomSheetRecyclerView)?.let {
48
+ private fun initAdapter (rootView : BottomSheetLayoutBinding ) {
49
+ adapter = rootView.bottomSheetRecyclerView.let {
56
50
LastAdapter (bottomSheetAdapterList, BR .item)
57
51
.map<BottomSheetModel >(
58
52
Type <ItemBottomSheetLayoutBinding >(R .layout.item_bottom_sheet_layout).onBind { holder ->
@@ -62,19 +56,19 @@ class BottomSheetDialog : BottomSheetDialogFragment() {
62
56
holder.binding.languageBottomSheetRadioButton.isChecked = it.isSelected
63
57
64
58
holder.binding.container.setOnClickListener {
65
- listener ?.bottomSheetItemClick(
59
+ itemClickListener ?.bottomSheetItemClick(
66
60
holder.binding.item as BottomSheetModel ,
67
61
holder.layoutPosition
68
62
)
69
63
}
70
- approveButton.setOnClickListener {
64
+ rootView. approveButton.setOnClickListener {
71
65
approveButtonListener?.approveItemClick(
72
66
holder.binding.item as BottomSheetModel ,
73
67
holder.layoutPosition
74
68
)
75
69
}
76
70
}
77
- }).into(recyclerView )
71
+ }).into(rootView.bottomSheetRecyclerView )
78
72
}
79
73
}
80
74
@@ -84,7 +78,7 @@ class BottomSheetDialog : BottomSheetDialogFragment() {
84
78
}
85
79
86
80
/* * BottomSheet RecList item listener **/
87
- interface BottomSheetListener {
81
+ interface BottomSheetItemClickListener {
88
82
fun bottomSheetItemClick (item : Any , layoutPosition : Int )
89
83
}
90
84
0 commit comments