@@ -10,23 +10,18 @@ import androidx.compose.runtime.Composable
10
10
import androidx.compose.ui.Alignment
11
11
import androidx.compose.ui.Modifier
12
12
import androidx.compose.ui.geometry.Size
13
+ import androidx.compose.ui.graphics.Color
13
14
import androidx.compose.ui.res.stringResource
14
15
import androidx.compose.ui.text.TextStyle
15
16
import androidx.compose.ui.text.font.FontStyle
16
17
import androidx.compose.ui.text.font.FontWeight
17
18
import androidx.compose.ui.text.style.TextOverflow
18
- import androidx.compose.ui.tooling.preview.Preview
19
19
import androidx.compose.ui.unit.dp
20
20
import androidx.compose.ui.unit.sp
21
- import androidx.constraintlayout.compose.ConstrainedLayoutReference
22
- import androidx.constraintlayout.compose.ConstraintLayout
23
- import androidx.constraintlayout.compose.ConstraintLayoutScope
24
- import androidx.constraintlayout.compose.Dimension
25
21
import coil.compose.ImagePainter
26
22
import coil.compose.rememberImagePainter
27
23
import com.funkymuse.aurora.generalbook.GeneralBook
28
24
import com.funkymuse.aurora.loadingcomponent.BoxShimmer
29
- import com.funkymuse.aurora.loadingcomponent.CardShimmer
30
25
import com.funkymuse.aurora.serverconstants.LIBGEN_BASE_URL
31
26
import com.funkymuse.style.color.CardBackground
32
27
import com.funkymuse.style.shape.Shapes
@@ -51,79 +46,104 @@ fun Book(
51
46
.wrapContentHeight(),
52
47
backgroundColor = CardBackground
53
48
) {
54
- ConstraintLayout (
49
+ Box (
55
50
modifier = Modifier
56
51
.combinedClickable(onLongClick = onLongClick, onClick = onClick)
57
52
) {
58
- val image = image(book.image)
59
- val title = addTitle(image, book.title)
60
- addAuthor(title, image, book.author)
53
+ Row {
54
+ Box (
55
+ modifier = Modifier
56
+ .weight(0.3f )
57
+ .padding(16 .dp)
58
+ ) {
59
+ AddStaticImage (remoteImage = book.image)
60
+ }
61
+ Box (
62
+ modifier = Modifier
63
+ .weight(0.7f )
64
+ .padding(8 .dp)
65
+ ) {
66
+ Column {
67
+ AddTitle (titleText = book.title)
68
+ AddAuthor (authorText = book.author)
69
+ AddYear (year = book.year)
70
+ AddFormatPagesAndSize (book.extension, book.pages, book.size)
71
+ }
72
+ }
73
+ }
61
74
}
62
75
}
63
76
}
64
77
65
78
@Composable
66
- private fun ConstraintLayoutScope.addAuthor (
67
- title : ConstrainedLayoutReference ,
68
- image : ConstrainedLayoutReference ,
79
+ fun AddFormatPagesAndSize (extension : String? , pages : String? , size : String? ) {
80
+ val pagesText =
81
+ if (pages.isNullOrBlank()) " " else " ($pages ${stringResource(id = R .string.pages)} )"
82
+ val extensionText = if (extension.isNullOrBlank()) " " else extension
83
+ val sizeText = if (size.isNullOrBlank()) " " else size
84
+
85
+ val text = when {
86
+ pages.isNullOrBlank() -> " $extensionText , $sizeText "
87
+ extension.isNullOrBlank() -> " $pagesText , $sizeText "
88
+ size.isNullOrBlank() -> " $extensionText $pagesText "
89
+ else -> " $extensionText $pagesText , $sizeText "
90
+ }
91
+
92
+ if (pages.isNullOrBlank() && extension.isNullOrBlank() && size.isNullOrBlank()) {
93
+ return
94
+ }
95
+
96
+ Text (
97
+ text = text,
98
+ color = Color .DarkGray ,
99
+ style = TextStyle (fontWeight = FontWeight .Light , fontSize = 17 .sp),
100
+ modifier = Modifier .padding(bottom = 8 .dp),
101
+ )
102
+ }
103
+
104
+ @Composable
105
+ private fun AddYear (year : String? ) {
106
+ year ? : return
107
+ Text (
108
+ text = year,
109
+ color = Color .DarkGray ,
110
+ style = TextStyle (fontWeight = FontWeight .Light , fontSize = 17 .sp)
111
+ )
112
+ }
113
+
114
+ @Composable
115
+ private fun AddAuthor (
69
116
authorText : String?
70
- ): ConstrainedLayoutReference {
71
- val author = createRef()
117
+ ) {
72
118
Text (
73
119
text = authorText ? : stringResource(id = R .string.not_available),
74
- modifier = Modifier
75
- .constrainAs(author) {
76
- start.linkTo(image.end, 16 .dp)
77
- top.linkTo(title.bottom, 8 .dp)
78
- end.linkTo(parent.end, 16 .dp)
79
- width = Dimension .fillToConstraints
80
- },
81
- style = TextStyle (fontStyle = FontStyle .Italic , fontSize = 16 .sp),
82
- maxLines = 1 ,
83
- overflow = TextOverflow .Ellipsis ,
84
- )
85
- return author
120
+ modifier = Modifier .padding(end = 8 .dp),
121
+ fontStyle = FontStyle .Italic
122
+ )
86
123
}
87
124
88
125
@Composable
89
- private fun ConstraintLayoutScope.addTitle (
90
- image : ConstrainedLayoutReference ,
126
+ private fun AddTitle (
91
127
titleText : String?
92
- ): ConstrainedLayoutReference {
93
- val title = createRef()
128
+ ) {
94
129
Text (
130
+ modifier = Modifier .padding(end = 8 .dp),
95
131
text = titleText ? : stringResource(id = R .string.not_available),
96
- modifier = Modifier
97
- .constrainAs(title) {
98
- start.linkTo(image.end, 16 .dp)
99
- top.linkTo(parent.top, 10 .dp)
100
- end.linkTo(parent.end, 16 .dp)
101
- width = Dimension .fillToConstraints
102
- },
103
132
overflow = TextOverflow .Ellipsis ,
104
- maxLines = 2 ,
133
+ maxLines = 3 ,
105
134
style = TextStyle (fontWeight = FontWeight .SemiBold , fontSize = 17 .sp)
106
135
)
107
- return title
108
136
}
109
137
110
138
@Composable
111
- private fun ConstraintLayoutScope.image (remoteImage : String? ): ConstrainedLayoutReference {
112
-
139
+ private fun AddStaticImage (remoteImage : String? ) {
113
140
val imageUrl = LIBGEN_BASE_URL + remoteImage
114
141
val painter = rememberImagePainter(data = imageUrl)
115
142
116
- val image = createRef()
117
-
118
143
val size = Size (85 .dp.value, 130 .dp.value)
119
144
120
145
val imageModifier = Modifier
121
146
.size(size.width.dp, size.height.dp)
122
- .constrainAs(image) {
123
- top.linkTo(parent.top)
124
- start.linkTo(parent.start)
125
- bottom.linkTo(parent.bottom)
126
- }
127
147
128
148
when (painter.state) {
129
149
is ImagePainter .State .Loading -> {
@@ -132,22 +152,12 @@ private fun ConstraintLayoutScope.image(remoteImage: String?): ConstrainedLayout
132
152
}
133
153
}
134
154
is ImagePainter .State .Success , is ImagePainter .State .Error , ImagePainter .State .Empty -> {
135
- Box (modifier = imageModifier, contentAlignment = Alignment .CenterStart ) {
155
+ Box (modifier = imageModifier, contentAlignment = Alignment .Center ) {
136
156
Image (
137
157
painter = painter,
138
158
contentDescription = stringResource(id = R .string.book_details)
139
159
)
140
160
}
141
161
}
142
162
}
143
-
144
- return image
145
- }
146
-
147
- @Preview
148
- @Composable
149
- fun BookPreview (){
150
- Book (book = com.funkymuse.aurora.bookmodel.Book (" /covers/23000/897294668dce7c4cc065e7d7d96a4923-d.jpg" ,
151
- title = " Communicating Design: Developing Web Site Documentation for Design and Planning" ,
152
- author = " Dan M. Brown" , " 897294668DCE7C4CC065E7D7D96A4923" ))
153
163
}
0 commit comments