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

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

Merge "Fix shape update unexpected (1/2)" into main

parents d42c56a0 4888b97c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ constructor(

    override fun applyGridOption(gridKey: String) {
        context.contentResolver.update(
            previewUtils.getUri(SHAPE_GRID),
            previewUtils.getUri(SET_GRID),
            ContentValues().apply { put(COL_GRID_KEY, gridKey) },
            null,
            null,
@@ -189,7 +189,7 @@ constructor(
        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"
        const val SET_GRID: String = "default_grid"
        const val SET_SHAPE: String = "shape"
        const val COL_SHAPE_KEY: String = "shape_key"
        const val COL_GRID_KEY: String = "name"
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ constructor(
    val isGridCustomizationAvailable =
        gridOptions.filterNotNull().map { it.size > 1 }.distinctUntilChanged()

    suspend fun applySelectedOption(gridKey: String) =
    suspend fun applyGridOption(gridKey: String) =
        withContext(bgDispatcher) {
            manager.applyGridOption(gridKey)
            // After applying, we should query and update shape and grid options again.
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class GridInteractor2 @Inject constructor(private val repository: GridRepository

    val selectedGridOption = repository.selectedGridOption

    suspend fun applySelectedOption(gridKey: String) = repository.applySelectedOption(gridKey)
    suspend fun applyGridOption(gridKey: String) = repository.applyGridOption(gridKey)

    fun getGridOptionDrawable(iconId: Int): Drawable? = repository.getGridOptionDrawable(iconId)
}
+5 −8
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ constructor(
                ->
                overridingGridOptionKey ?: selectedGridOption.key.value
            }
            .shareIn(scope = viewModelScope, started = SharingStarted.Lazily, replay = 1)

    val gridOptions: Flow<List<OptionItemViewModel2<Drawable>>> =
        interactor.gridOptions
@@ -72,11 +73,7 @@ constructor(
    val onApply: Flow<(suspend () -> Unit)?> =
        combine(overridingGridKey, selectedGridOption) { overridingGridKey, selectedGridOption ->
            if (overridingGridKey != null && overridingGridKey != selectedGridOption.key.value) {
                {
                    interactor.applySelectedOption(
                        overridingGridKey ?: selectedGridOption.key.value
                    )
                }
                { interactor.applyGridOption(overridingGridKey) }
            } else {
                null
            }
+2 −2
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ class GridRepository2Test {
                )
            val gridOptions = collectLastValue(underTest.gridOptions)

            underTest.applySelectedOption("practical")
            underTest.applyGridOption("practical")

            assertThat(gridOptions())
                .isEqualTo(
@@ -123,7 +123,7 @@ class GridRepository2Test {
                )
            val selectedGridOption = collectLastValue(underTest.selectedGridOption)

            underTest.applySelectedOption("practical")
            underTest.applyGridOption("practical")

            assertThat(selectedGridOption())
                .isEqualTo(FakeShapeGridManager.DEFAULT_GRID_OPTION_LIST[1].copy(isCurrent = true))
Loading