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 package com.android.intentresolver.contentpreview.payloadtoggle.ui.composable
17
18 import androidx.compose.foundation.background
19 import androidx.compose.foundation.border
20 import androidx.compose.foundation.layout.Box
21 import androidx.compose.foundation.layout.padding
22 import androidx.compose.foundation.layout.size
23 import androidx.compose.foundation.shape.CircleShape
24 import androidx.compose.material3.Icon
25 import androidx.compose.material3.MaterialTheme
26 import androidx.compose.runtime.Composable
27 import androidx.compose.ui.Alignment
28 import androidx.compose.ui.Modifier
29 import androidx.compose.ui.draw.clip
30 import androidx.compose.ui.draw.drawBehind
31 import androidx.compose.ui.draw.shadow
32 import androidx.compose.ui.graphics.Color
33 import androidx.compose.ui.res.painterResource
34 import androidx.compose.ui.unit.dp
35 import com.android.intentresolver.R
36 import com.android.intentresolver.contentpreview.payloadtoggle.shared.ContentType
37
38 @Composable
ShareouselCardnull39 fun ShareouselCard(
40 image: @Composable () -> Unit,
41 contentType: ContentType,
42 selected: Boolean,
43 modifier: Modifier = Modifier,
44 ) {
45 Box(modifier) {
46 image()
47 val topButtonPadding = 12.dp
48 Box(modifier = Modifier.padding(topButtonPadding).matchParentSize()) {
49 SelectionIcon(selected, modifier = Modifier.align(Alignment.TopStart))
50 when (contentType) {
51 ContentType.Video ->
52 TypeIcon(
53 R.drawable.ic_play_circle_filled_24px,
54 modifier = Modifier.align(Alignment.TopEnd)
55 )
56 ContentType.Other ->
57 TypeIcon(
58 R.drawable.chooser_file_generic,
59 modifier = Modifier.align(Alignment.TopEnd)
60 )
61 ContentType.Image -> Unit // No additional icon needed.
62 }
63 }
64 }
65 }
66
67 @Composable
TypeIconnull68 private fun TypeIcon(drawableResource: Int, modifier: Modifier = Modifier) {
69 Icon(
70 painterResource(id = drawableResource),
71 contentDescription = null, // Type attribute described at a higher level.
72 tint = Color.White,
73 modifier = Modifier.size(20.dp).then(modifier)
74 )
75 }
76
77 @Composable
SelectionIconnull78 private fun SelectionIcon(selected: Boolean, modifier: Modifier = Modifier) {
79 if (selected) {
80 val bgColor = MaterialTheme.colorScheme.primary
81 Icon(
82 painter = painterResource(id = R.drawable.checkbox),
83 tint = MaterialTheme.colorScheme.onPrimary,
84 contentDescription = null,
85 modifier =
86 Modifier.shadow(
87 elevation = 50.dp,
88 spotColor = Color(0x40000000),
89 ambientColor = Color(0x40000000)
90 )
91 .size(20.dp)
92 .drawBehind {
93 drawCircle(color = bgColor, radius = (this.size.width / 2f) - 1f)
94 }
95 .then(modifier)
96 )
97 } else {
98 Box(
99 modifier =
100 Modifier.shadow(
101 elevation = 50.dp,
102 spotColor = Color(0x40000000),
103 ambientColor = Color(0x40000000),
104 )
105 .border(
106 width = 2.dp,
107 color = MaterialTheme.colorScheme.onPrimary,
108 shape = CircleShape
109 )
110 .clip(CircleShape)
111 .size(20.dp)
112 .background(color = MaterialTheme.colorScheme.onPrimary.copy(alpha = 0.5f))
113 .then(modifier)
114 )
115 }
116 }
117