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

Commit 0421eb5e authored by Chris Poultney's avatar Chris Poultney Committed by Android (Google) Code Review
Browse files

Merge changes from topic "blackflash-main" into main

* changes:
  Reuse ClockViewFactory
  Cache affordances and selection picker side
parents a33ae479 953c3eeb
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
 */
package com.android.customization.module

import android.app.Activity
import android.app.UiModeManager
import android.app.WallpaperManager
import android.content.Context
@@ -105,7 +106,7 @@ internal constructor(
    private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null
    private var clockPickerInteractor: ClockPickerInteractor? = null
    private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null
    private var clockViewFactories: MutableMap<Int, ClockViewFactory> = HashMap()
    private var clockViewFactory: ClockViewFactory? = null
    private var clockPickerSnapshotRestorer: ClockPickerSnapshotRestorer? = null
    private var notificationsInteractor: NotificationsInteractor? = null
    private var notificationSectionViewModelFactory: NotificationSectionViewModel.Factory? = null
@@ -247,7 +248,7 @@ internal constructor(
        val client = getKeyguardQuickAffordancePickerProviderClient(context)
        val appContext = context.applicationContext
        return KeyguardQuickAffordancePickerInteractor(
            KeyguardQuickAffordancePickerRepository(client),
            KeyguardQuickAffordancePickerRepository(client, getApplicationCoroutineScope()),
            client
        ) {
            getKeyguardQuickAffordanceSnapshotRestorer(appContext)
@@ -353,8 +354,7 @@ internal constructor(
    }

    override fun getClockViewFactory(activity: ComponentActivity): ClockViewFactory {
        val activityHashCode = activity.hashCode()
        return clockViewFactories[activityHashCode]
        return clockViewFactory
            ?: ClockViewFactoryImpl(
                    activity.applicationContext,
                    ScreenSizeCalculator.getInstance()
@@ -363,13 +363,13 @@ internal constructor(
                    getClockRegistry(activity.applicationContext),
                )
                .also {
                    clockViewFactories[activityHashCode] = it
                    clockViewFactory = it
                    activity.lifecycle.addObserver(
                        object : DefaultLifecycleObserver {
                            override fun onDestroy(owner: LifecycleOwner) {
                                super.onDestroy(owner)
                                clockViewFactories[activityHashCode]?.onDestroy()
                                clockViewFactories.remove(activityHashCode)
                                if ((owner as Activity).isChangingConfigurations()) return
                                clockViewFactory?.onDestroy()
                            }
                        }
                    )
+12 −6
Original line number Diff line number Diff line
@@ -21,8 +21,11 @@ import com.android.customization.picker.quickaffordance.shared.model.KeyguardQui
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSelectionModel as SelectionModel
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSlotModel as SlotModel
import com.android.systemui.shared.customization.data.content.CustomizationProviderClient as Client
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn

/**
 * Abstracts access to application state related to functionality for selecting, picking, or setting
@@ -30,6 +33,7 @@ import kotlinx.coroutines.flow.map
 */
class KeyguardQuickAffordancePickerRepository(
    private val client: Client,
    private val scope: CoroutineScope
) {
    /** List of slots available on the device. */
    val slots: Flow<List<SlotModel>> =
@@ -37,15 +41,17 @@ class KeyguardQuickAffordancePickerRepository(

    /** List of all available quick affordances. */
    val affordances: Flow<List<AffordanceModel>> =
        client.observeAffordances().map { affordances ->
            affordances.map { affordance -> affordance.toModel() }
        }
        client
            .observeAffordances()
            .map { affordances -> affordances.map { affordance -> affordance.toModel() } }
            .shareIn(scope, replay = 1, started = SharingStarted.Lazily)

    /** List of slot-affordance pairs, modeling what the user has currently chosen for each slot. */
    val selections: Flow<List<SelectionModel>> =
        client.observeSelections().map { selections ->
            selections.map { selection -> selection.toModel() }
        }
        client
            .observeSelections()
            .map { selections -> selections.map { selection -> selection.toModel() } }
            .shareIn(scope, replay = 1, started = SharingStarted.Lazily)

    private fun Client.Slot.toModel(): SlotModel {
        return SlotModel(
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.android.customization.model.picker.quickaffordance.data.repository
import androidx.test.filters.SmallTest
import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository
import com.android.systemui.shared.customization.data.content.FakeCustomizationProviderClient
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
@@ -28,6 +29,7 @@ import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@@ -51,9 +53,16 @@ class KeyguardQuickAffordancePickerRepositoryTest {
        underTest =
            KeyguardQuickAffordancePickerRepository(
                client = client,
                scope = testScope.backgroundScope,
            )
    }

    // We need at least one test to prevent Studio errors
    @Test
    fun creationSucceeds() {
        assertThat(underTest).isNotNull()
    }

    @After
    fun tearDown() {
        Dispatchers.resetMain()
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ class KeyguardQuickAffordancePickerInteractorTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                    ),
                client = client,
                snapshotRestorer = {
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                    ),
                client = client,
                snapshotRestorer = {