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 */ 17 18 package com.android.systemui.keyguard.ui.binder 19 20 import android.content.Context 21 import android.view.View 22 import androidx.core.view.isInvisible 23 import androidx.lifecycle.Lifecycle 24 import androidx.lifecycle.repeatOnLifecycle 25 import com.android.app.tracing.coroutines.launch 26 import com.android.systemui.keyguard.shared.model.ClockSizeSetting 27 import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel 28 import com.android.systemui.lifecycle.repeatWhenAttached 29 30 /** Binder for the small clock view, large clock view and smartspace. */ 31 object KeyguardPreviewSmartspaceViewBinder { 32 33 @JvmStatic bindnull34 fun bind( 35 previewContext: Context, 36 smartspace: View, 37 splitShadePreview: Boolean, 38 viewModel: KeyguardPreviewSmartspaceViewModel, 39 ) { 40 smartspace.repeatWhenAttached { 41 repeatOnLifecycle(Lifecycle.State.STARTED) { 42 launch("$TAG#viewModel.selectedClockSize") { 43 viewModel.selectedClockSize.collect { 44 val topPadding = 45 when (it) { 46 ClockSizeSetting.DYNAMIC -> 47 viewModel.getLargeClockSmartspaceTopPadding( 48 splitShadePreview, 49 previewContext, 50 ) 51 ClockSizeSetting.SMALL -> 52 viewModel.getSmallClockSmartspaceTopPadding( 53 splitShadePreview, 54 previewContext, 55 ) 56 } 57 smartspace.setTopPadding(topPadding) 58 } 59 } 60 launch("$TAG#viewModel.shouldHideSmartspace") { 61 viewModel.shouldHideSmartspace.collect { smartspace.isInvisible = it } 62 } 63 } 64 } 65 } 66 setTopPaddingnull67 private fun View.setTopPadding(padding: Int) { 68 setPaddingRelative(paddingStart, padding, paddingEnd, paddingBottom) 69 } 70 71 private const val TAG = "KeyguardPreviewSmartspaceViewBinder" 72 } 73