• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * 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 package com.android.customization.picker.clock.ui.viewmodel
18 
19 import android.content.Context
20 import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
21 import com.android.customization.picker.clock.shared.ClockSize
22 import com.android.wallpaper.R
23 import java.util.Locale
24 import kotlinx.coroutines.flow.Flow
25 import kotlinx.coroutines.flow.combine
26 import kotlinx.coroutines.flow.map
27 
28 /** View model for the clock section view on the lockscreen customization surface. */
29 class ClockSectionViewModel(context: Context, interactor: ClockPickerInteractor) {
30     val appContext: Context = context.applicationContext
31     val clockColorMap: Map<String, ClockColorViewModel> =
32         ClockColorViewModel.getPresetColorMap(appContext.resources)
33     val selectedClockColorAndSizeText: Flow<String> =
34         combine(interactor.selectedColorId, interactor.selectedClockSize, ::Pair).map {
35             (selectedColorId, selectedClockSize) ->
36             val colorText =
37                 clockColorMap[selectedColorId]?.colorName
38                     ?: context.getString(R.string.default_theme_title)
39             val sizeText =
40                 when (selectedClockSize) {
41                     ClockSize.SMALL -> appContext.getString(R.string.clock_size_small)
42                     ClockSize.DYNAMIC -> appContext.getString(R.string.clock_size_dynamic)
43                 }
44             appContext
45                 .getString(R.string.clock_color_and_size_description, colorText, sizeText)
46                 .lowercase()
47                 .replaceFirstChar {
48                     if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
49                 }
50         }
51 }
52