Loading src/com/android/wallpaper/customization/ui/binder/ShapeIconViewBinder.kt +40 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.widget.ImageView import androidx.lifecycle.LifecycleOwner import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel import com.android.wallpaper.customization.ui.view.ShapeTileDrawable import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon import com.android.wallpaper.picker.customization.ui.binder.ColorUpdateBinder import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel import kotlinx.coroutines.DisposableHandle Loading @@ -36,7 +37,45 @@ object ShapeIconViewBinder { view.setImageDrawable(ShapeTileDrawable(view.context, shapeIcon.path)) } fun bindPreviewIcon( fun bindIconStyleAndShapePreviewIcon( view: ImageView, icon: Icon?, shapeIcon: ShapeIconViewModel? = null, colorUpdateViewModel: ColorUpdateViewModel, shouldAnimateColor: () -> Boolean, lifecycleOwner: LifecycleOwner, ): DisposableHandle? { val iconDrawable = icon?.getDrawable(view.context) val shapeIconDrawable = if (iconDrawable is ShapeTileDrawable) { ShapeTileDrawable( context = view.context, path = shapeIcon?.path, icon = iconDrawable.icon, isThemed = iconDrawable.isThemed, ) } else if (shapeIcon?.path != null) { ShapeTileDrawable( context = view.context, path = shapeIcon.path, icon = iconDrawable, isThemed = false, ) } else iconDrawable view.setImageDrawable(shapeIconDrawable) val disposableHandle = if (shapeIconDrawable is ShapeTileDrawable && shapeIconDrawable.isThemed) { bindPreviewIconColor( shapeTileDrawable = shapeIconDrawable, colorUpdateViewModel = colorUpdateViewModel, shouldAnimateColor = shouldAnimateColor, lifecycleOwner = lifecycleOwner, ) } else null return disposableHandle } fun bindShapeAndThemedIconPreviewIcon( view: ImageView, appIconDrawable: AdaptiveIconDrawable?, shapeIcon: ShapeIconViewModel? = null, Loading src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt +58 −24 Original line number Diff line number Diff line Loading @@ -354,21 +354,51 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO launch { var disposableHandle: DisposableHandle? = null if (BaseFlags.get().isExtendibleThemeManager()) { optionsViewModel.appIconPickerViewModel.iconStyleAndShapeSummary .collect { summary -> disposableHandle?.dispose() summary.iconShape?.let { optionAppIconsIcon?.let { it1 -> disposableHandle = ShapeIconViewBinder .bindIconStyleAndShapePreviewIcon( view = it1, icon = summary.icon, shapeIcon = summary.iconShape, colorUpdateViewModel = colorUpdateViewModel, shouldAnimateColor = isOnMainScreen, lifecycleOwner = lifecycleOwner, ) } } optionAppIconsDescription?.let { TextViewBinder.bind( view = it, viewModel = summary.description, ) } } } else { val previewIconPackageName = view.context.resources.getString(R.string.camera_package) val appIconDrawable = ShapeIconViewBinder.loadAppIcon(view.context, previewIconPackageName) optionsViewModel.appIconPickerViewModel.summary.collect { summary -> ShapeIconViewBinder.loadAppIcon( view.context, previewIconPackageName, ) optionsViewModel.appIconPickerViewModel.shapeAndThemedIconSummary .collect { summary -> disposableHandle?.dispose() summary.iconShape?.let { disposableHandle = optionAppIconsIcon?.let { it1 -> // TODO (b/397782741): bind icons correctly for additional // themes ShapeIconViewBinder.bindPreviewIcon( ShapeIconViewBinder .bindShapeAndThemedIconPreviewIcon( view = it1, appIconDrawable = appIconDrawable as? AdaptiveIconDrawable, appIconDrawable as? AdaptiveIconDrawable, shapeIcon = summary.iconShape, isThemed = summary.isThemed, colorUpdateViewModel = colorUpdateViewModel, Loading @@ -378,7 +408,11 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO } } optionAppIconsDescription?.let { TextViewBinder.bind(view = it, viewModel = summary.description) TextViewBinder.bind( view = it, viewModel = summary.description, ) } } } } Loading src/com/android/wallpaper/customization/ui/view/ShapeTileDrawable.kt +2 −2 Original line number Diff line number Diff line Loading @@ -44,8 +44,8 @@ import com.android.wallpaper.R class ShapeTileDrawable( context: Context, path: String? = null, private val icon: Drawable? = null, private val isThemed: Boolean = false, val icon: Drawable? = null, val isThemed: Boolean = false, ) : Drawable() { private val paint = Paint(Paint.ANTI_ALIAS_FLAG) Loading src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerSummaryViewModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,13 @@ package com.android.wallpaper.customization.ui.viewmodel import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon import com.android.wallpaper.picker.common.text.ui.viewmodel.Text /** View model representing information needed for the app icon entry point summary. */ data class AppIconPickerSummaryViewModel( val description: Text, val iconShape: ShapeIconViewModel?, val icon: Icon?, val isThemed: Boolean, ) src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerViewModel.kt +52 −7 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ constructor( replay = 1, ) //// Themed icons enabled //// Themed icons val isThemedIconAvailable = interactor.isThemedIconAvailable.shareIn( scope = viewModelScope, Loading Loading @@ -144,12 +144,12 @@ constructor( private val _selectedTab = MutableStateFlow<Tab?>(null) val selectedTab = combine(isThemedIconAvailable, isShapeOptionsAvailable, _selectedTab) { isThemedIconAvailable, combine(isIconStyleAvailable, isShapeOptionsAvailable, _selectedTab) { isIconStyleAvailable, isShapeOptionsAvailable, selectedTab -> selectedTab ?: if (isThemedIconAvailable) { ?: if (isIconStyleAvailable) { Tab.STYLE } else if (isShapeOptionsAvailable) { Tab.SHAPE Loading Loading @@ -211,7 +211,7 @@ constructor( } } val summary: Flow<AppIconPickerSummaryViewModel> = val shapeAndThemedIconSummary: Flow<AppIconPickerSummaryViewModel> = combine(selectedShape, isThemedIconEnabled, isShapeOptionsAvailable) { selectedShape, isThemedIconEnabled, Loading Loading @@ -241,11 +241,56 @@ constructor( } ), iconShape = selectedShape.payload, icon = null, isThemed = isThemedIconEnabled, ) } val onApply: Flow<(suspend () -> Unit)?> = val iconStyleAndShapeSummary: Flow<AppIconPickerSummaryViewModel> = combine( selectedShape, selectedIconStyle, iconStylesModels, isIconStyleAvailable, isShapeOptionsAvailable, ) { selectedShape, selectedIconStyle, iconStylesModels, isIconStyleAvailable, isShapeOptionsAvailable -> val selectedShapeString = if (isShapeOptionsAvailable) selectedShape.text.asString(applicationContext) else "" val selectedIconStyleModel = iconStylesModels.find { it.iconStyle == selectedIconStyle } val appIconThemeString = if (isIconStyleAvailable) selectedIconStyleModel?.nameResId?.let { applicationContext.getString(it) } else null AppIconPickerSummaryViewModel( description = Text.Loaded( if ( selectedShapeString.isNotEmpty() && !appIconThemeString.isNullOrEmpty() ) { // Show theme and shape, comma separated applicationContext.getString( R.string.app_icons_description, appIconThemeString, selectedShapeString, ) } else if (!appIconThemeString.isNullOrEmpty()) { appIconThemeString } else { selectedShapeString } ), iconShape = selectedShape.payload, icon = selectedIconStyleModel?.icon, isThemed = selectedIconStyleModel?.isThemedIcon ?: false, ) } val shapeAndThemedIconOnApply: Flow<(suspend () -> Unit)?> = combine( overridingShapeKey, selectedShape, Loading Loading @@ -288,7 +333,7 @@ constructor( } } val onApply2: Flow<(suspend () -> Unit)?> = val iconStyleAndShapeOnApply: Flow<(suspend () -> Unit)?> = combine(overridingShapeKey, selectedShape, overridingIconStyle, selectedIconStyle) { overridingShapeKey, selectedShape, Loading Loading
src/com/android/wallpaper/customization/ui/binder/ShapeIconViewBinder.kt +40 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import android.widget.ImageView import androidx.lifecycle.LifecycleOwner import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel import com.android.wallpaper.customization.ui.view.ShapeTileDrawable import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon import com.android.wallpaper.picker.customization.ui.binder.ColorUpdateBinder import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel import kotlinx.coroutines.DisposableHandle Loading @@ -36,7 +37,45 @@ object ShapeIconViewBinder { view.setImageDrawable(ShapeTileDrawable(view.context, shapeIcon.path)) } fun bindPreviewIcon( fun bindIconStyleAndShapePreviewIcon( view: ImageView, icon: Icon?, shapeIcon: ShapeIconViewModel? = null, colorUpdateViewModel: ColorUpdateViewModel, shouldAnimateColor: () -> Boolean, lifecycleOwner: LifecycleOwner, ): DisposableHandle? { val iconDrawable = icon?.getDrawable(view.context) val shapeIconDrawable = if (iconDrawable is ShapeTileDrawable) { ShapeTileDrawable( context = view.context, path = shapeIcon?.path, icon = iconDrawable.icon, isThemed = iconDrawable.isThemed, ) } else if (shapeIcon?.path != null) { ShapeTileDrawable( context = view.context, path = shapeIcon.path, icon = iconDrawable, isThemed = false, ) } else iconDrawable view.setImageDrawable(shapeIconDrawable) val disposableHandle = if (shapeIconDrawable is ShapeTileDrawable && shapeIconDrawable.isThemed) { bindPreviewIconColor( shapeTileDrawable = shapeIconDrawable, colorUpdateViewModel = colorUpdateViewModel, shouldAnimateColor = shouldAnimateColor, lifecycleOwner = lifecycleOwner, ) } else null return disposableHandle } fun bindShapeAndThemedIconPreviewIcon( view: ImageView, appIconDrawable: AdaptiveIconDrawable?, shapeIcon: ShapeIconViewModel? = null, Loading
src/com/android/wallpaper/customization/ui/binder/ThemePickerCustomizationOptionBinder.kt +58 −24 Original line number Diff line number Diff line Loading @@ -354,21 +354,51 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO launch { var disposableHandle: DisposableHandle? = null if (BaseFlags.get().isExtendibleThemeManager()) { optionsViewModel.appIconPickerViewModel.iconStyleAndShapeSummary .collect { summary -> disposableHandle?.dispose() summary.iconShape?.let { optionAppIconsIcon?.let { it1 -> disposableHandle = ShapeIconViewBinder .bindIconStyleAndShapePreviewIcon( view = it1, icon = summary.icon, shapeIcon = summary.iconShape, colorUpdateViewModel = colorUpdateViewModel, shouldAnimateColor = isOnMainScreen, lifecycleOwner = lifecycleOwner, ) } } optionAppIconsDescription?.let { TextViewBinder.bind( view = it, viewModel = summary.description, ) } } } else { val previewIconPackageName = view.context.resources.getString(R.string.camera_package) val appIconDrawable = ShapeIconViewBinder.loadAppIcon(view.context, previewIconPackageName) optionsViewModel.appIconPickerViewModel.summary.collect { summary -> ShapeIconViewBinder.loadAppIcon( view.context, previewIconPackageName, ) optionsViewModel.appIconPickerViewModel.shapeAndThemedIconSummary .collect { summary -> disposableHandle?.dispose() summary.iconShape?.let { disposableHandle = optionAppIconsIcon?.let { it1 -> // TODO (b/397782741): bind icons correctly for additional // themes ShapeIconViewBinder.bindPreviewIcon( ShapeIconViewBinder .bindShapeAndThemedIconPreviewIcon( view = it1, appIconDrawable = appIconDrawable as? AdaptiveIconDrawable, appIconDrawable as? AdaptiveIconDrawable, shapeIcon = summary.iconShape, isThemed = summary.isThemed, colorUpdateViewModel = colorUpdateViewModel, Loading @@ -378,7 +408,11 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO } } optionAppIconsDescription?.let { TextViewBinder.bind(view = it, viewModel = summary.description) TextViewBinder.bind( view = it, viewModel = summary.description, ) } } } } Loading
src/com/android/wallpaper/customization/ui/view/ShapeTileDrawable.kt +2 −2 Original line number Diff line number Diff line Loading @@ -44,8 +44,8 @@ import com.android.wallpaper.R class ShapeTileDrawable( context: Context, path: String? = null, private val icon: Drawable? = null, private val isThemed: Boolean = false, val icon: Drawable? = null, val isThemed: Boolean = false, ) : Drawable() { private val paint = Paint(Paint.ANTI_ALIAS_FLAG) Loading
src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerSummaryViewModel.kt +2 −0 Original line number Diff line number Diff line Loading @@ -17,11 +17,13 @@ package com.android.wallpaper.customization.ui.viewmodel import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon import com.android.wallpaper.picker.common.text.ui.viewmodel.Text /** View model representing information needed for the app icon entry point summary. */ data class AppIconPickerSummaryViewModel( val description: Text, val iconShape: ShapeIconViewModel?, val icon: Icon?, val isThemed: Boolean, )
src/com/android/wallpaper/customization/ui/viewmodel/AppIconPickerViewModel.kt +52 −7 Original line number Diff line number Diff line Loading @@ -85,7 +85,7 @@ constructor( replay = 1, ) //// Themed icons enabled //// Themed icons val isThemedIconAvailable = interactor.isThemedIconAvailable.shareIn( scope = viewModelScope, Loading Loading @@ -144,12 +144,12 @@ constructor( private val _selectedTab = MutableStateFlow<Tab?>(null) val selectedTab = combine(isThemedIconAvailable, isShapeOptionsAvailable, _selectedTab) { isThemedIconAvailable, combine(isIconStyleAvailable, isShapeOptionsAvailable, _selectedTab) { isIconStyleAvailable, isShapeOptionsAvailable, selectedTab -> selectedTab ?: if (isThemedIconAvailable) { ?: if (isIconStyleAvailable) { Tab.STYLE } else if (isShapeOptionsAvailable) { Tab.SHAPE Loading Loading @@ -211,7 +211,7 @@ constructor( } } val summary: Flow<AppIconPickerSummaryViewModel> = val shapeAndThemedIconSummary: Flow<AppIconPickerSummaryViewModel> = combine(selectedShape, isThemedIconEnabled, isShapeOptionsAvailable) { selectedShape, isThemedIconEnabled, Loading Loading @@ -241,11 +241,56 @@ constructor( } ), iconShape = selectedShape.payload, icon = null, isThemed = isThemedIconEnabled, ) } val onApply: Flow<(suspend () -> Unit)?> = val iconStyleAndShapeSummary: Flow<AppIconPickerSummaryViewModel> = combine( selectedShape, selectedIconStyle, iconStylesModels, isIconStyleAvailable, isShapeOptionsAvailable, ) { selectedShape, selectedIconStyle, iconStylesModels, isIconStyleAvailable, isShapeOptionsAvailable -> val selectedShapeString = if (isShapeOptionsAvailable) selectedShape.text.asString(applicationContext) else "" val selectedIconStyleModel = iconStylesModels.find { it.iconStyle == selectedIconStyle } val appIconThemeString = if (isIconStyleAvailable) selectedIconStyleModel?.nameResId?.let { applicationContext.getString(it) } else null AppIconPickerSummaryViewModel( description = Text.Loaded( if ( selectedShapeString.isNotEmpty() && !appIconThemeString.isNullOrEmpty() ) { // Show theme and shape, comma separated applicationContext.getString( R.string.app_icons_description, appIconThemeString, selectedShapeString, ) } else if (!appIconThemeString.isNullOrEmpty()) { appIconThemeString } else { selectedShapeString } ), iconShape = selectedShape.payload, icon = selectedIconStyleModel?.icon, isThemed = selectedIconStyleModel?.isThemedIcon ?: false, ) } val shapeAndThemedIconOnApply: Flow<(suspend () -> Unit)?> = combine( overridingShapeKey, selectedShape, Loading Loading @@ -288,7 +333,7 @@ constructor( } } val onApply2: Flow<(suspend () -> Unit)?> = val iconStyleAndShapeOnApply: Flow<(suspend () -> Unit)?> = combine(overridingShapeKey, selectedShape, overridingIconStyle, selectedIconStyle) { overridingShapeKey, selectedShape, Loading