1
+ package org.buffer.android.components
2
+
3
+ import android.buffer.org.ui_kit.R
4
+ import android.content.Context
5
+ import android.view.View
6
+ import android.widget.AdapterView
7
+ import android.widget.ArrayAdapter
8
+ import android.widget.LinearLayout
9
+ import androidx.annotation.StringRes
10
+ import com.google.android.material.bottomsheet.BottomSheetDialog
11
+ import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.list_item_selection_sheet_options
12
+ import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.text_item_selection_message
13
+ import kotlinx.android.synthetic.main.view_item_selection_message_sheet.view.text_item_selection_title
14
+
15
+ object BottomSheetFactory {
16
+
17
+ fun createTextItemSelectionBottomSheet (
18
+ context : Context ,
19
+ @StringRes titleResource : Int? = null,
20
+ adapter : ArrayAdapter <* >,
21
+ listener : AdapterView .OnItemClickListener ,
22
+ footerView : View ? = null
23
+ ): BottomSheetDialog {
24
+ return createTextItemSelectionBottomSheet(context, titleResource, messageResource = null ,
25
+ adapter = adapter, listener = listener, footerView = footerView)
26
+ }
27
+
28
+ fun createTextItemSelectionBottomSheet (
29
+ context : Context ,
30
+ @StringRes titleResource : Int? = null,
31
+ @StringRes messageResource : Int? = null,
32
+ adapter : ArrayAdapter <* >,
33
+ listener : AdapterView .OnItemClickListener ,
34
+ footerView : View ? = null
35
+ ): BottomSheetDialog {
36
+ val title = titleResource?.let { context.getString(titleResource) } ? : kotlin.run { null }
37
+ val message = messageResource?.let { context.getString(messageResource) }
38
+ ? : kotlin.run { null }
39
+ return createTextItemSelectionBottomSheet(context, title, message, adapter, listener,
40
+ footerView)
41
+ }
42
+
43
+ fun createTextItemSelectionBottomSheet (
44
+ context : Context ,
45
+ title : String? = null,
46
+ message : String? = null,
47
+ adapter : ArrayAdapter <* >,
48
+ listener : AdapterView .OnItemClickListener ,
49
+ footerView : View ? = null
50
+ ): BottomSheetDialog {
51
+ return BottomSheetDialog (context, R .style.BottomSheetDialog ).apply {
52
+ val view = layoutInflater.inflate(R .layout.view_item_selection_message_sheet, null )
53
+ as LinearLayout
54
+ title?.let {
55
+ view.text_item_selection_title.text = title
56
+ } ? : run {
57
+ view.text_item_selection_title.visibility = View .GONE
58
+ }
59
+ message?.let {
60
+ view.text_item_selection_message.text = message
61
+ } ? : run {
62
+ view.text_item_selection_message.visibility = View .GONE
63
+ }
64
+ view.list_item_selection_sheet_options.adapter = adapter
65
+ view.list_item_selection_sheet_options.onItemClickListener = listener
66
+ footerView?.let { view.addView(footerView) }
67
+ setContentView(view)
68
+ }
69
+ }
70
+ }
0 commit comments