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

Commit fc752457 authored by Catherine Liang's avatar Catherine Liang
Browse files

Enable additional icon themes to be shown (1/2)

Move icon styles into repository.

Flag: com.android.systemui.shared.extendible_theme_manager
Bug: 397782741
Test: manually verified by testing with additional themes
Change-Id: I9d4e5d6dec7d41eb35af8c2f3f98a9223c71aecc
parent adcc7a6d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.customization.picker.icon.data.repository

import com.android.customization.picker.icon.shared.model.IconStyle
import kotlinx.coroutines.flow.Flow

interface IconStyleRepository {
@@ -24,5 +25,9 @@ interface IconStyleRepository {

    val isThemedIconActivated: Flow<Boolean>

    val iconStyles: Flow<List<IconStyle>>

    val selectedIconStyle: Flow<IconStyle>

    suspend fun setThemedIconEnabled(enabled: Boolean)
}
+17 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.content.Context
import android.database.ContentObserver
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.ThemePickerIconStyle
import com.android.themepicker.R
import com.android.wallpaper.model.Screen
import com.android.wallpaper.module.InjectorProvider
@@ -105,6 +107,21 @@ constructor(
                initialValue = false,
            )

    override val iconStyles: Flow<List<IconStyle>> =
        isThemedIconAvailable.map { isThemedIconAvailable ->
            var styles = ThemePickerIconStyle.entries.toList()
            if (!isThemedIconAvailable) styles = styles.filter { !it.getIsThemedIcon() }
            styles
        }

    override val selectedIconStyle =
        isThemedIconActivated.map {
            when (it) {
                true -> ThemePickerIconStyle.MONOCHROME
                false -> ThemePickerIconStyle.DEFAULT
            }
        }

    fun getThemedIconEnabled(uri: Uri): Boolean {
        val cursor =
            contentResolver.query(
+2 −15
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ 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
@@ -45,21 +44,9 @@ constructor(

    val isThemedIconEnabled: Flow<Boolean> = iconStyleRepository.isThemedIconActivated

    val iconStyles =
        isThemedIconAvailable.map { isThemedIconAvailable ->
            // TODO (b/397782741): introduce different icon styles depending on repository
            var styles = IconStyle.entries.toList()
            if (!isThemedIconAvailable) styles = styles.filter { it != IconStyle.MONOCHROME }
            styles
        }
    val iconStyles = iconStyleRepository.iconStyles

    val selectedIconStyle =
        isThemedIconEnabled.map {
            when (it) {
                true -> IconStyle.MONOCHROME
                false -> IconStyle.DEFAULT
            }
        }
    val selectedIconStyle = iconStyleRepository.selectedIconStyle

    suspend fun applyThemedIconEnabled(enabled: Boolean) =
        iconStyleRepository.setThemedIconEnabled(enabled)
+12 −2
Original line number Diff line number Diff line
@@ -18,7 +18,17 @@ package com.android.customization.picker.icon.shared.model

import com.android.themepicker.R

enum class IconStyle(val nameResId: Int) {
interface IconStyle {
    val nameResId: Int

    fun getIsThemedIcon(): Boolean
}

enum class ThemePickerIconStyle(override val nameResId: Int) : IconStyle {
    DEFAULT(R.string.app_icons_style_default),
    MONOCHROME(R.string.app_icons_style_minimal),
    MONOCHROME(R.string.app_icons_style_minimal);

    override fun getIsThemedIcon(): Boolean {
        return this == MONOCHROME
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -288,10 +288,11 @@ object AppIconFloatingSheetBinder {
                val imageView = view.findViewById(R.id.foreground) as? ImageView
                val disposableHandle =
                    imageView?.let {
                        // TODO (b/397782741): bind icons correctly for additional themes
                        ShapeIconViewBinder.bindPreviewIcon(
                            view = it,
                            appIconDrawable = appIconDrawable as? AdaptiveIconDrawable,
                            isThemed = iconStyle == IconStyle.MONOCHROME,
                            isThemed = iconStyle.getIsThemedIcon(),
                            colorUpdateViewModel = colorUpdateViewModel,
                            shouldAnimateColor = shouldAnimateColor,
                            lifecycleOwner = lifecycleOwner,
Loading