@@ -35,11 +35,16 @@ import androidx.compose.ui.Modifier
3535import androidx.compose.ui.draw.alpha
3636import androidx.compose.ui.draw.clip
3737import androidx.compose.ui.text.font.FontWeight
38+ import com.rwmobi.kunigami.domain.extensions.roundToTwoDecimalPlaces
39+ import com.rwmobi.kunigami.domain.model.product.ElectricityTariffType
3840import com.rwmobi.kunigami.domain.model.product.Tariff
3941import com.rwmobi.kunigami.ui.composehelper.getScreenSizeInfo
4042import com.rwmobi.kunigami.ui.previewsampledata.TariffSamples
4143import com.rwmobi.kunigami.ui.theme.getDimension
4244import kunigami.composeapp.generated.resources.Res
45+ import kunigami.composeapp.generated.resources.day_unit_rate
46+ import kunigami.composeapp.generated.resources.night_unit_rate
47+ import kunigami.composeapp.generated.resources.off_peak_rate
4348import kunigami.composeapp.generated.resources.standard_unit_rate
4449import kunigami.composeapp.generated.resources.standing_charge
4550import kunigami.composeapp.generated.resources.tariffs_variable
@@ -90,38 +95,11 @@ internal fun TariffSummaryTile(
9095 )
9196 }
9297
93- val resolvedUnitRate = tariff.resolveUnitRate()
94- val rateString = when {
95- tariff.isVariable -> stringResource(resource = Res .string.tariffs_variable)
96- resolvedUnitRate != null -> stringResource(resource = Res .string.unit_p_kwh, resolvedUnitRate)
97- else -> null
98- }
99-
100- if (rateString != null ) {
101- HorizontalDivider (
102- modifier = Modifier
103- .padding(vertical = dimension.grid_1)
104- .alpha(0.5f ),
98+ val shouldShowUnitRate = tariff.containsValidUnitRate()
99+ if (shouldShowUnitRate) {
100+ UnitRateLayout (
101+ tariff = tariff,
105102 )
106-
107- Row (
108- modifier = Modifier .fillMaxWidth(),
109- verticalAlignment = Alignment .CenterVertically ,
110- horizontalArrangement = Arrangement .spacedBy(space = dimension.grid_0_5),
111- ) {
112- Text (
113- modifier = Modifier .weight(weight = 1f ),
114- style = MaterialTheme .typography.bodyMedium,
115- color = MaterialTheme .colorScheme.onSurface,
116- text = stringResource(resource = Res .string.standard_unit_rate),
117- )
118- Text (
119- modifier = Modifier .wrapContentWidth(),
120- style = MaterialTheme .typography.bodyMedium,
121- color = MaterialTheme .colorScheme.onSurface,
122- text = rateString,
123- )
124- }
125103 }
126104
127105 Spacer (modifier = Modifier .weight(1f ))
@@ -135,6 +113,115 @@ internal fun TariffSummaryTile(
135113 }
136114}
137115
116+ @Composable
117+ private fun UnitRateLayout (
118+ modifier : Modifier = Modifier ,
119+ tariff : Tariff ,
120+ ) {
121+ val dimension = getScreenSizeInfo().getDimension()
122+ HorizontalDivider (
123+ modifier = Modifier
124+ .padding(vertical = dimension.grid_1)
125+ .alpha(0.5f ),
126+ )
127+
128+ when (tariff.getElectricityTariffType()) {
129+ ElectricityTariffType .STANDARD -> {
130+ val rateString = when {
131+ tariff.isVariable -> stringResource(resource = Res .string.tariffs_variable)
132+ tariff.vatInclusiveStandardUnitRate != null -> stringResource(resource = Res .string.unit_p_kwh, tariff.vatInclusiveStandardUnitRate)
133+ else -> null
134+ }
135+
136+ rateString?.let {
137+ Row (
138+ modifier = Modifier .fillMaxWidth(),
139+ verticalAlignment = Alignment .CenterVertically ,
140+ horizontalArrangement = Arrangement .spacedBy(space = dimension.grid_0_5),
141+ ) {
142+ Text (
143+ modifier = Modifier .weight(weight = 1f ),
144+ style = MaterialTheme .typography.bodyMedium,
145+ color = MaterialTheme .colorScheme.onSurface,
146+ text = stringResource(resource = Res .string.standard_unit_rate),
147+ )
148+ Text (
149+ modifier = Modifier .wrapContentWidth(),
150+ style = MaterialTheme .typography.bodyMedium,
151+ color = MaterialTheme .colorScheme.onSurface,
152+ text = rateString,
153+ )
154+ }
155+ }
156+ }
157+
158+ else -> {
159+ tariff.vatInclusiveDayUnitRate?.let { rate ->
160+ Row (
161+ modifier = Modifier .fillMaxWidth(),
162+ verticalAlignment = Alignment .CenterVertically ,
163+ horizontalArrangement = Arrangement .spacedBy(space = dimension.grid_0_5),
164+ ) {
165+ Text (
166+ modifier = Modifier .weight(weight = 1f ),
167+ style = MaterialTheme .typography.bodyMedium,
168+ color = MaterialTheme .colorScheme.onSurface,
169+ text = stringResource(resource = Res .string.day_unit_rate),
170+ )
171+ Text (
172+ modifier = Modifier .wrapContentWidth(),
173+ style = MaterialTheme .typography.bodyMedium,
174+ color = MaterialTheme .colorScheme.onSurface,
175+ text = stringResource(resource = Res .string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
176+ )
177+ }
178+ }
179+
180+ tariff.vatInclusiveNightUnitRate?.let { rate ->
181+ Row (
182+ modifier = Modifier .fillMaxWidth(),
183+ verticalAlignment = Alignment .CenterVertically ,
184+ horizontalArrangement = Arrangement .spacedBy(space = dimension.grid_0_5),
185+ ) {
186+ Text (
187+ modifier = Modifier .weight(weight = 1f ),
188+ style = MaterialTheme .typography.bodyMedium,
189+ color = MaterialTheme .colorScheme.onSurface,
190+ text = stringResource(resource = Res .string.night_unit_rate),
191+ )
192+ Text (
193+ modifier = Modifier .wrapContentWidth(),
194+ style = MaterialTheme .typography.bodyMedium,
195+ color = MaterialTheme .colorScheme.onSurface,
196+ text = stringResource(resource = Res .string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
197+ )
198+ }
199+ }
200+
201+ tariff.vatInclusiveOffPeakRate?.let { rate ->
202+ Row (
203+ modifier = Modifier .fillMaxWidth(),
204+ verticalAlignment = Alignment .CenterVertically ,
205+ horizontalArrangement = Arrangement .spacedBy(space = dimension.grid_0_5),
206+ ) {
207+ Text (
208+ modifier = Modifier .weight(weight = 1f ),
209+ style = MaterialTheme .typography.bodyMedium,
210+ color = MaterialTheme .colorScheme.onSurface,
211+ text = stringResource(resource = Res .string.off_peak_rate),
212+ )
213+ Text (
214+ modifier = Modifier .wrapContentWidth(),
215+ style = MaterialTheme .typography.bodyMedium,
216+ color = MaterialTheme .colorScheme.onSurface,
217+ text = stringResource(resource = Res .string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
218+ )
219+ }
220+ }
221+ }
222+ }
223+ }
224+
138225@Preview
139226@Composable
140227private fun Preview () {
0 commit comments