11package voice.features.bookOverview.views
22
3+ import androidx.compose.foundation.background
34import androidx.compose.foundation.combinedClickable
45import androidx.compose.foundation.layout.Arrangement
6+ import androidx.compose.foundation.layout.Box
57import androidx.compose.foundation.layout.Column
68import androidx.compose.foundation.layout.PaddingValues
9+ import androidx.compose.foundation.layout.Row
710import androidx.compose.foundation.layout.Spacer
811import androidx.compose.foundation.layout.WindowInsets
912import androidx.compose.foundation.layout.aspectRatio
13+ import androidx.compose.foundation.layout.fillMaxSize
1014import androidx.compose.foundation.layout.fillMaxWidth
15+ import androidx.compose.foundation.layout.height
1116import androidx.compose.foundation.layout.padding
1217import androidx.compose.foundation.layout.systemBars
1318import androidx.compose.foundation.layout.windowInsetsBottomHeight
1419import androidx.compose.foundation.lazy.grid.GridCells
1520import androidx.compose.foundation.lazy.grid.GridItemSpan
1621import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
1722import androidx.compose.foundation.lazy.grid.items
18- import androidx.compose.foundation.shape.RoundedCornerShape
19- import androidx.compose.material3.Card
23+ import androidx.compose.material3.ElevatedCard
2024import androidx.compose.material3.LinearProgressIndicator
2125import androidx.compose.material3.MaterialTheme
2226import androidx.compose.material3.Text
2327import androidx.compose.runtime.Composable
28+ import androidx.compose.ui.Alignment
2429import androidx.compose.ui.Modifier
2530import androidx.compose.ui.draw.clip
2631import androidx.compose.ui.layout.ContentScale
2732import androidx.compose.ui.platform.LocalDensity
2833import androidx.compose.ui.platform.LocalResources
2934import androidx.compose.ui.res.painterResource
35+ import androidx.compose.ui.text.style.TextOverflow
36+ import androidx.compose.ui.tooling.preview.Preview
3037import androidx.compose.ui.unit.dp
3138import coil.compose.AsyncImage
3239import kotlinx.collections.immutable.ImmutableMap
@@ -96,45 +103,68 @@ internal fun GridBook(
96103 onBookClick : (BookId ) -> Unit ,
97104 onBookLongClick : (BookId ) -> Unit ,
98105) {
99- Card (
106+ ElevatedCard (
107+ shape = MaterialTheme .shapes.extraLarge,
100108 modifier = Modifier
101109 .fillMaxWidth()
102110 .combinedClickable(
103- onClick = {
104- onBookClick(book.id)
105- },
106- onLongClick = {
107- onBookLongClick(book.id)
108- },
111+ onClick = { onBookClick(book.id) },
112+ onLongClick = { onBookLongClick(book.id) },
109113 ),
110114 ) {
111- Column {
112- AsyncImage (
115+ Column (
116+ modifier = Modifier .padding(start = 12 .dp, end = 12 .dp, top = 12 .dp),
117+ ) {
118+ Box (
113119 modifier = Modifier
114- .aspectRatio(4F / 3F )
115- .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp)
116- .clip(RoundedCornerShape (8 .dp)),
117- contentScale = ContentScale .Crop ,
118- model = book.cover?.file,
119- placeholder = painterResource(id = UiR .drawable.album_art),
120- error = painterResource(id = UiR .drawable.album_art),
121- contentDescription = null ,
122- )
120+ .fillMaxWidth()
121+ .aspectRatio(4f / 3f )
122+ .clip(MaterialTheme .shapes.large)
123+ .background(MaterialTheme .colorScheme.surfaceVariant),
124+ contentAlignment = Alignment .Center ,
125+ ) {
126+ AsyncImage (
127+ modifier = Modifier .fillMaxSize(),
128+ contentScale = ContentScale .Crop ,
129+ model = book.cover?.file,
130+ placeholder = painterResource(id = UiR .drawable.album_art),
131+ error = painterResource(id = UiR .drawable.album_art),
132+ contentDescription = null ,
133+ )
134+ }
135+
136+ Spacer (Modifier .height(4 .dp))
137+
123138 Text (
124- modifier = Modifier .padding(start = 8 .dp, end = 8 .dp, top = 8 .dp),
125139 text = book.name,
140+ style = MaterialTheme .typography.titleMedium,
141+ color = MaterialTheme .colorScheme.onSurface,
126142 maxLines = 3 ,
127- style = MaterialTheme .typography.bodyMedium,
128- )
129- Text (
130- modifier = Modifier .padding(start = 8 .dp, end = 8 .dp, bottom = 8 .dp),
131- text = book.remainingTime,
132- style = MaterialTheme .typography.bodySmall,
143+ overflow = TextOverflow .Ellipsis ,
133144 )
134145
135- if (book.progress > 0F ) {
146+ Row (
147+ modifier = Modifier .fillMaxWidth(),
148+ horizontalArrangement = Arrangement .SpaceBetween ,
149+ verticalAlignment = Alignment .CenterVertically ,
150+ ) {
151+ Text (
152+ text = book.remainingTime,
153+ style = MaterialTheme .typography.labelMedium,
154+ color = MaterialTheme .colorScheme.onSurfaceVariant,
155+ )
156+ if (book.progress > 0f ) {
157+ Text (
158+ text = " ${(book.progress * 100 ).toInt()} %" ,
159+ style = MaterialTheme .typography.labelMedium,
160+ color = MaterialTheme .colorScheme.onSurfaceVariant,
161+ )
162+ }
163+ }
164+
165+ Spacer (Modifier .height(8 .dp))
166+ if (book.progress > 0.05f ) {
136167 LinearProgressIndicator (
137- modifier = Modifier .fillMaxWidth(),
138168 progress = { book.progress },
139169 )
140170 }
@@ -152,3 +182,15 @@ internal fun gridColumnCount(): Int {
152182 val columns = (widthPx / desiredPx).roundToInt()
153183 return columns.coerceAtLeast(2 )
154184}
185+
186+ @Composable
187+ @Preview(widthDp = 200 )
188+ private fun GridBookPreviewWithProgress () {
189+ GridBook (BookOverviewPreviewParameterProvider ().book().copy(progress = 0.66f ), {}, {})
190+ }
191+
192+ @Composable
193+ @Preview(widthDp = 200 )
194+ private fun GridBookPreviewWithoutProgress () {
195+ GridBook (BookOverviewPreviewParameterProvider ().book().copy(progress = 0f ), {}, {})
196+ }
0 commit comments