Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 810cff17 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10975086 from a33ae479 to 24Q1-release

Change-Id: I42036b4b7e4bb0119c749cd5d04aa7146b8c5856
parents 0d727574 a33ae479
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import androidx.activity.ComponentActivity
import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
import com.android.customization.picker.clock.ui.view.ClockViewFactory
import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel
import com.android.customization.picker.clock.ui.viewmodel.ClockSectionViewModel
import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel
import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor
import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel
@@ -41,10 +40,6 @@ interface CustomizationInjector : Injector {

    fun getClockPickerInteractor(context: Context): ClockPickerInteractor

    fun getClockSectionViewModel(
        context: Context,
    ): ClockSectionViewModel

    fun getColorPickerInteractor(
        context: Context,
        wallpaperColorsRepository: WallpaperColorsRepository,
+0 −13
Original line number Diff line number Diff line
@@ -44,7 +44,6 @@ import com.android.customization.picker.clock.domain.interactor.ClockPickerSnaps
import com.android.customization.picker.clock.ui.view.ClockViewFactory
import com.android.customization.picker.clock.ui.view.ClockViewFactoryImpl
import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel
import com.android.customization.picker.clock.ui.viewmodel.ClockSectionViewModel
import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel
import com.android.customization.picker.color.data.repository.ColorPickerRepositoryImpl
import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor
@@ -105,7 +104,6 @@ internal constructor(
        null
    private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null
    private var clockPickerInteractor: ClockPickerInteractor? = null
    private var clockSectionViewModel: ClockSectionViewModel? = null
    private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null
    private var clockViewFactories: MutableMap<Int, ClockViewFactory> = HashMap()
    private var clockPickerSnapshotRestorer: ClockPickerSnapshotRestorer? = null
@@ -344,17 +342,6 @@ internal constructor(
                .also { clockPickerInteractor = it }
    }

    override fun getClockSectionViewModel(
        context: Context,
    ): ClockSectionViewModel {
        return clockSectionViewModel
            ?: ClockSectionViewModel(
                    context.applicationContext,
                    getClockPickerInteractor(context.applicationContext)
                )
                .also { clockSectionViewModel = it }
    }

    override fun getClockCarouselViewModelFactory(
        interactor: ClockPickerInteractor,
        clockViewFactory: ClockViewFactory,
+0 −53
Original line number Diff line number Diff line
/*
 * 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.customization.picker.clock.ui.binder

import android.view.View
import android.widget.TextView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.android.customization.picker.clock.ui.viewmodel.ClockSectionViewModel
import com.android.wallpaper.R
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch

object ClockSectionViewBinder {
    fun bind(
        view: View,
        viewModel: ClockSectionViewModel,
        lifecycleOwner: LifecycleOwner,
        onClicked: () -> Unit,
    ) {
        view.setOnClickListener { onClicked() }

        val selectedClockColorAndSize: TextView =
            view.requireViewById(R.id.selected_clock_color_and_size)

        lifecycleOwner.lifecycleScope.launch {
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    viewModel.selectedClockColorAndSizeText.collectLatest {
                        selectedClockColorAndSize.text = it
                    }
                }
            }
        }
    }
}
+0 −62
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.customization.picker.clock.ui.section

import android.content.Context
import android.view.LayoutInflater
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.lifecycleScope
import com.android.customization.picker.clock.ui.binder.ClockSectionViewBinder
import com.android.customization.picker.clock.ui.fragment.ClockSettingsFragment
import com.android.customization.picker.clock.ui.view.ClockSectionView
import com.android.customization.picker.clock.ui.viewmodel.ClockSectionViewModel
import com.android.wallpaper.R
import com.android.wallpaper.config.BaseFlags
import com.android.wallpaper.model.CustomizationSectionController
import com.android.wallpaper.model.CustomizationSectionController.CustomizationSectionNavigationController
import kotlinx.coroutines.launch

/** A [CustomizationSectionController] for clock customization. */
class ClockSectionController(
    private val navigationController: CustomizationSectionNavigationController,
    private val lifecycleOwner: LifecycleOwner,
    private val flag: BaseFlags,
    private val viewModel: ClockSectionViewModel,
) : CustomizationSectionController<ClockSectionView> {

    override fun isAvailable(context: Context): Boolean {
        return flag.isCustomClocksEnabled(context!!)
    }

    override fun createView(context: Context): ClockSectionView {
        val view =
            LayoutInflater.from(context)
                .inflate(
                    R.layout.clock_section_view,
                    null,
                ) as ClockSectionView
        lifecycleOwner.lifecycleScope.launch {
            ClockSectionViewBinder.bind(
                view = view,
                viewModel = viewModel,
                lifecycleOwner = lifecycleOwner
            ) {
                navigationController.navigateTo(ClockSettingsFragment())
            }
        }
        return view
    }
}
+0 −51
Original line number Diff line number Diff line
/*
 * 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.customization.picker.clock.ui.viewmodel

import android.content.Context
import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
import com.android.customization.picker.clock.shared.ClockSize
import com.android.wallpaper.R
import java.util.Locale
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

/** View model for the clock section view on the lockscreen customization surface. */
class ClockSectionViewModel(context: Context, interactor: ClockPickerInteractor) {
    val appContext: Context = context.applicationContext
    val clockColorMap: Map<String, ClockColorViewModel> =
        ClockColorViewModel.getPresetColorMap(appContext.resources)
    val selectedClockColorAndSizeText: Flow<String> =
        combine(interactor.selectedColorId, interactor.selectedClockSize, ::Pair).map {
            (selectedColorId, selectedClockSize) ->
            val colorText =
                clockColorMap[selectedColorId]?.colorName
                    ?: appContext.getString(R.string.default_theme_title)
            val sizeText =
                when (selectedClockSize) {
                    ClockSize.SMALL -> appContext.getString(R.string.clock_size_small)
                    ClockSize.DYNAMIC -> appContext.getString(R.string.clock_size_dynamic)
                }
            appContext
                .getString(R.string.clock_color_and_size_description, colorText, sizeText)
                .lowercase()
                .replaceFirstChar {
                    if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString()
                }
        }
}
Loading