Created
July 28, 2021 14:37
-
-
Save Draketheb4dass/cf02825db3ecc9b2ae58c2e16c68543b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jephtecolin.kwii.util | |
import androidx.databinding.BindingAdapter | |
import androidx.databinding.InverseBindingAdapter | |
import androidx.databinding.InverseBindingListener | |
import com.jephtecolin.kwii.ui.custom.CheckBoxGroup | |
import com.jephtecolin.kwii.ui.custom.OnCheckedChangeListener | |
import com.jephtecolin.model.Topping | |
import timber.log.Timber | |
@BindingAdapter("setItems") | |
fun setItems(checkboxGroup: CheckBoxGroup, toppings: Array<Topping>) { | |
checkboxGroup.setItems(toppings) | |
} | |
@BindingAdapter(value = ["setOnCheckedChangeListener", "totalPriceAttrChanged"] , requireAll = false) | |
fun setOnCheckedChangeListener(checkboxGroup: CheckBoxGroup, listener: OnCheckedChangeListener, | |
totalPriceAttrChanged: InverseBindingListener) { | |
totalPriceAttrChanged.onChange() | |
checkboxGroup.setOnCheckedChangeListener(object : OnCheckedChangeListener { | |
override fun onCheckedChange(totalPrice: Double) { | |
Timber.d("binding adapter works") | |
if (totalPriceAttrChanged != null) { | |
totalPriceAttrChanged.onChange() | |
} | |
} | |
}) | |
} | |
@BindingAdapter( "totalPrice") | |
fun setTotalPrice(checkboxGroup: CheckBoxGroup, totalPrice: Double) { | |
if(checkboxGroup.totalPrice != totalPrice) { | |
checkboxGroup.totalPrice = totalPrice | |
} | |
} | |
@InverseBindingAdapter(attribute = "totalPrice") | |
fun getTotalPrice(checkboxGroup: CheckBoxGroup): Double { | |
return checkboxGroup.totalPrice | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment