Merge "Introduce small clock on the settings screen" into udc-dev

This commit is contained in:
George Lin
2023-05-26 00:42:21 +00:00
committed by Android (Google) Code Review
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.lifecycle.Lifecycle
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 kotlinx.coroutines.flow.collect
/** Binder for the small clock view, large clock view and smartspace. */
object KeyguardPreviewClockSmartspaceViewBinder {
/** Binder for the small clock view, large clock view. */
object KeyguardPreviewClockViewBinder {
@JvmStatic
fun bind(
largeClockHostView: View,
smallClockHostView: View,
smartspace: View?,
viewModel: KeyguardPreviewClockSmartspaceViewModel,
viewModel: KeyguardPreviewClockViewModel,
) {
largeClockHostView.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) {
@@ -46,15 +44,5 @@ object KeyguardPreviewClockSmartspaceViewBinder {
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.dagger.qualifiers.Application
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.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.shared.clocks.ClockRegistry
import com.android.systemui.shared.clocks.DefaultClockController
@@ -65,7 +67,8 @@ constructor(
@Application private val context: Context,
@Main private val mainDispatcher: CoroutineDispatcher,
@Main private val mainHandler: Handler,
private val clockSmartspaceViewModel: KeyguardPreviewClockSmartspaceViewModel,
private val clockViewModel: KeyguardPreviewClockViewModel,
private val smartspaceViewModel: KeyguardPreviewSmartspaceViewModel,
private val bottomAreaViewModel: KeyguardBottomAreaViewModel,
displayManager: DisplayManager,
private val windowManager: WindowManager,
@@ -129,16 +132,18 @@ constructor(
setUpBottomArea(rootView)
setUpSmartspace(rootView)
smartSpaceView?.let {
KeyguardPreviewSmartspaceViewBinder.bind(it, smartspaceViewModel)
}
setUpUdfps(rootView)
if (!shouldHideClock) {
setUpClock(rootView)
KeyguardPreviewClockSmartspaceViewBinder.bind(
KeyguardPreviewClockViewBinder.bind(
largeClockHostView,
smallClockHostView,
smartSpaceView,
clockSmartspaceViewModel,
clockViewModel,
)
}
@@ -219,8 +224,8 @@ constructor(
smartSpaceView = lockscreenSmartspaceController.buildAndConnectDateView(parentView)
val topPadding: Int =
KeyguardPreviewClockSmartspaceViewModel.getLargeClockSmartspaceTopPadding(
context.resources
KeyguardPreviewSmartspaceViewModel.getLargeClockSmartspaceTopPadding(
context.resources,
)
val startPadding: Int =
@@ -372,7 +377,7 @@ constructor(
resources.getDimensionPixelSize(R.dimen.small_clock_height)
)
layoutParams.topMargin =
KeyguardPreviewClockSmartspaceViewModel.getStatusBarHeight(resources) +
KeyguardPreviewSmartspaceViewModel.getStatusBarHeight(resources) +
resources.getDimensionPixelSize(R.dimen.small_clock_padding_top)
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.map
/** View model for the small clock view, large clock view and smartspace. */
class KeyguardPreviewClockSmartspaceViewModel
/** View model for the smartspace. */
class KeyguardPreviewSmartspaceViewModel
@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 }
val smartSpaceTopPadding: Flow<Int> =
interactor.selectedClockSize.map {
when (it) {