Skip to content

Instantly share code, notes, and snippets.

@gastsail
Created March 23, 2020 15:51
Show Gist options
  • Save gastsail/2ea07b63fb7a64a492b93fec1cfeff5e to your computer and use it in GitHub Desktop.
Save gastsail/2ea07b63fb7a64a492b93fec1cfeff5e to your computer and use it in GitHub Desktop.
private val cartHashMap = MutableLiveData<HashMap<String,Cart>>()
private var sharedHashMap = HashMap<String,Cart>()
fun setProductSelectedHashMap(productId:String,productSelected:Cart){
sharedHashMap[productId] = productSelected
cartHashMap.value = sharedHashMap
}
fun removeSelectedProduct(productId:String){
sharedHashMap.remove(productId)
cartHashMap.value = sharedHashMap
}
fun updateProductQuantity(productId:String, quantity:Int){
val productoCartSelected = sharedHashMap[productId]
productoCartSelected?.cantidad = quantity
sharedHashMap[productId] = productoCartSelected!!
cartHashMap.value = sharedHashMap
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment