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

Commit 2f6c3c04 authored by George Lin's avatar George Lin Committed by Android (Google) Code Review
Browse files

Merge "Fix crash of resource not found for grid options" into main

parents a8c98902 9e1e8a52
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.customization.model.grid

import android.content.ContentValues
import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import android.util.Log
import androidx.core.content.res.ResourcesCompat
import com.android.wallpaper.R
import com.android.wallpaper.picker.di.modules.BackgroundDispatcher
@@ -156,15 +158,26 @@ constructor(
        )
    }

    override fun getGridOptionDrawble(iconId: Int): Drawable? {
        return ResourcesCompat.getDrawable(
    override fun getGridOptionDrawable(iconId: Int): Drawable? {
        try {
            val drawable =
                ResourcesCompat.getDrawable(
                    context.packageManager.getResourcesForApplication(APP_RESOURCES_PACKAGE_NAME),
                    iconId,
                    /* theme = */ null,
                )
            return drawable
        } catch (exception: Resources.NotFoundException) {
            Log.w(
                TAG,
                "Unable to find drawable resource from package $APP_RESOURCES_PACKAGE_NAME with resource ID $iconId",
            )
            return null
        }
    }

    companion object {
        const val TAG = "DefaultShapeGridManager"
        const val SHAPE_OPTIONS: String = "shape_options"
        const val GRID_OPTIONS: String = "list_options"
        const val SHAPE_GRID: String = "default_grid"
+1 −1
Original line number Diff line number Diff line
@@ -26,5 +26,5 @@ interface ShapeGridManager {

    fun applyShapeGridOption(shapeKey: String, gridKey: String): Int

    fun getGridOptionDrawble(iconId: Int): Drawable?
    fun getGridOptionDrawable(iconId: Int): Drawable?
}
+1 −1
Original line number Diff line number Diff line
@@ -72,6 +72,6 @@ constructor(
        }

    fun getGridOptionDrawable(iconId: Int): Drawable? {
        return manager.getGridOptionDrawble(iconId)
        return manager.getGridOptionDrawable(iconId)
    }
}
+19 −2
Original line number Diff line number Diff line
@@ -17,11 +17,14 @@
package com.android.wallpaper.customization.ui.viewmodel

import android.content.Context
import android.content.res.Resources
import android.graphics.drawable.Drawable
import com.android.customization.model.ResourceConstants
import com.android.customization.model.grid.GridOptionModel
import com.android.customization.model.grid.ShapeOptionModel
import com.android.customization.picker.grid.domain.interactor.ShapeGridInteractor
import com.android.customization.picker.grid.ui.viewmodel.ShapeIconViewModel
import com.android.customization.widget.GridTileDrawable
import com.android.themepicker.R
import com.android.wallpaper.picker.common.icon.ui.viewmodel.Icon
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
@@ -186,6 +189,21 @@ constructor(
    }

    private fun toGridOptionItemViewModel(option: GridOptionModel): OptionItemViewModel2<Drawable> {
        // Fallback to use GridTileDrawable when no resource found for the icon ID
        val drawable =
            interactor.getGridOptionDrawable(option.iconId)
                ?: GridTileDrawable(
                    option.cols,
                    option.rows,
                    context.resources.getString(
                        Resources.getSystem()
                            .getIdentifier(
                                ResourceConstants.CONFIG_ICON_MASK,
                                "string",
                                ResourceConstants.ANDROID_PACKAGE,
                            )
                    ),
                )
        val isSelected =
            previewingGridKey
                .map { it == option.key }
@@ -194,10 +212,9 @@ constructor(
                    started = SharingStarted.Lazily,
                    initialValue = false,
                )

        return OptionItemViewModel2(
            key = MutableStateFlow(option.key),
            payload = interactor.getGridOptionDrawable(option.iconId),
            payload = drawable,
            text = Text.Loaded(option.title),
            isSelected = isSelected,
            onClicked =
+1 −1
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class FakeShapeGridManager @Inject constructor() : ShapeGridManager {
        return 0
    }

    override fun getGridOptionDrawble(iconId: Int): Drawable? {
    override fun getGridOptionDrawable(iconId: Int): Drawable? {
        return when (iconId) {
            0 -> gridOptionDrawable0
            1 -> gridOptionDrawable1