Skip to content

Commit

Permalink
Merge pull request #365 from ryanw-mobile/fix/364-usage-screen-fix-ti…
Browse files Browse the repository at this point in the history
…les-section

(#364) Usage screen: fix tiles section to support more tariff types
  • Loading branch information
ryanw-mobile authored Nov 21, 2024
2 parents 3a2d184 + 0ea7db0 commit 2a1551f
Showing 9 changed files with 161 additions and 45 deletions.
4 changes: 2 additions & 2 deletions composeApp/composeApp.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'composeApp'
spec.version = '2.3.0'
spec.version = '2.3.1'
spec.homepage = 'https://github.com/ryanw-mobile/OctoMeter/'
spec.source = { :http=> ''}
spec.authors = ''
@@ -51,4 +51,4 @@ Pod::Spec.new do |spec|
}
]
spec.resources = ['build/compose/cocoapods/compose-resources']
end
end
Original file line number Diff line number Diff line change
@@ -11,6 +11,10 @@ query PropertiesQuery($accountNumber: String!) {
meters {
serialNumber
makeAndType
smartImportElectricityMeter {
deviceId
__typename
}
meterPoint {
meters {
serialNumber
Original file line number Diff line number Diff line change
@@ -25,7 +25,11 @@ fun SingleEnergyProductQuery.EnergyProduct.toTariff(
tariffCode: String,
): Tariff? {
val tariffNode = tariffs?.edges
?.firstOrNull { it?.node?.onStandardTariff?.tariffCode == tariffCode }
?.firstOrNull {
it?.node?.onStandardTariff?.tariffCode == tariffCode ||
it?.node?.onDayNightTariff?.tariffCode == tariffCode ||
it?.node?.onThreeRateTariff?.tariffCode == tariffCode
}
?.node

if (tariffNode == null) {
Original file line number Diff line number Diff line change
@@ -88,7 +88,28 @@ data class Tariff(
}
}

// TODO: WIP - We do not support dual rates and don't know how it works for now
fun containsValidUnitRate(): Boolean {
return when (getElectricityTariffType()) {
ElectricityTariffType.STANDARD -> {
vatInclusiveStandardUnitRate != null || isVariable
}

ElectricityTariffType.DAY_NIGHT -> {
vatInclusiveDayUnitRate != null &&
vatInclusiveNightUnitRate != null
}

ElectricityTariffType.THREE_RATE -> {
vatInclusiveDayUnitRate != null &&
vatInclusiveNightUnitRate != null &&
vatInclusiveOffPeakRate != null
}

else -> false
}
}

// TODO: This function will be removed once we have migrated to get billing data from GraphQL
fun resolveUnitRate(referencePoint: Instant? = null): Double? {
return when (getElectricityTariffType()) {
ElectricityTariffType.STANDARD -> {
Original file line number Diff line number Diff line change
@@ -35,11 +35,16 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
import androidx.compose.ui.draw.clip
import androidx.compose.ui.text.font.FontWeight
import com.rwmobi.kunigami.domain.extensions.roundToTwoDecimalPlaces
import com.rwmobi.kunigami.domain.model.product.ElectricityTariffType
import com.rwmobi.kunigami.domain.model.product.Tariff
import com.rwmobi.kunigami.ui.composehelper.getScreenSizeInfo
import com.rwmobi.kunigami.ui.previewsampledata.TariffSamples
import com.rwmobi.kunigami.ui.theme.getDimension
import kunigami.composeapp.generated.resources.Res
import kunigami.composeapp.generated.resources.day_unit_rate
import kunigami.composeapp.generated.resources.night_unit_rate
import kunigami.composeapp.generated.resources.off_peak_rate
import kunigami.composeapp.generated.resources.standard_unit_rate
import kunigami.composeapp.generated.resources.standing_charge
import kunigami.composeapp.generated.resources.tariffs_variable
@@ -90,38 +95,11 @@ internal fun TariffSummaryTile(
)
}

val resolvedUnitRate = tariff.resolveUnitRate()
val rateString = when {
tariff.isVariable -> stringResource(resource = Res.string.tariffs_variable)
resolvedUnitRate != null -> stringResource(resource = Res.string.unit_p_kwh, resolvedUnitRate)
else -> null
}

if (rateString != null) {
HorizontalDivider(
modifier = Modifier
.padding(vertical = dimension.grid_1)
.alpha(0.5f),
val shouldShowUnitRate = tariff.containsValidUnitRate()
if (shouldShowUnitRate) {
UnitRateLayout(
tariff = tariff,
)

Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(space = dimension.grid_0_5),
) {
Text(
modifier = Modifier.weight(weight = 1f),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.standard_unit_rate),
)
Text(
modifier = Modifier.wrapContentWidth(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = rateString,
)
}
}

Spacer(modifier = Modifier.weight(1f))
@@ -135,6 +113,115 @@ internal fun TariffSummaryTile(
}
}

@Composable
private fun UnitRateLayout(
modifier: Modifier = Modifier,
tariff: Tariff,
) {
val dimension = getScreenSizeInfo().getDimension()
HorizontalDivider(
modifier = Modifier
.padding(vertical = dimension.grid_1)
.alpha(0.5f),
)

when (tariff.getElectricityTariffType()) {
ElectricityTariffType.STANDARD -> {
val rateString = when {
tariff.isVariable -> stringResource(resource = Res.string.tariffs_variable)
tariff.vatInclusiveStandardUnitRate != null -> stringResource(resource = Res.string.unit_p_kwh, tariff.vatInclusiveStandardUnitRate)
else -> null
}

rateString?.let {
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(space = dimension.grid_0_5),
) {
Text(
modifier = Modifier.weight(weight = 1f),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.standard_unit_rate),
)
Text(
modifier = Modifier.wrapContentWidth(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = rateString,
)
}
}
}

else -> {
tariff.vatInclusiveDayUnitRate?.let { rate ->
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(space = dimension.grid_0_5),
) {
Text(
modifier = Modifier.weight(weight = 1f),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.day_unit_rate),
)
Text(
modifier = Modifier.wrapContentWidth(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
)
}
}

tariff.vatInclusiveNightUnitRate?.let { rate ->
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(space = dimension.grid_0_5),
) {
Text(
modifier = Modifier.weight(weight = 1f),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.night_unit_rate),
)
Text(
modifier = Modifier.wrapContentWidth(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
)
}
}

tariff.vatInclusiveOffPeakRate?.let { rate ->
Row(
modifier = Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(space = dimension.grid_0_5),
) {
Text(
modifier = Modifier.weight(weight = 1f),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.off_peak_rate),
)
Text(
modifier = Modifier.wrapContentWidth(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurface,
text = stringResource(resource = Res.string.unit_p_kwh, rate.roundToTwoDecimalPlaces()),
)
}
}
}
}
}

@Preview
@Composable
private fun Preview() {
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -43,8 +43,8 @@ apollographqlMockServer = "0.1.0"
testRules = "1.6.1"

# App configurations, not dependencies
versionCode = "14"
versionName = "2.3.0"
versionCode = "15"
versionName = "2.3.1"
android-minSdk = "26"
android-targetSdk = "34"
android-compileSdk = "34"
8 changes: 4 additions & 4 deletions iosApp/OctoMeter.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
@@ -384,7 +384,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 14;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = V8M4R7N63C;
ENABLE_PREVIEWS = YES;
@@ -401,7 +401,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
@@ -422,7 +422,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 14;
CURRENT_PROJECT_VERSION = 15;
DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\"";
DEVELOPMENT_TEAM = V8M4R7N63C;
ENABLE_PREVIEWS = YES;
@@ -439,7 +439,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 2.3.0;
MARKETING_VERSION = 2.3.1;
OTHER_LDFLAGS = (
"$(inherited)",
"-framework",
4 changes: 2 additions & 2 deletions iosApp/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- composeApp (2.3.0)
- composeApp (2.3.1)

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

SPEC CHECKSUMS:
composeApp: be2eed0e93f9f2e0672a8aaf85099a186731e2d1
composeApp: 370b588122b7702f52bd2ba74fdbb187caee68c3

PODFILE CHECKSUM: 132f4b88956762bee62e7893fe00dca16e0d8114

4 changes: 2 additions & 2 deletions iosApp/iosApp/Info.plist
Original file line number Diff line number Diff line change
@@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>2.3.0</string>
<string>2.3.1</string>
<key>CFBundleVersion</key>
<string>14</string>
<string>15</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIApplicationSceneManifest</key>

0 comments on commit 2a1551f

Please sign in to comment.