Skip to content

Commit 39837ce

Browse files
committed
Copy dialog and bottom sheet factories from Buffer publish
1 parent 2b78690 commit 39837ce

File tree

11 files changed

+598
-1
lines changed

11 files changed

+598
-1
lines changed

app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ android {
2121
dependencies {
2222
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
2323
implementation 'com.android.support:appcompat-v7:28.0.0'
24-
24+
implementation 'com.google.android.material:material:1.0.0'
2525
implementation 'org.buffer.android:counter-view:1.0'
2626
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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

Comments
 (0)