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

Commit 3a99c18f authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "[TP] Update the clock section title" into tm-qpr-dev

parents a11d857a 85b46549
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -33,14 +33,13 @@
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/clock_settings_title"
            android:text="@string/clock_color_and_size_title"
            style="@style/SectionTitleTextStyle" />

        <TextView
            android:id="@+id/selected_clock_text"
            android:id="@+id/selected_clock_color_and_size"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/clock_description"
            style="@style/SectionSubtitleTextStyle"/>
    </LinearLayout>

+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,12 @@
    <!-- Title of a section of the customization picker where the user can configure Clock face. [CHAR LIMIT=19] -->
    <string name="clock_settings_title">Clock Settings</string>

    <!-- Title of a section of the customization picker where the user can configure clock color and size. [CHAR LIMIT=20] -->
    <string name="clock_color_and_size_title">Clock color &amp; size</string>

    <!-- Description of a section of the customization picker where the user can configure clock color and size, e.g. Violet, small. [CHAR LIMIT=NONE] -->
    <string name="clock_color_and_size_description"><xliff:g name="color">%1$s</xliff:g>, <xliff:g name="size">%2$s</xliff:g></string>

    <!-- Title of a tab to change the clock color. [CHAR LIMIT=15] -->
    <string name="clock_color">Color</string>

+1 −1
Original line number Diff line number Diff line
@@ -311,7 +311,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject

    override fun getClockSectionViewModel(context: Context): ClockSectionViewModel {
        return clockSectionViewModel
            ?: ClockSectionViewModel(getClockPickerInteractor(context)).also {
            ?: ClockSectionViewModel(context, getClockPickerInteractor(context)).also {
                clockSectionViewModel = it
            }
    }
+9 −6
Original line number Diff line number Diff line
@@ -21,8 +21,8 @@ import android.view.View
import android.widget.TextView
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.flowWithLifecycle
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
@@ -37,13 +37,16 @@ object ClockSectionViewBinder {
    ) {
        view.setOnClickListener { onClicked() }

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

        lifecycleOwner.lifecycleScope.launch {
            viewModel.selectedClockName
                .flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
                .collectLatest { selectedClockName ->
                    selectedClockTextView.text = selectedClockName
            lifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    viewModel.selectedClockColorAndSizeText.collectLatest {
                        selectedClockColorAndSize.text = it
                    }
                }
            }
        }
    }
+22 −3
Original line number Diff line number Diff line
@@ -16,12 +16,31 @@
 */
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.map

/** View model for the clock section view on the lockscreen customization surface. */
class ClockSectionViewModel(interactor: ClockPickerInteractor) {

    val selectedClockName: Flow<String> = interactor.selectedClock.map { it.name }
class ClockSectionViewModel(context: Context, interactor: ClockPickerInteractor) {
    val appContext: Context = context.applicationContext
    val selectedClockColorAndSizeText: Flow<String> =
        interactor.selectedClockSize.map { selectedClockSize ->
            // TODO (b/241966062) Finalize the colors and their names
            val colorText = "Violet"
            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