1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.wallpaper.picker.preview.ui.binder
17 
18 import android.content.Context
19 import android.graphics.Point
20 import android.view.View
21 import androidx.lifecycle.LifecycleOwner
22 import androidx.transition.Transition
23 import androidx.viewpager2.widget.ViewPager2
24 import com.android.wallpaper.picker.preview.ui.view.PreviewTabs
25 import com.android.wallpaper.picker.preview.ui.viewmodel.FullPreviewConfigViewModel
26 import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel
27 import com.android.wallpaper.util.wallpaperconnection.WallpaperConnectionUtils
28 import kotlinx.coroutines.CompletableDeferred
29 import kotlinx.coroutines.CoroutineScope
30 
31 /** Binds and synchronizes the tab and preview view pagers. */
32 object PreviewSelectorBinder {
bindnull33     fun bind(
34         tabs: PreviewTabs?,
35         previewsViewPager: ViewPager2?,
36         previewDisplaySize: Point,
37         wallpaperPreviewViewModel: WallpaperPreviewViewModel,
38         applicationContext: Context,
39         mainScope: CoroutineScope,
40         viewLifecycleOwner: LifecycleOwner,
41         transition: Transition?,
42         transitionConfig: FullPreviewConfigViewModel?,
43         wallpaperConnectionUtils: WallpaperConnectionUtils,
44         isFirstBindingDeferred: CompletableDeferred<Boolean>,
45         navigate: (View) -> Unit,
46     ) {
47         PreviewPagerBinder.bind(
48             applicationContext,
49             mainScope,
50             viewLifecycleOwner,
51             checkNotNull(previewsViewPager),
52             wallpaperPreviewViewModel,
53             previewDisplaySize,
54             transition,
55             transitionConfig,
56             wallpaperConnectionUtils,
57             isFirstBindingDeferred,
58             navigate,
59         )
60         tabs?.let { TabsBinder.bind(it, wallpaperPreviewViewModel, viewLifecycleOwner) }
61     }
62 }
63