/* * Copyright (C) 2023 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.wallpaper.picker.preview.ui.binder import android.view.View import android.widget.Button import android.widget.CheckBox import android.widget.TextView import androidx.core.content.ContextCompat import androidx.core.graphics.ColorUtils import androidx.core.view.isVisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.android.wallpaper.R import com.android.wallpaper.model.Screen import com.android.wallpaper.model.wallpaper.DeviceDisplayType.Companion.FOLDABLE_DISPLAY_TYPES import com.android.wallpaper.picker.customization.ui.util.ViewAlphaAnimator.animateToAlpha import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2.Companion.PREVIEW_FADE_ALPHA import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2.Companion.PREVIEW_SHOW_ALPHA import com.android.wallpaper.picker.data.WallpaperModel import com.android.wallpaper.picker.di.modules.MainDispatcher import com.android.wallpaper.picker.preview.ui.view.ClickableMotionLayout import com.android.wallpaper.picker.preview.ui.view.DualDisplayAspectRatioLayout.Companion.getViewId import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel.Companion.PreviewScreen import com.android.wallpaper.util.wallpaperconnection.WallpaperConnectionUtils import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.launch /** Binds the set wallpaper button on small preview. */ object ApplyWallpaperScreenBinder { fun bind( previewPager: ClickableMotionLayout, viewModel: WallpaperPreviewViewModel, lifecycleOwner: LifecycleOwner, @MainDispatcher mainScope: CoroutineScope, isFoldable: Boolean, wallpaperConnectionUtils: WallpaperConnectionUtils, onWallpaperSet: () -> Unit, ) { val applyButton = previewPager.requireViewById