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

Commit 309ce5b0 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Add falsing for edit mode button

Add a viewmodel for the button. Also, the action to start editing is not
needed anymore as part of TileGrid.

Test: manual, enter edit mode
Test: atest EditModeButtonViewModelTest
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Fixes: 379311646
Change-Id: I6e7a1c864ed2eba1202cee0473816d11f4df96a3
parent ba098cee
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -168,7 +168,6 @@ fun SceneScope.QuickSettingsLayout(
                modifier =
                    Modifier.fillMaxWidth()
                        .heightIn(max = QuickSettingsShade.Dimensions.GridMaxHeight),
                viewModel.editModeViewModel::startEditing,
            )
        }
    }
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.panels.ui.viewmodel

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.classifier.fakeFalsingManager
import com.android.systemui.kosmos.collectLastValue
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@SmallTest
class EditModeButtonViewModelTest : SysuiTestCase() {
    val kosmos = testKosmos()

    val underTest = kosmos.editModeButtonViewModelFactory.create()

    @Test
    fun falsingFalseTap_editModeDoesntStart() =
        kosmos.runTest {
            val isEditing by collectLastValue(editModeViewModel.isEditing)

            fakeFalsingManager.setFalseTap(true)

            underTest.onButtonClick()
            runCurrent()

            assertThat(isEditing).isFalse()
        }

    @Test
    fun falsingNotFalseTap_editModeStarted() =
        kosmos.runTest {
            val isEditing by collectLastValue(editModeViewModel.isEditing)

            fakeFalsingManager.setFalseTap(false)

            underTest.onButtonClick()
            runCurrent()

            assertThat(isEditing).isTrue()
        }
}
+8 −6
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.classifier.FalsingCollectorActual
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.plugins.FalsingManager.Penalty
import javax.inject.Inject

/**
@@ -63,12 +64,13 @@ constructor(
     * Inserts the given [result] into the falsing system, affecting future runs of the classifier
     * as if this was a result that had organically happened before.
     */
    fun updateFalseConfidence(
        result: FalsingClassifier.Result,
    ) = collector.updateFalseConfidence(result)
    fun updateFalseConfidence(result: FalsingClassifier.Result) =
        collector.updateFalseConfidence(result)

    /** Returns `true` if the gesture should be rejected. */
    fun isFalseTouch(
        @Classifier.InteractionType interactionType: Int,
    ): Boolean = manager.isFalseTouch(interactionType)
    fun isFalseTouch(@Classifier.InteractionType interactionType: Int): Boolean =
        manager.isFalseTouch(interactionType)

    /** Returns `true` if the tap gesture should be rejected */
    fun isFalseTap(@Penalty penalty: Int): Boolean = manager.isFalseTap(penalty)
}
+0 −1
Original line number Diff line number Diff line
@@ -719,7 +719,6 @@ constructor(
                                                    max =
                                                        QuickSettingsShade.Dimensions.GridMaxHeight
                                                ),
                                        containerViewModel.editModeViewModel::startEditing,
                                    )
                                }
                            }
+61 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.qs.panels.ui.compose

import androidx.compose.foundation.shape.CornerSize
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalContentColor
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.android.systemui.lifecycle.rememberViewModel
import com.android.systemui.qs.panels.ui.viewmodel.EditModeButtonViewModel
import com.android.systemui.qs.ui.compose.borderOnFocus
import com.android.systemui.res.R

@Composable
fun EditModeButton(
    viewModelFactory: EditModeButtonViewModel.Factory,
    modifier: Modifier = Modifier,
) {
    val viewModel = rememberViewModel(traceName = "EditModeButton") { viewModelFactory.create() }
    CompositionLocalProvider(
        value = LocalContentColor provides MaterialTheme.colorScheme.onSurface
    ) {
        IconButton(
            onClick = viewModel::onButtonClick,
            shape = RoundedCornerShape(CornerSize(28.dp)),
            modifier =
                modifier.borderOnFocus(
                    color = MaterialTheme.colorScheme.secondary,
                    cornerSize = CornerSize(24.dp),
                ),
        ) {
            Icon(
                imageVector = Icons.Default.Edit,
                contentDescription = stringResource(id = R.string.qs_edit),
            )
        }
    }
}
Loading