├── .gitignore
├── LICENSE
├── README.md
├── art
├── ss1.png
├── ss2.png
└── ss3.png
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── kennyc
│ │ └── bottomsheet
│ │ ├── BottomSheetListener.kt
│ │ ├── BottomSheetMenuDialogFragment.kt
│ │ ├── adapters
│ │ ├── GridAdapter.kt
│ │ └── ViewHolder.kt
│ │ └── menu
│ │ ├── BottomSheetMenu.kt
│ │ ├── BottomSheetMenuItem.kt
│ │ └── BottomSheetViewModel.kt
│ └── res
│ ├── drawable
│ └── ic_baseline_close_24.xml
│ ├── layout
│ ├── bottom_sheet_grid_item.xml
│ ├── bottom_sheet_list_item.xml
│ └── bottom_sheet_menu.xml
│ ├── values-sw600dp
│ └── bools.xml
│ └── values
│ ├── attrs.xml
│ ├── bools.xml
│ ├── dimens.xml
│ └── styles.xml
├── sample
├── .gitignore
├── build.gradle
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── kennyc
│ │ └── bottomsheetsample
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable-hdpi
│ ├── ic_close_grey_600_48dp.png
│ ├── ic_cloud_upload_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_48dp.png
│ ├── ic_delete_grey_600_48dp.png
│ ├── ic_edit_grey_600_48dp.png
│ ├── ic_mail_grey_600_48dp.png
│ ├── ic_print_grey_600_24dp.png
│ ├── ic_save_grey_600_48dp.png
│ └── ic_share_grey_600_24dp.png
│ ├── drawable-mdpi
│ ├── ic_close_grey_600_48dp.png
│ ├── ic_cloud_upload_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_48dp.png
│ ├── ic_delete_grey_600_48dp.png
│ ├── ic_edit_grey_600_48dp.png
│ ├── ic_mail_grey_600_48dp.png
│ ├── ic_print_grey_600_24dp.png
│ ├── ic_save_grey_600_48dp.png
│ └── ic_share_grey_600_24dp.png
│ ├── drawable-xhdpi
│ ├── ic_close_grey_600_48dp.png
│ ├── ic_cloud_upload_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_48dp.png
│ ├── ic_delete_grey_600_48dp.png
│ ├── ic_edit_grey_600_48dp.png
│ ├── ic_mail_grey_600_48dp.png
│ ├── ic_print_grey_600_24dp.png
│ ├── ic_save_grey_600_48dp.png
│ └── ic_share_grey_600_24dp.png
│ ├── drawable-xxhdpi
│ ├── ic_close_grey_600_48dp.png
│ ├── ic_cloud_upload_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_48dp.png
│ ├── ic_delete_grey_600_48dp.png
│ ├── ic_edit_grey_600_48dp.png
│ ├── ic_mail_grey_600_48dp.png
│ ├── ic_print_grey_600_24dp.png
│ ├── ic_save_grey_600_48dp.png
│ └── ic_share_grey_600_24dp.png
│ ├── drawable-xxxhdpi
│ ├── ic_close_grey_600_48dp.png
│ ├── ic_cloud_upload_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_24dp.png
│ ├── ic_content_copy_grey_600_48dp.png
│ ├── ic_delete_grey_600_48dp.png
│ ├── ic_edit_grey_600_48dp.png
│ ├── ic_mail_grey_600_48dp.png
│ ├── ic_print_grey_600_24dp.png
│ ├── ic_save_grey_600_48dp.png
│ └── ic_share_grey_600_24dp.png
│ ├── layout
│ └── activity_main.xml
│ ├── menu
│ ├── grid_sheet.xml
│ ├── list_sheet.xml
│ └── main.xml
│ ├── mipmap-hdpi
│ └── ic_launcher.png
│ ├── mipmap-mdpi
│ └── ic_launcher.png
│ ├── mipmap-xhdpi
│ └── ic_launcher.png
│ ├── mipmap-xxhdpi
│ └── ic_launcher.png
│ ├── values-w820dp
│ └── dimens.xml
│ └── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by https://www.gitignore.io
2 |
3 | ### Android ###
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
25 | # Log Files
26 | *.log
27 |
28 |
29 | ### Intellij ###
30 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
31 |
32 | *.iml
33 |
34 | ## Directory-based project format:
35 | .idea/
36 | # if you remove the above rule, at least ignore the following:
37 |
38 | # User-specific stuff:
39 | # .idea/workspace.xml
40 | # .idea/tasks.xml
41 | # .idea/dictionaries
42 |
43 | # Sensitive or high-churn files:
44 | # .idea/dataSources.ids
45 | # .idea/dataSources.xml
46 | # .idea/sqlDataSources.xml
47 | # .idea/dynamic.xml
48 | # .idea/uiDesigner.xml
49 |
50 | # Gradle:
51 | # .idea/gradle.xml
52 | # .idea/libraries
53 |
54 | # Mongo Explorer plugin:
55 | # .idea/mongoSettings.xml
56 |
57 | ## File-based project format:
58 | *.ipr
59 | *.iws
60 |
61 | ## Plugin-specific files:
62 |
63 | # IntelliJ
64 | out/
65 |
66 | # mpeltonen/sbt-idea plugin
67 | .idea_modules/
68 |
69 | # JIRA plugin
70 | atlassian-ide-plugin.xml
71 |
72 | # Crashlytics plugin (for Android Studio and IntelliJ)
73 | com_crashlytics_export_strings.xml
74 |
75 | # Ignore Gradle GUI config
76 | gradle-app.setting
77 |
78 | # Mobile Tools for Java (J2ME)
79 | .mtj.tmp/
80 |
81 | # Package Files #
82 | *.war
83 | *.ear
84 |
85 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
86 | hs_err_pid*
87 |
88 | *.DS_Store
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # BottomSheetMenu
2 | [](https://android-arsenal.com/details/1/2315)
3 |
4 |
5 |
6 |
7 |
8 | # Features
9 | - Both list and grid style
10 | - Light, Dark, and DayNight theme as well as custom themeing options
11 | - Material3 Theme support
12 | - XML style support
13 | - Tablet support
14 | - API 21+
15 | - Kotlin support
16 |
17 |
18 | # Using BottomSheetMenu
19 | To get started using BottomSheetMenu, first you'll need to create a menu resource file with the defined actions.
20 | ```xml
21 |
22 |
45 | ```
46 |
47 | Then create a BottomSheetMenuDialogFragment via the Builder class using either the Builder method calls for java
48 | or named arguments for Kotlin
49 | ```java
50 | new BottomSheetMenuDialogFragment.Builder(getActivity())
51 | .setSheet(R.menu.bottom_sheet)
52 | .setTitle(R.string.options)
53 | .setListener(myListener)
54 | .setObject(myObject)
55 | .show(getSupportFragmentManager());
56 | ```
57 |
58 | ```kotilin
59 | BottomSheetMenuDialogFragment.Builder(context = this,
60 | sheet = R.menu.bottom_sheet,
61 | listener = myListener,
62 | title = R.string.options,
63 | `object` = myObject)
64 | .show(supportFragmentManager)
65 | ```
66 | # Styling
67 | BottomSheetMenu comes with both a Light and Dark theme to accommodate most scenarios. However, if you want to customize itr more, you can create your own style and supply it to the builder.
68 | Customizable attributes are:
69 | ```xml
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 | ```
88 |
89 | Then create a style
90 | ```xml
91 |
96 |
97 |
100 |
101 |
105 |
106 |
110 | ```
111 | Also note that each of these pre-defined styles also have a light and DayNight theme. They are named similary with a `.Light` or `DayNight` added to the end of the style name
112 | `@style/Theme.BottomSheetMenuDialog.Light` `@style/BottomSheetMenu.Title.TextAppearance.Light` etc...
113 |
114 |
115 | Then finally pass the style into the `Builder` object.
116 | ```java
117 | new BottomSheetMenuDialogFragment.Builder(getActivity(), R.style.MyBottomSheetStyle)
118 | .setSheet(R.menu.bottom_sheet)
119 | .setTitle(R.string.options)
120 | .setListener(myListener)
121 | .show();
122 | ```
123 |
124 | ```kotlin
125 | BottomSheetMenuDialogFragment.Builder(context = this,
126 | sheet = R.menu.bottom_sheet,
127 | title = R.string.options,
128 | listener = myListener,
129 | style = R.style.MyBottomSheetStyle)
130 | .show(supportFragmentManager)
131 | ```
132 |
133 | # Callbacks
134 | BottomSheetMenu uses the [BottomSheetListener](https://github.com/Kennyc1012/BottomSheetMenu/blob/master/library/src/main/java/com/kennyc/bottomsheet/BottomSheetListener.kt) for callbacks
135 | ```kotlin
136 | /**
137 | * Called when the [BottomSheetMenuDialogFragment] is first displayed
138 | *
139 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that was shown
140 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
141 | */
142 | fun onSheetShown(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?)
143 |
144 | /**
145 | * Called when an item is selected from the list/grid of the [BottomSheetMenuDialogFragment]
146 | *
147 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that had an item selected
148 | * @param item The item that was selected
149 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
150 | */
151 | fun onSheetItemSelected(bottomSheet: BottomSheetMenuDialogFragment, item: MenuItem, `object`: Any?)
152 |
153 | /**
154 | * Called when the [BottomSheetMenuDialogFragment] has been dismissed
155 | *
156 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that was dismissed
157 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
158 | * @param dismissEvent How the [BottomSheetMenuDialogFragment] was dismissed. Possible values are:
159 | * * [.DISMISS_EVENT_SWIPE]
160 | * * [.DISMISS_EVENT_MANUAL]
161 | * * [.DISMISS_EVENT_ITEM_SELECTED]
162 | */
163 | fun onSheetDismissed(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?, @DismissEvent dismissEvent: Int)
164 | ```
165 |
166 | # Upgrading to 5.X
167 | - Removed various `createShareBottomSheet` methods
168 | - Targeting Android SDK 34
169 | - Targeting Kotlin 1.8.22
170 |
171 | # Upgrading to 4.X
172 | - Styles now extend Theme.Material3.* themes
173 | - An app's style should inherit from a MaterialComponent theme. Material3 themes are preferred but not required.
174 | - Removed `bottom_sheet_menu_selector` attribute
175 | - Removed various resources
176 | - Java 11 is now required to compile project
177 | - MinSdk is now 21, also targeting API 31
178 |
179 | # Upgrading to 3.X
180 | - `BottomSheet` has been renamed to `BottomSheetMenuDialogFragment`
181 | - Custom views and simple messages are no longer supported. Please use a [BottomSheetDialogFragment](https://developer.android.com/reference/com/google/android/material/bottomsheet/BottomSheetDialogFragment) and customize it from there
182 | - Many of the theme attributes have been removed or renamed. See the Styling section above for current values
183 | - CollaspingView has been removed.
184 | - Migration to [AndroidX](https://developer.android.com/jetpack/androidx/) and [Google Material Components](https://github.com/material-components/material-components-android)
185 | - MinSdk is now 19, also targeting API 28
186 |
187 | # Upgrading From 1.x
188 | When upgrading to 2.x from a 1.x release, some changes will have to be made.
189 | - All of the builder methods for settings colors have been removed. All customzing should be done through themes.
190 | - The style attributes have been change to text appearances rather than colors.
191 | - The Builder constructor no longer takes a menu object. You will need to call ```setSheet(...)```.
192 | - The ```onSheetDismissed``` callback now takes an int as an argument for simple message support.
193 | - The gradle dependency has changed and needs to be updated.
194 |
195 | # Including in your project
196 | To include BottomSheet in your project, make the following changes to your build.gradle file
197 |
198 | ## Add repository
199 | ```groovy
200 | allprojects {
201 | repositories {
202 | ...
203 | maven { url "https://jitpack.io" }
204 | }
205 | }
206 | ```
207 | ## Add dependency
208 | ```groovy
209 | dependencies {
210 | implementation "com.github.Kennyc1012:BottomSheetMenu:5.1.1"
211 | ```
212 |
213 | # Contribution
214 | Pull requests are welcomed and encouraged. If you experience any bugs, please file an [issue](https://github.com/Kennyc1012/BottomSheet/issues)
215 |
216 | License
217 | =======
218 |
219 | Copyright 2015 Kenny Campagna
220 |
221 | Licensed under the Apache License, Version 2.0 (the "License");
222 | you may not use this file except in compliance with the License.
223 | You may obtain a copy of the License at
224 |
225 | http://www.apache.org/licenses/LICENSE-2.0
226 |
227 | Unless required by applicable law or agreed to in writing, software
228 | distributed under the License is distributed on an "AS IS" BASIS,
229 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
230 | See the License for the specific language governing permissions and
231 | limitations under the License.
232 |
--------------------------------------------------------------------------------
/art/ss1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennyc1012/BottomSheetMenu/0a2213a2907d0a89018ee0cb12df1d72840b53bf/art/ss1.png
--------------------------------------------------------------------------------
/art/ss2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennyc1012/BottomSheetMenu/0a2213a2907d0a89018ee0cb12df1d72840b53bf/art/ss2.png
--------------------------------------------------------------------------------
/art/ss3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennyc1012/BottomSheetMenu/0a2213a2907d0a89018ee0cb12df1d72840b53bf/art/ss3.png
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | buildscript {
3 | ext.kotlin_version = '1.9.21'
4 | ext.sdk_version = 34
5 |
6 | repositories {
7 | jcenter()
8 | google()
9 | }
10 |
11 | dependencies {
12 | classpath 'com.android.tools.build:gradle:8.3.2'
13 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
14 | // NOTE: Do not place your application dependencies here; they belong
15 | // in the individual module build.gradle files
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | jcenter()
22 | google()
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | android.useAndroidX=true
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Kennyc1012/BottomSheetMenu/0a2213a2907d0a89018ee0cb12df1d72840b53bf/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Mar 14 07:55:52 EDT 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 | yes | $ANDROID_HOME/tools/bin/sdkmanager "build-tools;28.0.3"
3 |
4 | ##############################################################################
5 | ##
6 | ## Gradle start up script for UN*X
7 | ##
8 | ##############################################################################
9 |
10 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
11 | DEFAULT_JVM_OPTS=""
12 |
13 | APP_NAME="Gradle"
14 | APP_BASE_NAME=`basename "$0"`
15 |
16 | # Use the maximum available, or set MAX_FD != -1 to use that value.
17 | MAX_FD="maximum"
18 |
19 | warn ( ) {
20 | echo "$*"
21 | }
22 |
23 | die ( ) {
24 | echo
25 | echo "$*"
26 | echo
27 | exit 1
28 | }
29 |
30 | # OS specific support (must be 'true' or 'false').
31 | cygwin=false
32 | msys=false
33 | darwin=false
34 | case "`uname`" in
35 | CYGWIN* )
36 | cygwin=true
37 | ;;
38 | Darwin* )
39 | darwin=true
40 | ;;
41 | MINGW* )
42 | msys=true
43 | ;;
44 | esac
45 |
46 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
47 | if $cygwin ; then
48 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
49 | fi
50 |
51 | # Attempt to set APP_HOME
52 | # Resolve links: $0 may be a link
53 | PRG="$0"
54 | # Need this for relative symlinks.
55 | while [ -h "$PRG" ] ; do
56 | ls=`ls -ld "$PRG"`
57 | link=`expr "$ls" : '.*-> \(.*\)$'`
58 | if expr "$link" : '/.*' > /dev/null; then
59 | PRG="$link"
60 | else
61 | PRG=`dirname "$PRG"`"/$link"
62 | fi
63 | done
64 | SAVED="`pwd`"
65 | cd "`dirname \"$PRG\"`/" >&-
66 | APP_HOME="`pwd -P`"
67 | cd "$SAVED" >&-
68 |
69 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
70 |
71 | # Determine the Java command to use to start the JVM.
72 | if [ -n "$JAVA_HOME" ] ; then
73 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
74 | # IBM's JDK on AIX uses strange locations for the executables
75 | JAVACMD="$JAVA_HOME/jre/sh/java"
76 | else
77 | JAVACMD="$JAVA_HOME/bin/java"
78 | fi
79 | if [ ! -x "$JAVACMD" ] ; then
80 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
81 |
82 | Please set the JAVA_HOME variable in your environment to match the
83 | location of your Java installation."
84 | fi
85 | else
86 | JAVACMD="java"
87 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
88 |
89 | Please set the JAVA_HOME variable in your environment to match the
90 | location of your Java installation."
91 | fi
92 |
93 | # Increase the maximum file descriptors if we can.
94 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
95 | MAX_FD_LIMIT=`ulimit -H -n`
96 | if [ $? -eq 0 ] ; then
97 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
98 | MAX_FD="$MAX_FD_LIMIT"
99 | fi
100 | ulimit -n $MAX_FD
101 | if [ $? -ne 0 ] ; then
102 | warn "Could not set maximum file descriptor limit: $MAX_FD"
103 | fi
104 | else
105 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
106 | fi
107 | fi
108 |
109 | # For Darwin, add options to specify how the application appears in the dock
110 | if $darwin; then
111 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
112 | fi
113 |
114 | # For Cygwin, switch paths to Windows format before running java
115 | if $cygwin ; then
116 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
117 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
118 |
119 | # We build the pattern for arguments to be converted via cygpath
120 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
121 | SEP=""
122 | for dir in $ROOTDIRSRAW ; do
123 | ROOTDIRS="$ROOTDIRS$SEP$dir"
124 | SEP="|"
125 | done
126 | OURCYGPATTERN="(^($ROOTDIRS))"
127 | # Add a user-defined pattern to the cygpath arguments
128 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
129 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
130 | fi
131 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
132 | i=0
133 | for arg in "$@" ; do
134 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
135 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
136 |
137 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
138 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
139 | else
140 | eval `echo args$i`="\"$arg\""
141 | fi
142 | i=$((i+1))
143 | done
144 | case $i in
145 | (0) set -- ;;
146 | (1) set -- "$args0" ;;
147 | (2) set -- "$args0" "$args1" ;;
148 | (3) set -- "$args0" "$args1" "$args2" ;;
149 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
150 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
151 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
152 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
153 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
154 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
155 | esac
156 | fi
157 |
158 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
159 | function splitJvmOpts() {
160 | JVM_OPTS=("$@")
161 | }
162 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
163 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
164 |
165 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
166 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/library/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 |
4 | android {
5 | compileSdk sdk_version
6 | namespace "com.kennyc.bottomsheet"
7 |
8 | defaultConfig {
9 | minSdkVersion 21
10 | targetSdkVersion sdk_version
11 | }
12 |
13 | lintOptions {
14 | abortOnError false
15 | }
16 |
17 | compileOptions {
18 | sourceCompatibility JavaVersion.VERSION_17
19 | targetCompatibility JavaVersion.VERSION_17
20 | }
21 |
22 | kotlinOptions {
23 | jvmTarget = "17"
24 | }
25 |
26 | packagingOptions {
27 | exclude 'META-INF/library_release.kotlin_module'
28 | }
29 | }
30 |
31 | dependencies {
32 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
33 | implementation 'androidx.annotation:annotation:1.8.0'
34 | implementation 'com.google.android.material:material:1.12.0'
35 | }
36 |
--------------------------------------------------------------------------------
/library/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/library/src/main/java/com/kennyc/bottomsheet/BottomSheetListener.kt:
--------------------------------------------------------------------------------
1 | package com.kennyc.bottomsheet
2 |
3 | import android.view.MenuItem
4 | import androidx.annotation.IntDef
5 |
6 | interface BottomSheetListener {
7 |
8 | @IntDef(DISMISS_EVENT_MANUAL, DISMISS_EVENT_SWIPE)
9 | annotation class DismissEvent
10 |
11 | /**
12 | * Called when the [BottomSheetMenuDialogFragment] is first displayed
13 | *
14 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that was shown
15 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
16 | */
17 | fun onSheetShown(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?)
18 |
19 | /**
20 | * Called when an item is selected from the list/grid of the [BottomSheetMenuDialogFragment]
21 | *
22 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that had an item selected
23 | * @param item The item that was selected
24 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
25 | */
26 | fun onSheetItemSelected(bottomSheet: BottomSheetMenuDialogFragment, item: MenuItem, `object`: Any?)
27 |
28 | /**
29 | * Called when the [BottomSheetMenuDialogFragment] has been dismissed
30 | *
31 | * @param bottomSheet The [BottomSheetMenuDialogFragment] that was dismissed
32 | * @param object Optional [Object] to pass to the [BottomSheetMenuDialogFragment]
33 | * @param dismissEvent How the [BottomSheetMenuDialogFragment] was dismissed. Possible values are:
34 | * * [.DISMISS_EVENT_SWIPE]
35 | * * [.DISMISS_EVENT_MANUAL]
36 | * * [.DISMISS_EVENT_ITEM_SELECTED]
37 | */
38 | fun onSheetDismissed(bottomSheet: BottomSheetMenuDialogFragment, `object`: Any?, @DismissEvent dismissEvent: Int)
39 |
40 | companion object {
41 | const val DISMISS_EVENT_SWIPE = -4
42 |
43 | const val DISMISS_EVENT_MANUAL = -5
44 |
45 | const val DISMISS_EVENT_ITEM_SELECTED = -6
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/library/src/main/java/com/kennyc/bottomsheet/BottomSheetMenuDialogFragment.kt:
--------------------------------------------------------------------------------
1 | package com.kennyc.bottomsheet
2 |
3 | import android.app.Dialog
4 | import android.content.Context
5 | import android.content.DialogInterface
6 | import android.os.Bundle
7 | import android.text.TextUtils
8 | import android.util.Log
9 | import android.view.*
10 | import android.widget.*
11 | import androidx.annotation.IntegerRes
12 | import androidx.annotation.MenuRes
13 | import androidx.annotation.StringRes
14 | import androidx.annotation.StyleRes
15 | import androidx.coordinatorlayout.widget.CoordinatorLayout
16 | import androidx.fragment.app.FragmentManager
17 | import androidx.lifecycle.ViewModelProvider
18 | import com.google.android.material.bottomsheet.BottomSheetBehavior
19 | import com.google.android.material.bottomsheet.BottomSheetDialog
20 | import com.google.android.material.bottomsheet.BottomSheetDialogFragment
21 | import com.kennyc.bottomsheet.adapters.GridAdapter
22 | import com.kennyc.bottomsheet.menu.BottomSheetMenu
23 | import com.kennyc.bottomsheet.menu.BottomSheetMenuItem
24 | import com.kennyc.bottomsheet.menu.BottomSheetViewModel
25 | import java.util.*
26 |
27 | private const val TAG = "BottomSheetMenu"
28 |
29 | class BottomSheetMenuDialogFragment() : BottomSheetDialogFragment(),
30 | AdapterView.OnItemClickListener {
31 |
32 | private constructor(builder: Builder) : this() {
33 | setTempBuilder(builder)
34 | }
35 |
36 | private var tempBuilder: Builder? = null
37 |
38 | private lateinit var container: LinearLayout
39 |
40 | private lateinit var closeContainer: LinearLayout
41 |
42 | private lateinit var adapter: GridAdapter
43 |
44 | private var dismissEvent = BottomSheetListener.DISMISS_EVENT_MANUAL
45 |
46 | private lateinit var viewModel: BottomSheetViewModel
47 |
48 | override fun onCreate(savedInstanceState: Bundle?) {
49 | super.onCreate(savedInstanceState)
50 | viewModel = ViewModelProvider(this)[BottomSheetViewModel::class.java].apply {
51 | if (builder == null) {
52 | builder = tempBuilder
53 | }
54 | }
55 |
56 | tempBuilder = null
57 | }
58 |
59 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
60 | return BottomSheetDialog(requireActivity(), viewModel.style).apply {
61 | setOnShowListener(DialogInterface.OnShowListener {
62 |
63 | if (container.parent == null) return@OnShowListener
64 | val params =
65 | (container.parent as View).layoutParams as CoordinatorLayout.LayoutParams
66 | val behavior = params.behavior
67 |
68 | // Should always be the case
69 | if (behavior is BottomSheetBehavior<*>) {
70 | if (viewModel.autoExpand) behavior.state = BottomSheetBehavior.STATE_EXPANDED
71 |
72 | behavior.addBottomSheetCallback(object :
73 | BottomSheetBehavior.BottomSheetCallback() {
74 | override fun onStateChanged(bottomSheet: View, state: Int) {
75 | if (state == BottomSheetBehavior.STATE_HIDDEN) {
76 | dismissEvent = BottomSheetListener.DISMISS_EVENT_SWIPE
77 | dismiss()
78 | }
79 | }
80 |
81 | override fun onSlide(bottomSheet: View, slideOffSet: Float) {
82 | closeContainer.alpha = if (slideOffSet > 0) slideOffSet else 0.0f
83 |
84 | }
85 | })
86 | }
87 | })
88 | }
89 | }
90 |
91 | override fun onCreateView(
92 | inflater: LayoutInflater,
93 | container: ViewGroup?,
94 | savedInstanceState: Bundle?
95 | ): View? {
96 | return inflater.inflate(R.layout.bottom_sheet_menu, container, false)
97 | }
98 |
99 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
100 | super.onViewCreated(view, savedInstanceState)
101 | if (viewModel.builder == null) {
102 | Log.e(TAG, "Builder object is null, dismissing dialog.")
103 | dismiss()
104 | return
105 | }
106 |
107 | container = view.findViewById(R.id.bottom_sheet_container)
108 | val title = container.findViewById(R.id.bottom_sheet_title)
109 | val gridView = container.findViewById(R.id.bottom_sheet_grid)
110 | closeContainer = container.findViewById(R.id.bottom_sheet_close_container)
111 | val closeTitle = closeContainer.findViewById(R.id.bottom_sheet_close_title)
112 | initUi(title, closeTitle, gridView)
113 |
114 | require(viewModel.menuItems.isNotEmpty()) { "No items were passed to the builder" }
115 |
116 | adapter = GridAdapter(
117 | ContextThemeWrapper(requireActivity(), viewModel.style),
118 | viewModel.menuItems,
119 | viewModel.isGrid
120 | )
121 |
122 | gridView.onItemClickListener = this
123 | gridView.adapter = adapter
124 | viewModel.listener?.onSheetShown(this, viewModel.`object`)
125 | this.isCancelable = viewModel.cancelable
126 |
127 | closeContainer.findViewById(R.id.bottom_sheet_close).setOnClickListener {
128 | dismissEvent = BottomSheetListener.DISMISS_EVENT_MANUAL
129 | dismiss()
130 | }
131 | }
132 |
133 | private fun initUi(title: TextView, closeTitle: TextView, gridView: GridView) {
134 | val hasTitle = !TextUtils.isEmpty(viewModel.title)
135 |
136 | if (hasTitle) {
137 | title.text = viewModel.title
138 | } else {
139 | title.visibility = View.GONE
140 | }
141 |
142 | if (!viewModel.isGrid) {
143 | val padding = resources.getDimensionPixelSize(R.dimen.bottom_sheet_menu_list_padding)
144 | gridView.setPadding(0, if (hasTitle) 0 else padding, 0, padding)
145 | }
146 |
147 | if (!TextUtils.isEmpty(viewModel.closeTitle)) {
148 | closeTitle.text = viewModel.closeTitle
149 | } else {
150 | closeTitle.visibility = View.GONE
151 | }
152 |
153 | gridView.numColumns = getNumberColumns()
154 | }
155 |
156 | private fun getNumberColumns(): Int {
157 | if (viewModel.columnCount > 0) return viewModel.columnCount
158 | val isTablet = resources.getBoolean(R.bool.bottom_sheet_menu_it_tablet)
159 |
160 | val numItems = viewModel.menuItems.size
161 |
162 | if (viewModel.isGrid) {
163 | // Show 4 columns if a tablet and the number of its is 4 or >=7
164 | return if ((numItems >= 7 || numItems == GRID_MAX_COLUMN) && isTablet) {
165 | GRID_MAX_COLUMN
166 | } else {
167 | GRID_MIN_COLUMNS
168 | }
169 | }
170 |
171 | return when (isTablet) {
172 | // If a tablet with more than 6 items are present, split them into 2 columns
173 | true -> if (numItems >= MIN_LIST_TABLET_ITEMS) 2 else 1
174 | // Regular phone, one column
175 | else -> 1
176 | }
177 | }
178 |
179 | private fun setTempBuilder(builder: Builder) {
180 | this.tempBuilder = builder
181 | }
182 |
183 | override fun onDismiss(dialog: DialogInterface) {
184 | viewModel.listener?.onSheetDismissed(this, viewModel.`object`, dismissEvent)
185 | super.onDismiss(dialog)
186 | }
187 |
188 | override fun onItemClick(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
189 | dismissEvent = BottomSheetListener.DISMISS_EVENT_ITEM_SELECTED
190 |
191 | viewModel.listener?.let {
192 | val item = adapter.getItem(position)
193 | it.onSheetItemSelected(this, item, viewModel.`object`)
194 | dismiss()
195 | }
196 | }
197 |
198 | /**
199 | * Builder factory used for creating [BottomSheetMenuDialogFragment]
200 | */
201 | class Builder @JvmOverloads constructor(
202 | private val context: Context,
203 | @StyleRes style: Int = R.style.Theme_BottomSheetMenuDialog_Light,
204 | columnCount: Int = -1,
205 | @MenuRes sheet: Int = -1,
206 | cancelable: Boolean = true,
207 | isGrid: Boolean = false,
208 | autoExpand: Boolean = false,
209 | menuItems: MutableList