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

<lambda>null1 package com.airbnb.lottie.samples
2 
3 import android.content.Intent
4 import androidx.fragment.app.FragmentActivity
5 import com.airbnb.epoxy.EpoxyController
6 import com.airbnb.lottie.samples.model.AnimationResponse
7 import com.airbnb.lottie.samples.model.CompositionArgs
8 import com.airbnb.lottie.samples.model.ShowcaseItem
9 import com.airbnb.lottie.samples.views.loadingView
10 import com.airbnb.lottie.samples.views.marquee
11 import com.airbnb.lottie.samples.views.showcaseAnimationItemView
12 import com.airbnb.lottie.samples.views.showcaseCarousel
13 import com.airbnb.mvrx.*
14 
15 data class ShowcaseState(val response: Async<AnimationResponse> = Uninitialized) : MvRxState
16 
17 class ShowcaseViewModel(initialState: ShowcaseState, service: LottiefilesService) : MvRxViewModel<ShowcaseState>(initialState) {
18     init {
19         service.getCollection("lottie-showcase")
20                 .retry(3)
21                 .execute { copy(response = it) }
22     }
23 
24     companion object : MvRxViewModelFactory<ShowcaseState> {
25         @JvmStatic
26         override fun create(activity: FragmentActivity, state: ShowcaseState): ShowcaseViewModel {
27             val service = (activity.applicationContext as LottieApplication).lottiefilesService
28             return ShowcaseViewModel(state, service)
29         }
30     }
31 }
32 
33 class ShowcaseFragment : BaseEpoxyFragment() {
34 
35     private val showcaseItems = listOf(
<lambda>null36             ShowcaseItem(R.drawable.showcase_preview_lottie, R.string.showcase_item_app_intro) {
37                 startActivity(Intent(requireContext(), AppIntroActivity::class.java))
38             },
<lambda>null39             ShowcaseItem(R.drawable.showcase_preview_lottie, R.string.showcase_item_dynamic_properties) {
40                 startActivity(Intent(requireContext(), DynamicActivity::class.java))
41             },
<lambda>null42             ShowcaseItem(R.drawable.gilbert_animated, R.string.showcase_item_animated_text) {
43                 startActivity(Intent(requireContext(), TypographyDemoActivity::class.java))
44             },
<lambda>null45             ShowcaseItem(R.drawable.gilbert_animated, R.string.showcase_item_dynamic_text) {
46                 startActivity(Intent(requireContext(), DynamicTextActivity::class.java))
47             },
<lambda>null48             ShowcaseItem(R.drawable.showcase_preview_lottie, R.string.showcase_item_bullseye) {
49                 startActivity(Intent(requireContext(), BullseyeActivity::class.java))
50             },
<lambda>null51             ShowcaseItem(R.drawable.showcase_preview_lottie, R.string.showcase_item_recycler_viwe) {
52                 startActivity(Intent(requireContext(), ListActivity::class.java))
53             }
54     )
55     private val viewModel: ShowcaseViewModel by fragmentViewModel()
56 
buildModelsnull57     override fun EpoxyController.buildModels() = withState(viewModel) { state ->
58         marquee {
59             id("showcase")
60             title("Showcase")
61         }
62         showcaseCarousel {
63             id("carousel")
64             showcaseItems(showcaseItems)
65         }
66 
67         val collectionItems = state.response()?.data
68 
69         if (collectionItems == null) {
70             loadingView {
71                 id("loading")
72             }
73         } else {
74             collectionItems.forEach {
75                 showcaseAnimationItemView {
76                     id(it.id)
77                     title(it.title)
78                     previewUrl(it.preview)
79                     onClickListener { _ -> startActivity(PlayerActivity.intent(requireContext(), CompositionArgs(animationData = it))) }
80                 }
81             }
82         }
83     }
84 }