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

Commit 7e5ed447 authored by George Lin's avatar George Lin
Browse files

[TP] Clock color picker

Add clock color picker

Test: Manually tested that clock color picker works
Bug: 241966062
Change-Id: I3c017a78cca5844c3a15f1ad65c10622301c1944
parent ea078c3f
Loading
Loading
Loading
Loading
+27 −8
Original line number Original line Diff line number Diff line
@@ -19,11 +19,11 @@
    android:layout_width="match_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    android:orientation="vertical">

    <FrameLayout
    <FrameLayout
        android:id="@+id/section_header_container"
        android:id="@+id/section_header_container"
        android:layout_width="match_parent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        android:layout_height="wrap_content">

        <include layout="@layout/section_header" />
        <include layout="@layout/section_header" />
    </FrameLayout>
    </FrameLayout>


@@ -94,16 +94,35 @@
        </FrameLayout>
        </FrameLayout>


        <FrameLayout
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingTop="16dp">

            <FrameLayout
                android:id="@+id/color_options_container"
                android:layout_width="match_parent"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                android:layout_height="wrap_content">


                <androidx.recyclerview.widget.RecyclerView
                <androidx.recyclerview.widget.RecyclerView
                android:id="@id/affordances"
                    android:id="@+id/color_options"
                    android:layout_width="match_parent"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_height="wrap_content"
                    android:clipToPadding="false"
                    android:clipToPadding="false"
                android:paddingHorizontal="16dp"
                    android:paddingHorizontal="16dp" />
                android:visibility="gone"/>

                <!--
                This is just an invisible placeholder put in place so that the parent keeps its
                height stable as the RecyclerView updates from 0 items to N items. Keeping it stable
                allows the layout logic to keep the size of the preview container stable as well,
                which bodes well for setting up the SurfaceView for remote rendering without
                changing its size after the content is loaded into the RecyclerView.
                -->
                <include
                    layout="@layout/color_option_with_background"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:visibility="invisible" />
            </FrameLayout>


            <com.android.customization.picker.clock.ui.view.ClockSizeRadioButtonGroup
            <com.android.customization.picker.clock.ui.view.ClockSizeRadioButtonGroup
                android:id="@+id/clock_size_radio_button_group"
                android:id="@+id/clock_size_radio_button_group"
+2 −0
Original line number Original line Diff line number Diff line
@@ -33,5 +33,7 @@ interface ClockPickerRepository {


    fun setSelectedClock(clockId: String)
    fun setSelectedClock(clockId: String)


    fun setClockColor(color: Int?)

    fun setClockSize(size: ClockSize)
    fun setClockSize(size: ClockSize)
}
}
+8 −4
Original line number Original line Diff line number Diff line
@@ -43,7 +43,7 @@ class ClockPickerRepositoryImpl(
        registry
        registry
            .getClocks()
            .getClocks()
            .filter { "NOT_IN_USE" !in it.clockId }
            .filter { "NOT_IN_USE" !in it.clockId }
            .map { it.toModel() }
            .map { it.toModel(null) }
            .toTypedArray()
            .toTypedArray()


    /** The currently-selected clock. */
    /** The currently-selected clock. */
@@ -56,7 +56,7 @@ class ClockPickerRepositoryImpl(
                        registry
                        registry
                            .getClocks()
                            .getClocks()
                            .find { clockMetadata -> clockMetadata.clockId == currentClockId }
                            .find { clockMetadata -> clockMetadata.clockId == currentClockId }
                            ?.toModel()
                            ?.toModel(registry.seedColor)
                    if (model == null) {
                    if (model == null) {
                        Log.w(
                        Log.w(
                            TAG,
                            TAG,
@@ -77,6 +77,10 @@ class ClockPickerRepositoryImpl(
        registry.currentClockId = clockId
        registry.currentClockId = clockId
    }
    }


    override fun setClockColor(color: Int?) {
        registry.seedColor = color
    }

    // TODO(b/262924055): Use the shared system UI component to query the clock size
    // TODO(b/262924055): Use the shared system UI component to query the clock size
    private val _selectedClockSize = MutableStateFlow(ClockSize.DYNAMIC)
    private val _selectedClockSize = MutableStateFlow(ClockSize.DYNAMIC)
    override val selectedClockSize: Flow<ClockSize> = _selectedClockSize.asStateFlow()
    override val selectedClockSize: Flow<ClockSize> = _selectedClockSize.asStateFlow()
@@ -85,8 +89,8 @@ class ClockPickerRepositoryImpl(
        _selectedClockSize.value = size
        _selectedClockSize.value = size
    }
    }


    private fun ClockMetadata.toModel(): ClockMetadataModel {
    private fun ClockMetadata.toModel(color: Int?): ClockMetadataModel {
        return ClockMetadataModel(clockId = clockId, name = name)
        return ClockMetadataModel(clockId = clockId, name = name, color = color)
    }
    }


    companion object {
    companion object {
+7 −0
Original line number Original line Diff line number Diff line
@@ -21,6 +21,7 @@ import com.android.customization.picker.clock.data.repository.ClockPickerReposit
import com.android.customization.picker.clock.shared.ClockSize
import com.android.customization.picker.clock.shared.ClockSize
import com.android.customization.picker.clock.shared.model.ClockMetadataModel
import com.android.customization.picker.clock.shared.model.ClockMetadataModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map


/**
/**
 * Interactor for accessing application clock settings, as well as selecting and configuring custom
 * Interactor for accessing application clock settings, as well as selecting and configuring custom
@@ -31,12 +32,18 @@ class ClockPickerInteractor(private val repository: ClockPickerRepository) {


    val selectedClock: Flow<ClockMetadataModel> = repository.selectedClock
    val selectedClock: Flow<ClockMetadataModel> = repository.selectedClock


    val selectedClockColor: Flow<Int?> = repository.selectedClock.map { clock -> clock.color }

    val selectedClockSize: Flow<ClockSize> = repository.selectedClockSize
    val selectedClockSize: Flow<ClockSize> = repository.selectedClockSize


    fun setSelectedClock(clockId: String) {
    fun setSelectedClock(clockId: String) {
        repository.setSelectedClock(clockId)
        repository.setSelectedClock(clockId)
    }
    }


    fun setClockColor(color: Int?) {
        repository.setClockColor(color)
    }

    fun setClockSize(size: ClockSize) {
    fun setClockSize(size: ClockSize) {
        repository.setClockSize(size)
        repository.setClockSize(size)
    }
    }
+1 −0
Original line number Original line Diff line number Diff line
@@ -21,4 +21,5 @@ package com.android.customization.picker.clock.shared.model
data class ClockMetadataModel(
data class ClockMetadataModel(
    val clockId: String,
    val clockId: String,
    val name: String,
    val name: String,
    val color: Int?,
)
)
Loading