Skip to content

Commit 4c5a4fd

Browse files
Merge pull request #110 from Rome-Squad/fix/category-icon
change category icon to match size correctly
2 parents 8e64e4f + 39a910d commit 4c5a4fd

File tree

3 files changed

+44
-36
lines changed

3 files changed

+44
-36
lines changed

app/src/main/java/com/giraffe/tudeeapp/design_system/component/CategoryItem.kt

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,35 @@ import androidx.compose.foundation.layout.Box
77
import androidx.compose.foundation.layout.Column
88
import androidx.compose.foundation.layout.padding
99
import androidx.compose.foundation.layout.size
10+
import androidx.compose.foundation.shape.CircleShape
1011
import androidx.compose.foundation.shape.RoundedCornerShape
12+
import androidx.compose.foundation.verticalScroll
1113
import androidx.compose.material3.Text
1214
import androidx.compose.runtime.Composable
1315
import androidx.compose.ui.Alignment
1416
import androidx.compose.ui.Modifier
1517
import androidx.compose.ui.draw.clip
1618
import androidx.compose.ui.graphics.painter.Painter
19+
import androidx.compose.ui.layout.ContentScale
20+
import androidx.compose.ui.platform.LocalContext
1721
import androidx.compose.ui.res.painterResource
1822
import androidx.compose.ui.res.stringResource
1923
import androidx.compose.ui.text.style.TextOverflow
2024
import androidx.compose.ui.tooling.preview.Preview
2125
import androidx.compose.ui.unit.dp
26+
import coil3.compose.rememberAsyncImagePainter
27+
import coil3.request.ImageRequest
2228
import com.giraffe.tudeeapp.R
2329
import com.giraffe.tudeeapp.design_system.color.LocalTudeeColors
2430
import com.giraffe.tudeeapp.design_system.theme.Theme
31+
import com.giraffe.tudeeapp.domain.entity.Category
2532

2633
@Composable
2734
fun CategoryItem(
28-
icon: Painter,
29-
categoryName: String,
3035
modifier: Modifier = Modifier,
31-
count: Int = 0,
3236
isShowCount: Boolean = true,
3337
isSelected: Boolean = false,
38+
category: Category,
3439
onClick: () -> Unit = {}
3540
) {
3641

@@ -46,13 +51,35 @@ fun CategoryItem(
4651
.clickable(onClick = onClick),
4752
contentAlignment = Alignment.Center
4853
) {
49-
Image(
50-
painter = icon,
51-
contentDescription = stringResource(R.string.category_icon),
52-
modifier = Modifier
53-
.padding(23.dp)
54-
.size(32.dp),
55-
)
54+
if (category.isEditable) {
55+
Image(
56+
painter = rememberAsyncImagePainter(
57+
ImageRequest
58+
.Builder(LocalContext.current)
59+
.data(data = category.imageUri)
60+
.build()
61+
),
62+
contentDescription = stringResource(R.string.category_icon),
63+
contentScale = ContentScale.FillBounds,
64+
modifier = Modifier
65+
.padding(23.dp)
66+
.size(32.dp)
67+
.clip(CircleShape)
68+
)
69+
}else{
70+
Image(
71+
painter = rememberAsyncImagePainter(
72+
ImageRequest
73+
.Builder(LocalContext.current)
74+
.data(data = category.imageUri)
75+
.build()
76+
),
77+
contentDescription = stringResource(R.string.category_icon),
78+
modifier = Modifier
79+
.padding(23.dp)
80+
.size(32.dp)
81+
)
82+
}
5683
}
5784
if (isSelected) {
5885
Box(
@@ -78,7 +105,7 @@ fun CategoryItem(
78105
.align(Alignment.TopEnd),
79106
) {
80107
Text(
81-
text = count.toString(),
108+
text = category.taskCount.toString(),
82109
style = Theme.textStyle.label.small,
83110
color = LocalTudeeColors.current.hint,
84111
modifier = Modifier.align(Alignment.Center)
@@ -88,7 +115,7 @@ fun CategoryItem(
88115
}
89116

90117
Text(
91-
text = categoryName,
118+
text = category.name,
92119
style = Theme.textStyle.label.small,
93120
color = LocalTudeeColors.current.body,
94121
maxLines = 1,
@@ -101,19 +128,11 @@ fun CategoryItem(
101128
@Preview(showBackground = true)
102129
@Composable
103130
fun CategoryItemWithCountPreview() {
104-
CategoryItem(
105-
icon = painterResource(R.drawable.user_multiple),
106-
categoryName = "Education",
107-
count = 16
108-
)
131+
109132
}
110133

111134
@Preview(showBackground = true)
112135
@Composable
113136
fun CategoryItemWithSelectedPreview() {
114-
CategoryItem(
115-
icon = painterResource(R.drawable.user_multiple),
116-
categoryName = "Education",
117-
isSelected = true
118-
)
137+
119138
}

app/src/main/java/com/giraffe/tudeeapp/presentation/screen/categories/CategoriesScreen.kt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,7 @@ fun CategoriesContent(
107107
) {
108108
items(state.categories.size) { index ->
109109
CategoryItem(
110-
icon = rememberAsyncImagePainter(
111-
ImageRequest
112-
.Builder(LocalContext.current)
113-
.data(data = state.categories[index].imageUri)
114-
.build()
115-
),
116-
categoryName = state.categories[index].name,
117-
count = state.categories[index].taskCount,
110+
category= state.categories[index],
118111
onClick = {
119112
actions.selectCategory(state.categories[index].id)
120113
}

app/src/main/java/com/giraffe/tudeeapp/presentation/screen/taskeditor/TaskEditorBottomSheet.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -253,16 +253,12 @@ private fun TaskEditorBottomSheetContent(
253253
verticalArrangement = Arrangement.spacedBy(24.dp),
254254
) {
255255
items(taskEditorState.categories) { category ->
256-
val painter = rememberAsyncImagePainter(model = category.imageUri)
257-
258256
CategoryItem(
259-
icon = painter,
260-
categoryName = category.name,
261257
isSelected = task.category.id == category.id,
262-
count = 0,
263258
isShowCount = false,
264259
onClick = { actions.onChangeTaskCategoryValue(category.id) },
265-
modifier = Modifier.fillMaxWidth()
260+
modifier = Modifier.fillMaxWidth(),
261+
category = category
266262
)
267263
}
268264
}

0 commit comments

Comments
 (0)