Skip to content

Commit 2a1551f

Browse files
authored
Merge pull request #365 from ryanw-mobile/fix/364-usage-screen-fix-tiles-section
(#364) Usage screen: fix tiles section to support more tariff types
2 parents 3a2d184 + 0ea7db0 commit 2a1551f

File tree

9 files changed

+161
-45
lines changed

9 files changed

+161
-45
lines changed

composeApp/composeApp.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |spec|
22
spec.name = 'composeApp'
3-
spec.version = '2.3.0'
3+
spec.version = '2.3.1'
44
spec.homepage = 'https://github.com/ryanw-mobile/OctoMeter/'
55
spec.source = { :http=> ''}
66
spec.authors = ''
@@ -51,4 +51,4 @@ Pod::Spec.new do |spec|
5151
}
5252
]
5353
spec.resources = ['build/compose/cocoapods/compose-resources']
54-
end
54+
end

composeApp/src/commonMain/graphql/com/rwmobi/kunigami/queries/PropertiesQuery.graphql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ query PropertiesQuery($accountNumber: String!) {
1111
meters {
1212
serialNumber
1313
makeAndType
14+
smartImportElectricityMeter {
15+
deviceId
16+
__typename
17+
}
1418
meterPoint {
1519
meters {
1620
serialNumber

composeApp/src/commonMain/kotlin/com/rwmobi/kunigami/data/repository/mapper/TariffMapper.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ fun SingleEnergyProductQuery.EnergyProduct.toTariff(
2525
tariffCode: String,
2626
): Tariff? {
2727
val tariffNode = tariffs?.edges
28-
?.firstOrNull { it?.node?.onStandardTariff?.tariffCode == tariffCode }
28+
?.firstOrNull {
29+
it?.node?.onStandardTariff?.tariffCode == tariffCode ||
30+
it?.node?.onDayNightTariff?.tariffCode == tariffCode ||
31+
it?.node?.onThreeRateTariff?.tariffCode == tariffCode
32+
}
2933
?.node
3034

3135
if (tariffNode == null) {

composeApp/src/commonMain/kotlin/com/rwmobi/kunigami/domain/model/product/Tariff.kt

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,28 @@ data class Tariff(
8888
}
8989
}
9090

91-
// TODO: WIP - We do not support dual rates and don't know how it works for now
91+
fun containsValidUnitRate(): Boolean {
92+
return when (getElectricityTariffType()) {
93+
ElectricityTariffType.STANDARD -> {
94+
vatInclusiveStandardUnitRate != null || isVariable
95+
}
96+
97+
ElectricityTariffType.DAY_NIGHT -> {
98+
vatInclusiveDayUnitRate != null &&
99+
vatInclusiveNightUnitRate != null
100+
}
101+
102+
ElectricityTariffType.THREE_RATE -> {
103+
vatInclusiveDayUnitRate != null &&
104+
vatInclusiveNightUnitRate != null &&
105+
vatInclusiveOffPeakRate != null
106+
}
107+
108+
else -> false
109+
}
110+
}
111+
112+
// TODO: This function will be removed once we have migrated to get billing data from GraphQL
92113
fun resolveUnitRate(referencePoint: Instant? = null): Double? {
93114
return when (getElectricityTariffType()) {
94115
ElectricityTariffType.STANDARD -> {

composeApp/src/commonMain/kotlin/com/rwmobi/kunigami/ui/components/TariffSummaryTile.kt

Lines changed: 118 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,16 @@ import androidx.compose.ui.Modifier
3535
import androidx.compose.ui.draw.alpha
3636
import androidx.compose.ui.draw.clip
3737
import androidx.compose.ui.text.font.FontWeight
38+
import com.rwmobi.kunigami.domain.extensions.roundToTwoDecimalPlaces
39+
import com.rwmobi.kunigami.domain.model.product.ElectricityTariffType
3840
import com.rwmobi.kunigami.domain.model.product.Tariff
3941
import com.rwmobi.kunigami.ui.composehelper.getScreenSizeInfo
4042
import com.rwmobi.kunigami.ui.previewsampledata.TariffSamples
4143
import com.rwmobi.kunigami.ui.theme.getDimension
4244
import 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
4348
import kunigami.composeapp.generated.resources.standard_unit_rate
4449
import kunigami.composeapp.generated.resources.standing_charge
4550
import 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
140227
private fun Preview() {

gradle/libs.versions.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ apollographqlMockServer = "0.1.0"
4343
testRules = "1.6.1"
4444

4545
# App configurations, not dependencies
46-
versionCode = "14"
47-
versionName = "2.3.0"
46+
versionCode = "15"
47+
versionName = "2.3.1"
4848
android-minSdk = "26"
4949
android-targetSdk = "34"
5050
android-compileSdk = "34"

iosApp/OctoMeter.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@
384384
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
385385
CODE_SIGN_IDENTITY = "Apple Development";
386386
CODE_SIGN_STYLE = Automatic;
387-
CURRENT_PROJECT_VERSION = 14;
387+
CURRENT_PROJECT_VERSION = 15;
388388
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
389389
DEVELOPMENT_TEAM = V8M4R7N63C;
390390
ENABLE_PREVIEWS = YES;
@@ -401,7 +401,7 @@
401401
"$(inherited)",
402402
"@executable_path/Frameworks",
403403
);
404-
MARKETING_VERSION = 2.3.0;
404+
MARKETING_VERSION = 2.3.1;
405405
OTHER_LDFLAGS = (
406406
"$(inherited)",
407407
"-framework",
@@ -422,7 +422,7 @@
422422
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
423423
CODE_SIGN_IDENTITY = "Apple Development";
424424
CODE_SIGN_STYLE = Automatic;
425-
CURRENT_PROJECT_VERSION = 14;
425+
CURRENT_PROJECT_VERSION = 15;
426426
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
427427
DEVELOPMENT_TEAM = V8M4R7N63C;
428428
ENABLE_PREVIEWS = YES;
@@ -439,7 +439,7 @@
439439
"$(inherited)",
440440
"@executable_path/Frameworks",
441441
);
442-
MARKETING_VERSION = 2.3.0;
442+
MARKETING_VERSION = 2.3.1;
443443
OTHER_LDFLAGS = (
444444
"$(inherited)",
445445
"-framework",

iosApp/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- composeApp (2.3.0)
2+
- composeApp (2.3.1)
33

44
DEPENDENCIES:
55
- composeApp (from `../composeApp/`)
@@ -9,7 +9,7 @@ EXTERNAL SOURCES:
99
:path: "../composeApp/"
1010

1111
SPEC CHECKSUMS:
12-
composeApp: be2eed0e93f9f2e0672a8aaf85099a186731e2d1
12+
composeApp: 370b588122b7702f52bd2ba74fdbb187caee68c3
1313

1414
PODFILE CHECKSUM: 132f4b88956762bee62e7893fe00dca16e0d8114
1515

iosApp/iosApp/Info.plist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
<key>CFBundlePackageType</key>
2020
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
2121
<key>CFBundleShortVersionString</key>
22-
<string>2.3.0</string>
22+
<string>2.3.1</string>
2323
<key>CFBundleVersion</key>
24-
<string>14</string>
24+
<string>15</string>
2525
<key>LSRequiresIPhoneOS</key>
2626
<true/>
2727
<key>UIApplicationSceneManifest</key>

0 commit comments

Comments
 (0)