@@ -43,11 +43,32 @@ class ToggleButtonLayout : CardView {
4343
4444 private lateinit var linearLayout: LinearLayout
4545
46- private val toggles = mutableListOf<Toggle >()
46+ /* *
47+ * The current list of toggles. Do not modify directly, instead call [addToggle] and [inflateMenu] methods
48+ */
49+ val toggles = mutableListOf<Toggle >()
50+
51+
52+ /* *
53+ * Set if we are going to allow multiple selection or not. This will also call [.reset]
54+ * in order to prevent strange behaviour switching between multiple and single selection
55+ *
56+ */
57+ var multipleSelection: Boolean = false
58+ set(value) {
59+ field = value
60+ reset()
61+ }
4762
48- // customization
49- private var multipleSelection: Boolean = false
50- private var allowDeselection = true
63+ /* *
64+ * Allow selected items to be de-selected. Defaults to true.
65+ *
66+ */
67+ var allowDeselection = true
68+
69+ /* *
70+ * Set the color of the divider between toggles. Set to null to not include dividers
71+ */
5172 @ColorInt
5273 var dividerColor: Int? = null
5374 set(value) {
@@ -64,12 +85,17 @@ class ToggleButtonLayout : CardView {
6485 }
6586 }
6687 }
88+
89+ /* *
90+ * Set the color to show when the toggle is selected
91+ */
6792 @ColorInt
6893 var selectedColor: Int = 0
6994 set(value) {
7095 field = value
7196 adjustColorOfSelected()
7297 }
98+
7399 @LayoutRes
74100 private var layoutRes: Int? = null
75101 private var mode: Int = 0
@@ -157,7 +183,7 @@ class ToggleButtonLayout : CardView {
157183 *
158184 * @return the selected toggles
159185 */
160- fun getSelectedToggles (): List <Toggle > {
186+ fun selectedToggles (): List <Toggle > {
161187 return toggles.filter { it.isSelected }
162188 }
163189
@@ -186,26 +212,6 @@ class ToggleButtonLayout : CardView {
186212 linearLayout.addView(toggleView)
187213 }
188214
189- /* *
190- * Set if we are going to allow multiple selection or not. This will also call [.reset]
191- * in order to prevent strange behaviour switching between multiple and single selection
192- *
193- * @param multipleSelection true if allowing multiple selection, false otherwise
194- */
195- fun setMultipleSelection (multipleSelection : Boolean ) {
196- this .multipleSelection = multipleSelection
197- reset()
198- }
199-
200- /* *
201- * Allow selected items to be de-selected. Defaults to true.
202- *
203- * @param allowDeselection allow de-selection
204- */
205- fun setAllowDeselection (allowDeselection : Boolean ) {
206- this .allowDeselection = allowDeselection
207- }
208-
209215 /* *
210216 * Reset all toggles to unselected
211217 */
@@ -254,7 +260,7 @@ class ToggleButtonLayout : CardView {
254260 }
255261
256262 private fun adjustColorOfSelected () {
257- val selectedToggles = getSelectedToggles ()
263+ val selectedToggles = selectedToggles ()
258264 selectedToggles.forEach {
259265 val view = linearLayout.findViewById<View >(it.id)
260266 view.background = ColorDrawable (selectedColor)
@@ -276,8 +282,8 @@ class ToggleButtonLayout : CardView {
276282 */
277283 @SuppressLint(" ViewConstructor" )
278284 internal class ToggleView (context : Context , toggle : Toggle , @LayoutRes layoutRes : Int? ) : FrameLayout(context) {
279- var textView: TextView ? = null
280- var imageView: ImageView ? = null
285+ private val textView: TextView ?
286+ private val imageView: ImageView ?
281287
282288 init {
283289 id = toggle.id
0 commit comments