• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download

<lambda>null1 package com.airbnb.lottie.samples.views
2 
3 import android.content.Context
4 import android.util.AttributeSet
5 import android.widget.FrameLayout
6 import com.airbnb.epoxy.CallbackProp
7 import com.airbnb.epoxy.ModelProp
8 import com.airbnb.epoxy.ModelView
9 import com.airbnb.epoxy.OnViewRecycled
10 import com.airbnb.lottie.samples.databinding.ListingCardBinding
11 import com.airbnb.lottie.samples.utils.viewBinding
12 
13 @ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_WRAP_HEIGHT)
14 class ListingCard @JvmOverloads constructor(
15     context: Context,
16     attrs: AttributeSet? = null,
17     defStyleAttr: Int = 0
18 ) : FrameLayout(context, attrs, defStyleAttr) {
19     private val binding: ListingCardBinding by viewBinding()
20 
21     @CallbackProp
22     fun onToggled(listener: ((isWishListed: Boolean) -> Unit)?) {
23         binding.wishListIcon.setOnClickListener(when (listener) {
24             null -> null
25             else -> { _ ->
26                 listener(binding.wishListIcon.progress == 0f)
27             }
28         })
29     }
30 
31     @ModelProp
32     fun isWishListed(isWishListed: Boolean) {
33         val targetProgress = if (isWishListed) 1f else 0f
34         binding.wishListIcon.speed = if (isWishListed) 1f else -1f
35         if (binding.wishListIcon.progress != targetProgress) {
36             binding.wishListIcon.playAnimation()
37         }
38     }
39 
40     @OnViewRecycled
41     fun onRecycled() {
42         binding.wishListIcon.pauseAnimation()
43         binding.wishListIcon.progress = 0f
44     }
45 }