• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.systemui.qs.panels.ui.compose
18 
19 import androidx.compose.runtime.Stable
20 import com.android.compose.animation.Bounceable
21 import com.android.systemui.qs.panels.shared.model.SizedTile
22 import com.android.systemui.qs.panels.ui.viewmodel.BounceableTileViewModel
23 import com.android.systemui.qs.panels.ui.viewmodel.TileViewModel
24 
25 @Stable
26 data class BounceableInfo(
27     val bounceable: BounceableTileViewModel,
28     val previousTile: Bounceable?,
29     val nextTile: Bounceable?,
30     val bounceEnd: Boolean,
31 )
32 
bounceableInfonull33 fun List<BounceableTileViewModel>.bounceableInfo(
34     sizedTile: SizedTile<TileViewModel>,
35     index: Int,
36     column: Int,
37     columns: Int,
38     isFirstInRow: Boolean,
39     isLastInRow: Boolean,
40 ): BounceableInfo {
41     // A tile may be the last in the row without being on the last column
42     val onLastColumn = sizedTile.onLastColumn(column, columns)
43 
44     // Only look for neighbor bounceables if they are on the same row
45     val previousTile = getOrNull(index - 1)?.takeIf { !isFirstInRow }
46     val nextTile = getOrNull(index + 1)?.takeIf { !isLastInRow }
47 
48     return BounceableInfo(this[index], previousTile, nextTile, !onLastColumn)
49 }
50 
onLastColumnnull51 private fun <T> SizedTile<T>.onLastColumn(column: Int, columns: Int): Boolean {
52     return column == columns - width
53 }
54