1 /*
2  * Copyright 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 androidx.compose.material3.adaptive.layout
18 
19 import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
20 
21 /**
22  * The adaptation specs of [ThreePaneScaffold]. This class denotes how each pane of
23  * [ThreePaneScaffold] should be adapted. It should be used as an input parameter of
24  * [calculateThreePaneScaffoldValue] to decide the [ThreePaneScaffoldValue].
25  *
26  * @param primaryPaneAdaptStrategy [AdaptStrategy] of the primary pane of [ThreePaneScaffold]
27  * @param secondaryPaneAdaptStrategy [AdaptStrategy] of the secondary pane of [ThreePaneScaffold]
28  * @param tertiaryPaneAdaptStrategy [AdaptStrategy] of the tertiary pane of [ThreePaneScaffold]
29  * @constructor create an instance of [ThreePaneScaffoldAdaptStrategies]
30  */
31 @ExperimentalMaterial3AdaptiveApi
32 class ThreePaneScaffoldAdaptStrategies(
33     private val primaryPaneAdaptStrategy: AdaptStrategy,
34     private val secondaryPaneAdaptStrategy: AdaptStrategy,
35     private val tertiaryPaneAdaptStrategy: AdaptStrategy
36 ) {
getnull37     operator fun get(role: ThreePaneScaffoldRole): AdaptStrategy {
38         return when (role) {
39             ThreePaneScaffoldRole.Primary -> primaryPaneAdaptStrategy
40             ThreePaneScaffoldRole.Secondary -> secondaryPaneAdaptStrategy
41             ThreePaneScaffoldRole.Tertiary -> tertiaryPaneAdaptStrategy
42         }
43     }
44 
equalsnull45     override fun equals(other: Any?): Boolean {
46         if (this === other) return true
47         if (other !is ThreePaneScaffoldAdaptStrategies) return false
48         if (primaryPaneAdaptStrategy != other.primaryPaneAdaptStrategy) return false
49         if (secondaryPaneAdaptStrategy != other.secondaryPaneAdaptStrategy) return false
50         if (tertiaryPaneAdaptStrategy != other.tertiaryPaneAdaptStrategy) return false
51         return true
52     }
53 
hashCodenull54     override fun hashCode(): Int {
55         var result = primaryPaneAdaptStrategy.hashCode()
56         result = 31 * result + secondaryPaneAdaptStrategy.hashCode()
57         result = 31 * result + tertiaryPaneAdaptStrategy.hashCode()
58         return result
59     }
60 }
61