/* * 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.graphics.Point import android.view.View import android.widget.Button import android.widget.FrameLayout 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 import com.android.wallpaper.picker.preview.ui.view.DualDisplayAspectRatioLayout import com.android.wallpaper.picker.preview.ui.view.DualDisplayAspectRatioLayout.Companion.getViewId import com.android.wallpaper.picker.preview.ui.viewmodel.WallpaperPreviewViewModel import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch /** Binds the dialog on small preview confirming and setting wallpaper with destination. */ object SetWallpaperDialogBinder { private val PreviewScreenIds = mapOf( Screen.LOCK_SCREEN to R.id.lock_preview_selector, Screen.HOME_SCREEN to R.id.home_preview_selector ) fun bind( dialogContent: View, wallpaperPreviewViewModel: WallpaperPreviewViewModel, isFoldable: Boolean, handheldDisplaySize: Point, lifecycleOwner: LifecycleOwner, mainScope: CoroutineScope, currentNavDestId: Int, onFinishActivity: () -> Unit, onDismissDialog: () -> Unit, isFirstBinding: Boolean, navigate: ((View) -> Unit)?, ) { val previewLayout: View = if (isFoldable) dialogContent.requireViewById(R.id.foldable_previews) else dialogContent.requireViewById(R.id.handheld_previews) if (isFoldable) bindFoldablePreview( previewLayout, wallpaperPreviewViewModel, lifecycleOwner, currentNavDestId, isFirstBinding, navigate, ) else bindHandheldPreview( previewLayout, wallpaperPreviewViewModel, handheldDisplaySize, lifecycleOwner, currentNavDestId, isFirstBinding, navigate, ) val cancelButton = dialogContent.requireViewById