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

Commit 087a3e16 authored by Catherine Liang's avatar Catherine Liang Committed by Android Build Coastguard Worker
Browse files

Add launcher extendible theme integration (2/3)

Flag: com.android.systemui.shared.extendible_theme_manager
Bug: 397782741
Test: manually verified
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:c5612b3ff6fbf5cda8d8d1bffbec084a165e6c5b)
Merged-In: I36db3f88e9dd7ad8385d35c85d817bbd73beb9dd
Change-Id: I36db3f88e9dd7ad8385d35c85d817bbd73beb9dd
parent eea88648
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -18,17 +18,22 @@ package com.android.customization.picker.icon.data.repository

import com.android.customization.picker.icon.shared.model.IconStyle
import com.android.customization.picker.icon.shared.model.IconStyleModel
import com.android.wallpaper.util.BasePreviewUtils
import kotlinx.coroutines.flow.Flow

interface IconStyleRepository {

    val isThemedIconAvailable: Flow<Boolean>
    val previewUtilsFlow: Flow<BasePreviewUtils?>

    val isCustomizationAvailable: Flow<Boolean>

    val isThemedIconActivated: Flow<Boolean>

    suspend fun setThemedIconEnabled(enabled: Boolean)

    val iconStyleModels: Flow<List<IconStyleModel>>

    val selectedIconStyle: Flow<IconStyle>

    suspend fun setThemedIconEnabled(enabled: Boolean)
    suspend fun setIconStyle(iconStyle: IconStyle)
}
+17 −10
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
@@ -61,7 +62,7 @@ constructor(
    private val metadataKey = appContext.getString(R.string.themed_icon_metadata_key)
    // TODO (b/424856247): test the retry logic for getting PreviewUtils
    private var previewUtils: PreviewUtils? = null
    private val previewUtilsFlow = flow {
    override val previewUtilsFlow = flow {
        // If PreviewUtils is created too early on start up, the provider (e.g. Launcher) may not be
        // ready, so PreviewUtils#supportsPreview would return false. Only cache previewUtils if it
        // supports previewing. Otherwise, retry when new flow consumers appear.
@@ -74,14 +75,12 @@ constructor(
        }
        emit(previewUtils)
    }
    private var uri: Uri? = null
    private val uriFlow: Flow<Uri?> =
        previewUtilsFlow.map { uri ?: it?.getUri(ICON_THEMED)?.also { result -> uri = result } }
    val themedIconUri: Flow<Uri?> = previewUtilsFlow.map { it?.getUri(ICON_THEMED) }

    override val isThemedIconAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null }
    override val isCustomizationAvailable: Flow<Boolean> = previewUtilsFlow.map { it != null }

    override val isThemedIconActivated: Flow<Boolean> =
        uriFlow
        themedIconUri
            .flatMapLatest {
                callbackFlow {
                    var disposableHandle: DisposableHandle? = null
@@ -114,7 +113,7 @@ constructor(
            )

    override val iconStyleModels: Flow<List<IconStyleModel>> =
        isThemedIconAvailable.map { isThemedIconAvailable ->
        isCustomizationAvailable.map { isThemedIconAvailable ->
            ThemePickerIconStyle.entries
                .toList()
                // Filter entries if themed icon is not available
@@ -178,16 +177,24 @@ constructor(
    }

    override suspend fun setThemedIconEnabled(enabled: Boolean) {
        uri?.let {
        themedIconUri.first()?.let {
            val values = ContentValues()
            values.put(COL_ICON_THEMED_VALUE, enabled)
            contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null)
        }
    }

    override suspend fun setIconStyle(iconStyle: IconStyle) {
        themedIconUri.first()?.let {
            val values = ContentValues()
            values.put(COL_ICON_THEMED_VALUE, iconStyle == ThemePickerIconStyle.MONOCHROME)
            contentResolver.update(it, values, /* where= */ null, /* selectionArgs= */ null)
        }
    }

    companion object {
        private const val ICON_THEMED = "icon_themed"
        private const val COL_ICON_THEMED_VALUE = "boolean_value"
        const val ICON_THEMED = "icon_themed"
        const val COL_ICON_THEMED_VALUE = "boolean_value"
        private const val ENABLED = 1
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.customization.picker.icon.domain.interactor
import com.android.customization.model.grid.ShapeOptionModel
import com.android.customization.picker.grid.data.repository.ShapeRepository
import com.android.customization.picker.icon.data.repository.IconStyleRepository
import com.android.customization.picker.icon.shared.model.IconStyle
import javax.inject.Inject
import javax.inject.Singleton
import kotlinx.coroutines.flow.Flow
@@ -42,7 +43,7 @@ constructor(

    val isShapeOptionsAvailable: Flow<Boolean> = shapeRepository.isShapeOptionsAvailable

    val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isThemedIconAvailable
    val isThemedIconAvailable: Flow<Boolean> = iconStyleRepository.isCustomizationAvailable

    val isThemedIconEnabled: Flow<Boolean> = iconStyleRepository.isThemedIconActivated

@@ -54,4 +55,6 @@ constructor(
        iconStyleRepository.setThemedIconEnabled(enabled)

    suspend fun applyShape(shapeKey: String) = shapeRepository.applyShape(shapeKey)

    suspend fun applyIconStyle(iconStyle: IconStyle) = iconStyleRepository.setIconStyle(iconStyle)
}
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package com.android.customization.picker.icon.shared.model

import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon

data class IconStyleModel(
open class IconStyleModel(
    val iconStyle: IconStyle,
    val nameResId: Int,
    val icon: Icon?,
+1 −1
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import kotlinx.coroutines.flow.Flow

@Singleton
class ThemedIconInteractor @Inject constructor(private val repository: IconStyleRepository) {
    val isAvailable: Flow<Boolean> = repository.isThemedIconAvailable
    val isAvailable: Flow<Boolean> = repository.isCustomizationAvailable
    val isActivated: Flow<Boolean> = repository.isThemedIconActivated

    suspend fun setThemedIconEnabled(enabled: Boolean) = repository.setThemedIconEnabled(enabled)
Loading