Skip to content

Commit

Permalink
refactor(style-partners): migrate JobItem to tokenized based component.
Browse files Browse the repository at this point in the history
  • Loading branch information
GerardPaligot committed Nov 12, 2023
1 parent 4b203bb commit 37b1dc4
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.style.cards.AddressCard
import org.gdglille.devfest.android.theme.m3.partners.ui.jobs.JobItem
import org.gdglille.devfest.android.theme.m3.partners.ui.partners.PartnerDetailSectionVertical
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.android.theme.m3.style.partners.jobs.JobItem
import org.gdglille.devfest.android.theme.m3.style.placeholder
import org.gdglille.devfest.models.ui.PartnerItemUi

@Composable
Expand Down Expand Up @@ -62,10 +63,15 @@ fun PartnerDetailVerticalScreen(
}
items(partnerItemUi.jobs) {
JobItem(
jobUi = it,
isLoading = isLoading,
onClick = onLinkClicked,
modifier = Modifier.fillMaxWidth()
title = it.title,
description = "${it.companyName} - ${it.location}",
requirements = it.requirements,
propulsedBy = it.propulsed,
salaryMin = it.salary?.min,
salaryMax = it.salary?.max,
salaryRecurrence = it.salary?.recurrence,
onClick = { onLinkClicked(it.url) },
modifier = Modifier.fillMaxWidth().placeholder(visible = isLoading)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.partners.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.partners.items.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.placeholder

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.partners.ui.partners.PartnerDivider
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.partners.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.partners.items.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.placeholder
import org.gdglille.devfest.models.ui.PartnerGroupsUi

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
package org.gdglille.devfest.android.theme.m3.partners.ui.partners

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.markdowns.MarkdownText
import org.gdglille.devfest.android.theme.m3.style.partners.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.partners.items.PartnerItem
import org.gdglille.devfest.android.theme.m3.style.placeholder
import org.gdglille.devfest.android.theme.m3.style.previews.ThemedPreviews
import org.gdglille.devfest.android.theme.m3.style.socials.SocialsSection
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gdglille.devfest.android.theme.m3.style.partners
package org.gdglille.devfest.android.theme.m3.style.partners.items

import androidx.compose.foundation.Image
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gdglille.devfest.android.theme.m3.style.partners
package org.gdglille.devfest.android.theme.m3.style.partners.items

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.gdglille.devfest.android.theme.m3.style.partners
package org.gdglille.devfest.android.theme.m3.style.partners.items

import org.gdglille.devfest.android.theme.m3.style.ColorSchemeTokens
import org.gdglille.devfest.android.theme.m3.style.ShapeTokens
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package org.gdglille.devfest.android.theme.m3.style.partners.jobs

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Payments
import androidx.compose.material.icons.outlined.Work
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import org.gdglille.devfest.android.theme.m3.style.Conferences4HallTheme
import org.gdglille.devfest.android.theme.m3.style.R
import org.gdglille.devfest.android.theme.m3.style.previews.ThemedPreviews
import org.gdglille.devfest.android.theme.m3.style.tags.MediumTag
import org.gdglille.devfest.android.theme.m3.style.tags.TagDefaults
import org.gdglille.devfest.android.theme.m3.style.toDp

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun JobItem(
title: String,
description: String,
requirements: Int,
propulsedBy: String,
salaryMin: Int?,
salaryMax: Int?,
salaryRecurrence: String?,
onClick: () -> Unit,
modifier: Modifier = Modifier,
containerColor: Color = JobItemDefaults.containerColor,
shape: Shape = JobItemDefaults.shape,
titleTextStyle: TextStyle = JobItemDefaults.titleTextStyle,
descriptionTextStyle: TextStyle = JobItemDefaults.descriptionTextStyle
) {
Card(
shape = shape,
colors = CardDefaults.cardColors(containerColor = containerColor),
modifier = modifier,
onClick = onClick
) {
Column(modifier = Modifier.padding(JobItemTokens.ContainerPadding.toDp())) {
Text(
text = title,
style = titleTextStyle,
modifier = Modifier.padding(start = JobItemTokens.ContentStartPadding.toDp())
)
Text(
text = description,
style = descriptionTextStyle,
modifier = Modifier.padding(start = JobItemTokens.ContentStartPadding.toDp())
)
Row(
modifier = Modifier.padding(top = JobItemTokens.TagTopPadding.toDp())
) {
if (salaryMin != null && salaryMax != null && salaryRecurrence != null) {
MediumTag(
text = stringResource(
id = R.string.text_job_salary,
salaryMin,
salaryMax,
salaryRecurrence
),
icon = Icons.Outlined.Payments,
colors = TagDefaults.unStyledColors()
)
}
MediumTag(
text = pluralStringResource(
id = R.plurals.text_job_requirements,
count = requirements,
requirements
),
icon = Icons.Outlined.Work,
colors = TagDefaults.unStyledColors()
)
}
MediumTag(
text = stringResource(id = R.string.text_job_propulsed, propulsedBy),
colors = TagDefaults.gravelColors(),
modifier = Modifier.padding(
top = JobItemTokens.TagTopPadding.toDp(),
start = JobItemTokens.ContentStartPadding.toDp()
)
)
}
}
}

@Suppress("UnusedPrivateMember")
@ThemedPreviews
@Composable
private fun JobItemPreview() {
Conferences4HallTheme {
JobItem(
title = "Mobile Staff Engineer",
description = "Google - Paris, France",
requirements = 5,
propulsedBy = "WeLoveDevs",
salaryMin = 55,
salaryMax = 75,
salaryRecurrence = "year",
onClick = {},
modifier = Modifier.fillMaxWidth()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.gdglille.devfest.android.theme.m3.style.partners.jobs

import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.text.TextStyle
import org.gdglille.devfest.android.theme.m3.style.toColor
import org.gdglille.devfest.android.theme.m3.style.toShape
import org.gdglille.devfest.android.theme.m3.style.toTextStyle

object JobItemDefaults {
val containerColor: Color
@Composable
get() = JobItemTokens.ContainerColor.toColor()
val shape: Shape
@Composable
get() = JobItemTokens.ContainerShape.toShape()
val titleTextStyle: TextStyle
@Composable
get() = JobItemTokens.TitleTextStyle.toTextStyle()
val descriptionTextStyle: TextStyle
@Composable
get() = JobItemTokens.DescriptionTextStyle.toTextStyle()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.gdglille.devfest.android.theme.m3.style.partners.jobs

import org.gdglille.devfest.android.theme.m3.style.ColorSchemeTokens
import org.gdglille.devfest.android.theme.m3.style.ShapeTokens
import org.gdglille.devfest.android.theme.m3.style.SpacingTokens
import org.gdglille.devfest.android.theme.m3.style.TextStyleTokens

object JobItemTokens {
val ContainerColor = ColorSchemeTokens.SurfaceVariantColor
val ContainerShape = ShapeTokens.MediumShape
val ContainerPadding = SpacingTokens.MediumSpacing
val TitleTextStyle = TextStyleTokens.TitleMedium
val DescriptionTextStyle = TextStyleTokens.BodyMedium
val ContentStartPadding = SpacingTokens.MediumSpacing
val TagTopPadding = SpacingTokens.SmallSpacing
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum class ColorSchemeTokens {
SecondaryColor,
SurfaceColor,
OnSurfaceColor,
SurfaceVariantColor,
OnSurfaceVariant,
OnBackgroundColor,
WhiteBackgroundColor
Expand All @@ -22,6 +23,7 @@ internal fun ColorScheme.fromToken(value: ColorSchemeTokens): Color {
ColorSchemeTokens.SecondaryColor -> secondary
ColorSchemeTokens.SurfaceColor -> surface
ColorSchemeTokens.OnSurfaceColor -> onSurface
ColorSchemeTokens.SurfaceVariantColor -> surfaceVariant
ColorSchemeTokens.OnSurfaceVariant -> onSurfaceVariant
ColorSchemeTokens.OnBackgroundColor -> onBackground
ColorSchemeTokens.WhiteBackgroundColor -> Color.White
Expand Down

0 comments on commit 37b1dc4

Please sign in to comment.