Skip to content

Instantly share code, notes, and snippets.

@Pouyaa91
Pouyaa91 / InstructionsView.kt
Created October 20, 2023 00:49
InstructionsView
@Composable
private fun InstructionsView(modifier: Modifier = Modifier, instructions: String) {
ExpandableSection(modifier = modifier, title = stringResource(id = R.string.how_to_prepare)) {
Text(
modifier = Modifier.padding(8.dp),
text = instructions,
color = MaterialTheme.colorScheme.onSecondaryContainer
)
}
}
@Pouyaa91
Pouyaa91 / ExpandableSection.kt
Created October 20, 2023 00:22
ExpandableSection
@Composable
fun ExpandableSection(
modifier: Modifier = Modifier,
title: String,
content: @Composable () -> Unit
) {
var isExpanded by rememberSaveable { mutableStateOf(false) }
Column(
modifier = modifier
.clickable { isExpanded = !isExpanded }
@Pouyaa91
Pouyaa91 / ExpandableSectionTitle.kt
Created October 20, 2023 00:07
ExpandableSectionTitle
@Composable
fun ExpandableSectionTitle(modifier: Modifier = Modifier, isExpanded: Boolean, title: String) {
val icon = if (isExpanded) Icons.Rounded.KeyboardArrowUp else Icons.Rounded.KeyboardArrowDown
Row(modifier = modifier.padding(8.dp), verticalAlignment = Alignment.CenterVertically) {
Image(
modifier = Modifier.size(32.dp),
imageVector = icon,
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onPrimaryContainer),
@Composable
private fun CategoryImageView(
modifier: Modifier = Modifier,
categoryName: String,
imageUrl: String
) {
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(LocalContext.current)
.data(imageUrl)
.crossfade(200)
@Composable
fun ShimmerEffectBrush(): ShaderBrush {
val infiniteTransition = rememberInfiniteTransition(label = "shimmer transition")
val offset by infiniteTransition.animateFloat(
initialValue = 0f,
targetValue = 1f,
animationSpec = infiniteRepeatable(
animation = tween(durationMillis = 1_000),
),
@Serializable
data class NetworkCategoriesWrapper(
@SerialName(value = "categories") val categories: List<NetworkCategory>
)
class CategoriesApiServiceTest {
private lateinit var apiService: CategoriesApiService
private lateinit var mockWebServer: MockWebServer
private val json = Json { ignoreUnknownKeys = true }
@Before
fun setup() {
mockWebServer = MockWebServer().apply(MockWebServer::start)
interface CategoriesApiService {
@GET("categories.php")
suspend fun getCategories(): NetworkCategoriesWrapper
}
{
"categories": [
{
"idCategory": "1",
"strCategory": "first category",
"strCategoryThumb": "first thumb",
"strCategoryDescription": "first description"
},
{
"idCategory": "2",
@Serializable
data class NetworkCategory(
@SerialName(value = "idCategory") val id: String?,
@SerialName(value = "strCategory") val name: String?,
@SerialName(value = "strCategoryThumb") val imageUrl: String?,
@SerialName(value = "strCategoryDescription") val description: String?
)