1 /*
2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.customization.tool.domain.menu
18 
19 import androidx.annotation.StringRes
20 import com.android.car.customization.tool.domain.Action
21 
22 /**
23  * Base for all the menu actions.
24  *
25  * Menu Actions are actions that trigger a change in the menu.
26  */
27 internal interface MenuAction : Action
28 
29 /**
30  * This action triggers an update of the whole menu.
31  *
32  * It's used to keep the menu up to date with the system.
33  */
34 object ReloadMenuAction : MenuAction
35 
36 /**
37  * Navigate up the menu tree.
38  */
39 object NavigateUpAction : MenuAction
40 
41 /**
42  * Open a sub menu and navigate down the menu tree.
43  *
44  * @property newParentId the id of the new parent that will be used in [Menu.currentParentNode].
45  */
46 data class OpenSubMenuAction(
47     @StringRes val newParentId: Int,
48 ) : MenuAction
49 
50 /**
51  * A generic action for [MenuItem.Switch] menu elements.
52  */
53 internal interface ToggleMenuAction : MenuAction {
54 
55     @get:StringRes
56     val itemId: Int
57 
58     /**
59      * The new value of a [MenuItem.Switch] after the action is completed.
60      */
61     val newValue: Boolean
62 
63     /**
64      * A helper function to make sure the action can be copied, changing only the [newValue] property.
65      */
clonenull66     fun clone(newValue: Boolean): ToggleMenuAction
67 }
68