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

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

Merge "Fix content description for the grid option (2/2)" into main

parents 879d5889 5c0f7c6a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -204,6 +204,9 @@
    <!--Title for a grid option, describing the number of columns and rows, eg: 4x4 [CHAR LIMIT=10] -->
    <string name="grid_title_pattern"><xliff:g name="num_cols" example="1">%1$d</xliff:g>x<xliff:g name="num_rows" example="1">%2$d</xliff:g></string>

    <!--Copntent description for a grid option, describing the number of columns and rows, eg: 4 by 4 [CHAR LIMIT=10] -->
    <string name="grid_content_description"><xliff:g name="num_cols" example="1">%1$d</xliff:g> by <xliff:g name="num_rows" example="1">%2$d</xliff:g></string>

    <!-- Label of what will happen when user tap on apply button to change grid. [CHAR LIMIT=50] -->
    <string name="apply_grid_btn_note">Changing grid size will reload workspace and may take a few seconds.</string>

+14 −14
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import androidx.lifecycle.viewModelScope
import com.android.customization.model.ResourceConstants
import com.android.customization.picker.grid.domain.interactor.GridInteractor
import com.android.customization.picker.grid.shared.model.GridOptionItemsModel
import com.android.themepicker.R
import com.android.wallpaper.picker.common.text.ui.viewmodel.Text
import com.android.wallpaper.picker.option.ui.viewmodel.OptionItemViewModel
import kotlinx.coroutines.flow.Flow
@@ -34,10 +35,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch

class GridScreenViewModel(
    context: Context,
    private val interactor: GridInteractor,
) : ViewModel() {
class GridScreenViewModel(context: Context, private val interactor: GridInteractor) : ViewModel() {

    @SuppressLint("StaticFieldLeak") // We're not leaking this context as it is the app context.
    private val applicationContext = context.applicationContext
@@ -46,7 +44,7 @@ class GridScreenViewModel(
        interactor.options.map { model -> toViewModel(model) }

    private fun toViewModel(
        model: GridOptionItemsModel,
        model: GridOptionItemsModel
    ): List<OptionItemViewModel<GridIconViewModel>> {
        val iconShapePath =
            applicationContext.resources.getString(
@@ -72,6 +70,14 @@ class GridScreenViewModel(
                                path = iconShapePath,
                            ),
                        text = text,
                        contentDescription =
                            Text.Loaded(
                                applicationContext.resources.getString(
                                    R.string.grid_content_description,
                                    option.cols,
                                    option.rows,
                                )
                            ),
                        isSelected = option.isSelected,
                        onClicked =
                            option.isSelected.map { isSelected ->
@@ -87,20 +93,14 @@ class GridScreenViewModel(
        }
    }

    class Factory(
        context: Context,
        private val interactor: GridInteractor,
    ) : ViewModelProvider.Factory {
    class Factory(context: Context, private val interactor: GridInteractor) :
        ViewModelProvider.Factory {

        private val applicationContext = context.applicationContext

        @Suppress("UNCHECKED_CAST")
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            return GridScreenViewModel(
                context = applicationContext,
                interactor = interactor,
            )
                as T
            return GridScreenViewModel(context = applicationContext, interactor = interactor) as T
        }
    }
}