1 /* <lambda>null2 * Copyright (C) 2024 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 17 package com.android.wallpaper.picker.customization.ui.binder 18 19 import android.app.Activity 20 import android.app.AlertDialog 21 import android.content.Context 22 import android.view.View 23 import androidx.lifecycle.Lifecycle 24 import androidx.lifecycle.LifecycleOwner 25 import androidx.lifecycle.lifecycleScope 26 import androidx.lifecycle.repeatOnLifecycle 27 import com.android.customization.picker.clock.ui.view.ClockViewFactory 28 import com.android.wallpaper.R 29 import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil.CustomizationOption 30 import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel 31 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel 32 import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationPickerViewModel2 33 import javax.inject.Inject 34 import javax.inject.Singleton 35 import kotlinx.coroutines.launch 36 37 @Singleton 38 class DefaultCustomizationOptionsBinder @Inject constructor() : CustomizationOptionsBinder { 39 40 override fun bind( 41 view: View, 42 lockScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 43 homeScreenCustomizationOptionEntries: List<Pair<CustomizationOption, View>>, 44 customizationOptionFloatingSheetViewMap: Map<CustomizationOption, View>?, 45 viewModel: CustomizationPickerViewModel2, 46 colorUpdateViewModel: ColorUpdateViewModel, 47 lifecycleOwner: LifecycleOwner, 48 navigateToMoreLockScreenSettingsActivity: () -> Unit, 49 navigateToColorContrastSettingsActivity: () -> Unit, 50 navigateToLockScreenNotificationsSettingsActivity: () -> Unit, 51 navigateToPackThemeActivity: () -> Unit, 52 ) { 53 // Do nothing intended 54 } 55 56 override fun bindClockPreview( 57 context: Context, 58 clockHostView: View, 59 clockFaceClickDelegateView: View, 60 viewModel: CustomizationPickerViewModel2, 61 colorUpdateViewModel: ColorUpdateViewModel, 62 lifecycleOwner: LifecycleOwner, 63 clockViewFactory: ClockViewFactory, 64 ) { 65 // Do nothing intended 66 } 67 68 override fun bindDiscardChangesDialog( 69 customizationOptionsViewModel: CustomizationOptionsViewModel, 70 lifecycleOwner: LifecycleOwner, 71 activity: Activity, 72 ) { 73 var discardChangesDialog: AlertDialog? = null 74 75 lifecycleOwner.lifecycleScope.launch { 76 lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) { 77 customizationOptionsViewModel.discardChangesDialogViewModel.collect { viewModel -> 78 if (viewModel != null) { 79 val (onDismiss, onKeepEditing, onDiscard) = viewModel 80 val dialog = 81 discardChangesDialog 82 ?: AlertDialog.Builder(activity) 83 .setMessage(R.string.discard_changes_dialog_message) 84 .setOnDismissListener { onDismiss.invoke() } 85 .setPositiveButton( 86 R.string.discard_changes_dialog_button_keep_editing 87 ) { _, _ -> 88 onKeepEditing.invoke() 89 } 90 .setNegativeButton( 91 R.string.discard_changes_dialog_button_discard 92 ) { _, _ -> 93 onDiscard.invoke() 94 } 95 .create() 96 .also { discardChangesDialog = it } 97 dialog.show() 98 } else { 99 discardChangesDialog?.dismiss() 100 discardChangesDialog = null 101 } 102 } 103 } 104 } 105 } 106 } 107