Refactor RatingWidget to use imageVec
This commit is contained in:
1 parent
974108088a
commit
261ccdda51
1 file changed
+25
-8
@@ -2,20 +2,25 @@ package com.hippo.ehviewer.ui.widget
|
|||||||
|
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.filled.Star
|
||||||
|
import androidx.compose.material.icons.filled.StarHalf
|
||||||
|
import androidx.compose.material.icons.filled.StarOutline
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.res.dimensionResource
|
import androidx.compose.ui.res.dimensionResource
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.unit.Dp
|
||||||
import com.hippo.ehviewer.R
|
import com.hippo.ehviewer.R
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private val colorYellow800 = Color(0xfff9a825)
|
private val colorYellow800 = Color(0xfff9a825)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SimpleRatingWidget(rating: Float) {
|
fun MetaRatingWidget(rating: Float, ratingSize: Dp, ratingInterval: Dp) {
|
||||||
val r = (rating * 2).roundToInt().coerceIn(0, 10)
|
val r = (rating * 2).roundToInt().coerceIn(0, 10)
|
||||||
val fullStar = r / 2
|
val fullStar = r / 2
|
||||||
val halfStar = r % 2
|
val halfStar = r % 2
|
||||||
@@ -23,27 +28,39 @@ fun SimpleRatingWidget(rating: Float) {
|
|||||||
Row {
|
Row {
|
||||||
repeat(fullStar) {
|
repeat(fullStar) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.v_star_x16),
|
imageVector = Icons.Default.Star,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(ratingSize),
|
||||||
tint = colorYellow800
|
tint = colorYellow800
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(dimensionResource(id = R.dimen.rating_interval)))
|
Spacer(modifier = Modifier.width(ratingInterval))
|
||||||
}
|
}
|
||||||
repeat(halfStar) {
|
repeat(halfStar) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.v_star_half_x16),
|
imageVector = Icons.Default.StarHalf,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(ratingSize),
|
||||||
tint = colorYellow800
|
tint = colorYellow800
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(dimensionResource(id = R.dimen.rating_interval)))
|
Spacer(modifier = Modifier.width(ratingInterval))
|
||||||
}
|
}
|
||||||
repeat(outlineStar) {
|
repeat(outlineStar) {
|
||||||
Icon(
|
Icon(
|
||||||
painter = painterResource(id = R.drawable.v_star_outline_x16),
|
imageVector = Icons.Default.StarOutline,
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
|
modifier = Modifier.size(ratingSize),
|
||||||
tint = colorYellow800
|
tint = colorYellow800
|
||||||
)
|
)
|
||||||
Spacer(modifier = Modifier.width(dimensionResource(id = R.dimen.rating_interval)))
|
Spacer(modifier = Modifier.width(ratingInterval))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun SimpleRatingWidget(rating: Float) {
|
||||||
|
MetaRatingWidget(
|
||||||
|
rating = rating,
|
||||||
|
ratingSize = dimensionResource(id = R.dimen.rating_size),
|
||||||
|
ratingInterval = dimensionResource(id = R.dimen.rating_interval)
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in new issue
Block a user