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

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

Display current extendible theme icon (2/3)

Consolidate relevant information about an icon style into an icon style
model, including the icon to display, to enable passing extendible theme
icon from the repository up to the binder. Also allow ShapeTileDrawable
to work with any icon drawable to accomodate extendible theme icon.

Flag: com.android.systemui.shared.extendible_theme_manager
Bug: 397782741
Test: manually verified
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:cfaa650472b642d7be8d42b5e5968ac49a0df1ab)
Merged-In: I47e403301602b0f0ce8289d4b8d2a9d30468c066
Change-Id: I47e403301602b0f0ce8289d4b8d2a9d30468c066
parent 1bab7c05
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
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 kotlinx.coroutines.flow.Flow

interface IconStyleRepository {
@@ -25,7 +26,7 @@ interface IconStyleRepository {

    val isThemedIconActivated: Flow<Boolean>

    val iconStyles: Flow<List<IconStyle>>
    val iconStyleModels: Flow<List<IconStyleModel>>

    val selectedIconStyle: Flow<IconStyle>

+35 −4
Original line number Diff line number Diff line
@@ -20,13 +20,18 @@ import android.content.ContentResolver
import android.content.ContentValues
import android.content.Context
import android.database.ContentObserver
import android.graphics.drawable.AdaptiveIconDrawable
import android.net.Uri
import com.android.customization.module.CustomizationPreferences
import com.android.customization.picker.icon.shared.model.IconStyle
import com.android.customization.picker.icon.shared.model.IconStyleModel
import com.android.customization.picker.icon.shared.model.ThemePickerIconStyle
import com.android.themepicker.R
import com.android.wallpaper.customization.ui.binder.ShapeIconViewBinder
import com.android.wallpaper.customization.ui.view.ShapeTileDrawable
import com.android.wallpaper.model.Screen
import com.android.wallpaper.module.InjectorProvider
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
import com.android.wallpaper.util.PreviewUtils
import dagger.hilt.android.qualifiers.ApplicationContext
@@ -108,11 +113,37 @@ constructor(
                initialValue = false,
            )

    override val iconStyles: Flow<List<IconStyle>> =
    override val iconStyleModels: Flow<List<IconStyleModel>> =
        isThemedIconAvailable.map { isThemedIconAvailable ->
            var styles = ThemePickerIconStyle.entries.toList()
            if (!isThemedIconAvailable) styles = styles.filter { !it.getIsThemedIcon() }
            styles
            ThemePickerIconStyle.entries
                .toList()
                // Filter entries if themed icon is not available
                .filter { isThemedIconAvailable || !it.getIsThemedIcon() }
                .map { it.toIconStyleModel() }
        }

    private fun IconStyle.toIconStyleModel(): IconStyleModel {
        return IconStyleModel(
            iconStyle = this,
            nameResId = this.nameResId,
            icon = this.getIcon(),
            isThemedIcon = this == ThemePickerIconStyle.MONOCHROME,
            isExternalLink = false,
        )
    }

    private fun IconStyle.getIcon(): Icon {
        val previewIconPackageName = appContext.resources.getString(R.string.camera_package)
        val appIconDrawable = ShapeIconViewBinder.loadAppIcon(appContext, previewIconPackageName)
        return Icon.Loaded(
            drawable =
                ShapeTileDrawable(
                    context = appContext,
                    icon = appIconDrawable as? AdaptiveIconDrawable,
                    isThemed = this == ThemePickerIconStyle.MONOCHROME,
                ),
            contentDescription = null,
        )
    }

    override val selectedIconStyle =
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ constructor(

    val isThemedIconEnabled: Flow<Boolean> = iconStyleRepository.isThemedIconActivated

    val iconStyles = iconStyleRepository.iconStyles
    val iconStyleModels = iconStyleRepository.iconStyleModels

    val selectedIconStyle = iconStyleRepository.selectedIconStyle

+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.icon.shared.model

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

data class IconStyleModel(
    val iconStyle: IconStyle,
    val nameResId: Int,
    val icon: Icon?,
    val isThemedIcon: Boolean,
    val isExternalLink: Boolean,
)
+0 −4
Original line number Diff line number Diff line
@@ -25,8 +25,4 @@ enum class ThemePickerIconStyle(override val nameResId: Int) : IconStyle {
    override fun getIsThemedIcon(): Boolean {
        return this == MONOCHROME
    }

    override fun getIsExternalLink(): Boolean {
        return false
    }
}
Loading