@@ -19,11 +19,11 @@ import android.widget.ImageView
1919import android.widget.LinearLayout
2020import android.widget.TextView
2121
22- @Suppress(" MemberVisibilityCanBePrivate" , " unused" )
2322/* *
2423 * ToggleButtonLayout is a layout used to group related options. Layout and spacing is arranged to
2524 * convey that certain toggle buttons are part of a group.
2625 */
26+ @Suppress(" MemberVisibilityCanBePrivate" , " unused" )
2727class ToggleButtonLayout : CardView {
2828
2929 companion object {
@@ -116,7 +116,7 @@ class ToggleButtonLayout : CardView {
116116 /* *
117117 * Listen for when toggles get selected and deselected
118118 */
119- var onToggledListener: ((v : View ? , toggle: Toggle , selected: Boolean ) -> Unit )? = null
119+ var onToggledListener: ((toggleButtonLayout : ToggleButtonLayout ? , toggle: Toggle , selected: Boolean ) -> Unit )? = null
120120
121121 constructor (context: Context ) : super (context) {
122122 init (context, null )
@@ -173,9 +173,7 @@ class ToggleButtonLayout : CardView {
173173 MenuInflater (context).inflate(menuId, menu)
174174 for (i in 0 until menu.size()) {
175175 val item = menu.getItem(i)
176- val toggle = Toggle (item.itemId, item.icon, item.title).apply {
177- this .parentRef = this @ToggleButtonLayout
178- }
176+ val toggle = Toggle (item.itemId, item.icon, item.title)
179177 addToggle(toggle)
180178 }
181179 }
@@ -212,6 +210,8 @@ class ToggleButtonLayout : CardView {
212210 toggleView.layoutParams = params
213211 }
214212 linearLayout.addView(toggleView)
213+ toggle.toggleView = toggleView
214+ toggle.toggleButtonLayout = this
215215 }
216216
217217 /* *
@@ -278,35 +278,4 @@ class ToggleButtonLayout : CardView {
278278 view.background = null
279279 }
280280 }
281-
282- /* *
283- * Default view for Toggle
284- */
285- @SuppressLint(" ViewConstructor" )
286- internal class ToggleView (context : Context , toggle : Toggle , @LayoutRes layoutRes : Int? ) : FrameLayout(context) {
287- private val textView: TextView ?
288- private val imageView: ImageView ?
289-
290- init {
291- id = toggle.id
292- if (layoutRes != null ) {
293- View .inflate(context, layoutRes, this )
294- textView = findViewById(android.R .id.text1)
295- imageView = findViewById(android.R .id.icon)
296- } else {
297- textView = TextView (context)
298- imageView = ImageView (context)
299- addView(imageView)
300- addView(textView)
301- val eightDp = Utils .dpToPx(getContext(), 8 )
302- setPadding(eightDp, eightDp, eightDp, eightDp)
303- }
304- setTag(R .id.tb_toggle_id, toggle)
305- textView?.text = toggle.title
306- if (toggle.icon != null ) {
307- imageView?.setImageDrawable(toggle.icon)
308- }
309- foreground = Utils .getThemeAttrDrawable(getContext(), R .attr.selectableItemBackground)
310- }
311- }
312281}
0 commit comments