Merge "Introduce small clock on the settings screen" into udc-dev am: 4a3d7406f7

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23375956

Change-Id: Ie5707289b0de35a193692e101829739d60c4d917
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
George Lin
2023-05-26 00:45:30 +00:00
committed by Automerger Merge Worker
5 changed files with 105 additions and 33 deletions

View File

@@ -21,19 +21,17 @@ import android.view.View
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockSmartspaceViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel
import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.lifecycle.repeatWhenAttached
import kotlinx.coroutines.flow.collect
/** Binder for the small clock view, large clock view and smartspace. */ /** Binder for the small clock view, large clock view. */
object KeyguardPreviewClockSmartspaceViewBinder { object KeyguardPreviewClockViewBinder {
@JvmStatic @JvmStatic
fun bind( fun bind(
largeClockHostView: View, largeClockHostView: View,
smallClockHostView: View, smallClockHostView: View,
smartspace: View?, viewModel: KeyguardPreviewClockViewModel,
viewModel: KeyguardPreviewClockSmartspaceViewModel,
) { ) {
largeClockHostView.repeatWhenAttached { largeClockHostView.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -46,15 +44,5 @@ object KeyguardPreviewClockSmartspaceViewBinder {
viewModel.isSmallClockVisible.collect { smallClockHostView.isVisible = it } viewModel.isSmallClockVisible.collect { smallClockHostView.isVisible = it }
} }
} }
smartspace?.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.smartSpaceTopPadding.collect { smartspace.setTopPadding(it) }
}
}
}
private fun View.setTopPadding(padding: Int) {
setPaddingRelative(paddingStart, padding, paddingEnd, paddingBottom)
} }
} }

View File

@@ -0,0 +1,45 @@
/*
* 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.systemui.keyguard.ui.binder
import android.view.View
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
/** Binder for the small clock view, large clock view and smartspace. */
object KeyguardPreviewSmartspaceViewBinder {
@JvmStatic
fun bind(
smartspace: View,
viewModel: KeyguardPreviewSmartspaceViewModel,
) {
smartspace.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
viewModel.smartSpaceTopPadding.collect { smartspace.setTopPadding(it) }
}
}
}
private fun View.setTopPadding(padding: Int) {
setPaddingRelative(paddingStart, padding, paddingEnd, paddingBottom)
}
}

View File

@@ -42,9 +42,11 @@ import com.android.systemui.biometrics.domain.interactor.UdfpsOverlayInteractor
import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.broadcast.BroadcastDispatcher
import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.ui.binder.KeyguardPreviewClockSmartspaceViewBinder import com.android.systemui.keyguard.ui.binder.KeyguardPreviewClockViewBinder
import com.android.systemui.keyguard.ui.binder.KeyguardPreviewSmartspaceViewBinder
import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockSmartspaceViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewClockViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.plugins.ClockController import com.android.systemui.plugins.ClockController
import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.DefaultClockController import com.android.systemui.shared.clocks.DefaultClockController
@@ -65,7 +67,8 @@ constructor(
@Application private val context: Context, @Application private val context: Context,
@Main private val mainDispatcher: CoroutineDispatcher, @Main private val mainDispatcher: CoroutineDispatcher,
@Main private val mainHandler: Handler, @Main private val mainHandler: Handler,
private val clockSmartspaceViewModel: KeyguardPreviewClockSmartspaceViewModel, private val clockViewModel: KeyguardPreviewClockViewModel,
private val smartspaceViewModel: KeyguardPreviewSmartspaceViewModel,
private val bottomAreaViewModel: KeyguardBottomAreaViewModel, private val bottomAreaViewModel: KeyguardBottomAreaViewModel,
displayManager: DisplayManager, displayManager: DisplayManager,
private val windowManager: WindowManager, private val windowManager: WindowManager,
@@ -129,16 +132,18 @@ constructor(
setUpBottomArea(rootView) setUpBottomArea(rootView)
setUpSmartspace(rootView) setUpSmartspace(rootView)
smartSpaceView?.let {
KeyguardPreviewSmartspaceViewBinder.bind(it, smartspaceViewModel)
}
setUpUdfps(rootView) setUpUdfps(rootView)
if (!shouldHideClock) { if (!shouldHideClock) {
setUpClock(rootView) setUpClock(rootView)
KeyguardPreviewClockSmartspaceViewBinder.bind( KeyguardPreviewClockViewBinder.bind(
largeClockHostView, largeClockHostView,
smallClockHostView, smallClockHostView,
smartSpaceView, clockViewModel,
clockSmartspaceViewModel,
) )
} }
@@ -219,8 +224,8 @@ constructor(
smartSpaceView = lockscreenSmartspaceController.buildAndConnectDateView(parentView) smartSpaceView = lockscreenSmartspaceController.buildAndConnectDateView(parentView)
val topPadding: Int = val topPadding: Int =
KeyguardPreviewClockSmartspaceViewModel.getLargeClockSmartspaceTopPadding( KeyguardPreviewSmartspaceViewModel.getLargeClockSmartspaceTopPadding(
context.resources context.resources,
) )
val startPadding: Int = val startPadding: Int =
@@ -372,7 +377,7 @@ constructor(
resources.getDimensionPixelSize(R.dimen.small_clock_height) resources.getDimensionPixelSize(R.dimen.small_clock_height)
) )
layoutParams.topMargin = layoutParams.topMargin =
KeyguardPreviewClockSmartspaceViewModel.getStatusBarHeight(resources) + KeyguardPreviewSmartspaceViewModel.getStatusBarHeight(resources) +
resources.getDimensionPixelSize(R.dimen.small_clock_padding_top) resources.getDimensionPixelSize(R.dimen.small_clock_padding_top)
hostView.layoutParams = layoutParams hostView.layoutParams = layoutParams

View File

@@ -0,0 +1,40 @@
/*
* 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.systemui.keyguard.ui.viewmodel
import android.content.Context
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
/** View model for the small clock view, large clock view. */
class KeyguardPreviewClockViewModel
@Inject
constructor(
@Application private val context: Context,
interactor: KeyguardClockInteractor,
) {
val isLargeClockVisible: Flow<Boolean> =
interactor.selectedClockSize.map { it == SettingsClockSize.DYNAMIC }
val isSmallClockVisible: Flow<Boolean> =
interactor.selectedClockSize.map { it == SettingsClockSize.SMALL }
}

View File

@@ -26,20 +26,14 @@ import javax.inject.Inject
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.map
/** View model for the small clock view, large clock view and smartspace. */ /** View model for the smartspace. */
class KeyguardPreviewClockSmartspaceViewModel class KeyguardPreviewSmartspaceViewModel
@Inject @Inject
constructor( constructor(
@Application private val context: Context, @Application private val context: Context,
interactor: KeyguardClockInteractor, interactor: KeyguardClockInteractor,
) { ) {
val isLargeClockVisible: Flow<Boolean> =
interactor.selectedClockSize.map { it == SettingsClockSize.DYNAMIC }
val isSmallClockVisible: Flow<Boolean> =
interactor.selectedClockSize.map { it == SettingsClockSize.SMALL }
val smartSpaceTopPadding: Flow<Int> = val smartSpaceTopPadding: Flow<Int> =
interactor.selectedClockSize.map { interactor.selectedClockSize.map {
when (it) { when (it) {