Skip to content

Commit 43823b9

Browse files
authored
Refactor: Remove unused code and replace raw unit constants with extension functions (#192)
1 parent 96baf5c commit 43823b9

35 files changed

Lines changed: 68 additions & 277 deletions

File tree

androidApp/src/screenshotTest/kotlin/org/neotech/app/abysner/presentation/screens/ShareImageScreenshotTest.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ package org.neotech.app.abysner.presentation.screens
1515
import androidx.compose.runtime.Composable
1616
import androidx.compose.ui.tooling.preview.Preview
1717
import com.android.tools.screenshot.PreviewTest
18-
import org.neotech.app.abysner.presentation.preview.DEVICE_PHONE_MAX_HEIGHT
1918

2019
@PreviewTest
2120
@Preview(device = DEVICE_SHARE_IMAGE)

buildSrc/src/main/kotlin/org/neotech/gradle/GradleUtilities.kt

Lines changed: 0 additions & 23 deletions
This file was deleted.

buildSrc/src/main/kotlin/org/neotech/plugin/ScreenshotTestCoveragePlugin.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ class ScreenshotTestCoveragePlugin : Plugin<Project> {
121121

122122
val classFiles = listOf(
123123
"com/android/tools/screenshot/renderer/Renderer.class",
124-
"com/android/tools/screenshot/renderer/Renderer\$copyObject\$objectIn\$1.class",
124+
$$"com/android/tools/screenshot/renderer/Renderer$copyObject$objectIn$1.class",
125125
"com/android/tools/screenshot/renderer/RendererKt.class",
126-
"com/android/tools/screenshot/renderer/RendererKt\$createResourceEnhancedClassLoader\$1.class",
126+
$$"com/android/tools/screenshot/renderer/RendererKt$createResourceEnhancedClassLoader$1.class",
127127
)
128128

129129
for (classFile in classFiles) {

composeApp/src/commonMain/kotlin/androidx/compose/material3/AlertDialogCustomContent.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,7 @@ private fun AlertDialogFlowRowCopy(
192192

193193
val crossAxisLayoutSize = max(crossAxisSpace, constraints.minHeight)
194194

195-
val layoutWidth = mainAxisLayoutSize
196-
197-
val layoutHeight = crossAxisLayoutSize
198-
199-
layout(layoutWidth, layoutHeight) {
195+
layout(mainAxisLayoutSize, crossAxisLayoutSize) {
200196
sequences.fastForEachIndexed { i, placeables ->
201197
val childrenMainAxisSizes = IntArray(placeables.size) { j ->
202198
placeables[j].width +

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/App.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
package org.neotech.app.abysner
1414

1515
import androidx.compose.runtime.Composable
16-
import androidx.compose.ui.tooling.preview.Preview
1716
import org.neotech.app.abysner.di.AppComponent
1817

1918
@Composable
20-
@Preview
2119
fun App(appComponent: AppComponent) {
2220
appComponent.mainNavController()
2321
}

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/AnimationExtensions.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import androidx.compose.animation.core.DurationBasedAnimationSpec
1818
import androidx.compose.animation.core.TwoWayConverter
1919
import androidx.compose.animation.core.VectorizedDurationBasedAnimationSpec
2020

21-
fun <T> none(): AnimationSpec<T> = AnimationSpecNone<T>()
21+
fun <T> none(): AnimationSpec<T> = AnimationSpecNone()
2222

2323
class AnimationSpecNone<T>: DurationBasedAnimationSpec<T> {
2424

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/AnnotatedStringExtensions.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,22 @@
1313
package org.neotech.app.abysner.presentation.component
1414

1515
import androidx.compose.ui.text.AnnotatedString
16-
import androidx.compose.ui.text.AnnotatedString.Builder
1716
import androidx.compose.ui.text.ParagraphStyle
1817
import androidx.compose.ui.text.SpanStyle
1918
import androidx.compose.ui.text.font.FontWeight
2019
import androidx.compose.ui.text.style.TextIndent
2120
import androidx.compose.ui.text.withStyle
2221
import androidx.compose.ui.unit.sp
2322

24-
internal fun Builder.appendBold(
23+
internal fun AnnotatedString.Builder.appendBold(
2524
text: String,
2625
) {
2726
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
2827
append(text)
2928
}
3029
}
3130

32-
internal fun Builder.appendBoldLine(
31+
internal fun AnnotatedString.Builder.appendBoldLine(
3332
text: String,
3433
) {
3534
withStyle(style = SpanStyle(fontWeight = FontWeight.Bold)) {
@@ -46,9 +45,5 @@ internal inline fun <R: Any> AnnotatedString.Builder.appendBulletPoint(crossinli
4645
}
4746

4847
internal fun CharSequence.toAnnotatedString(): AnnotatedString {
49-
return if(this is AnnotatedString) {
50-
return this
51-
} else {
52-
AnnotatedString(this.toString())
53-
}
48+
return this as? AnnotatedString ?: AnnotatedString(this.toString())
5449
}

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/CheckableListComponent.kt

Lines changed: 0 additions & 47 deletions
This file was deleted.

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/CylinderSizeField.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,10 @@ import org.neotech.app.abysner.domain.core.model.Cylinder
5858
import org.neotech.app.abysner.domain.core.model.Gas
5959
import org.neotech.app.abysner.domain.core.model.UnitSystem
6060
import org.neotech.app.abysner.domain.core.physics.GasEquationOfStateModel
61-
import org.neotech.app.abysner.domain.core.physics.LITERS_PER_CUBIC_FOOT
62-
import org.neotech.app.abysner.domain.core.physics.PSI_PER_BAR
61+
import org.neotech.app.abysner.domain.core.physics.asBarToPsi
62+
import org.neotech.app.abysner.domain.core.physics.asCubicFeetToLiters
63+
import org.neotech.app.abysner.domain.core.physics.asLitersToCubicFeet
64+
import org.neotech.app.abysner.domain.core.physics.asPsiToBar
6365
import org.neotech.app.abysner.domain.utilities.DecimalFormat
6466
import org.neotech.app.abysner.presentation.component.list.LazyColumnWithScrollIndicators
6567
import org.neotech.app.abysner.presentation.component.textfield.OutlinedDecimalInputField
@@ -81,7 +83,7 @@ fun CylinderSizeField(
8183

8284
val displayText = when (unitSystem) {
8385
UnitSystem.METRIC -> DecimalFormat.format(1, cylinderSize.waterVolume)
84-
UnitSystem.IMPERIAL -> (cylinderSize.ratedCapacity() / LITERS_PER_CUBIC_FOOT).roundToInt().toString()
86+
UnitSystem.IMPERIAL -> cylinderSize.ratedCapacity().asLitersToCubicFeet().roundToInt().toString()
8587
}
8688

8789
OutlinedTextField(
@@ -143,15 +145,15 @@ private fun CylinderSizeDialog(
143145
mutableStateOf(
144146
when (unitSystem) {
145147
UnitSystem.METRIC -> currentCylinderSize.waterVolume
146-
UnitSystem.IMPERIAL -> currentCylinderSize.ratedCapacity() / LITERS_PER_CUBIC_FOOT
148+
UnitSystem.IMPERIAL -> currentCylinderSize.ratedCapacity().asLitersToCubicFeet()
147149
}
148150
)
149151
}
150152
var customPressure: Double? by remember {
151153
mutableStateOf(
152154
when (unitSystem) {
153155
UnitSystem.METRIC -> currentCylinderSize.workingPressure
154-
UnitSystem.IMPERIAL -> currentCylinderSize.workingPressure * PSI_PER_BAR
156+
UnitSystem.IMPERIAL -> currentCylinderSize.workingPressure.asBarToPsi()
155157
}
156158
)
157159
}
@@ -177,8 +179,8 @@ private fun CylinderSizeDialog(
177179
workingPressure = customPressure!!,
178180
)
179181
UnitSystem.IMPERIAL -> {
180-
val pressureBar = customPressure!! / PSI_PER_BAR
181-
val targetCapacityLiters = customVolume!! * LITERS_PER_CUBIC_FOOT
182+
val pressureBar = customPressure!!.asPsiToBar()
183+
val targetCapacityLiters = customVolume!!.asCubicFeetToLiters()
182184
val gasVolumePerLiter = GasEquationOfStateModel.Default.getGasVolume(Gas.Air, 1.0, pressureBar)
183185
Cylinder.Size(
184186
waterVolume = targetCapacityLiters / gasVolumePerLiter,
@@ -300,14 +302,14 @@ private fun PresetsTankSizeTab(
300302
label = when (unitSystem) {
301303
UnitSystem.METRIC -> null
302304
UnitSystem.IMPERIAL -> {
303-
val pressurePsi = (preset.workingPressure * PSI_PER_BAR).roundToInt()
305+
val pressurePsi = preset.workingPressure.asBarToPsi().roundToInt()
304306
"$pressurePsi ${unitSystem.pressureUnitLabel}"
305307
}
306308
},
307309
value = when (unitSystem) {
308310
UnitSystem.METRIC -> "${DecimalFormat.format(1, preset.waterVolume)} ${unitSystem.volumeUnitLabel}"
309311
UnitSystem.IMPERIAL -> {
310-
val capacityCuFt = (preset.ratedCapacity() / LITERS_PER_CUBIC_FOOT).roundToInt()
312+
val capacityCuFt = preset.ratedCapacity().asLitersToCubicFeet().roundToInt()
311313
"$capacityCuFt ${unitSystem.volumeUnitLabel}"
312314
}
313315
},

composeApp/src/commonMain/kotlin/org/neotech/app/abysner/presentation/component/MultiChoiceSegmentedButtonRowComponent.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,18 @@
1212

1313
package org.neotech.app.abysner.presentation.component
1414

15-
import androidx.compose.ui.tooling.preview.Preview
1615
import androidx.compose.material3.SegmentedButton
1716
import androidx.compose.material3.SegmentedButtonDefaults
1817
import androidx.compose.material3.Text
1918
import androidx.compose.runtime.Composable
2019
import androidx.compose.runtime.Stable
21-
import androidx.compose.runtime.mutableStateListOf
2220
import androidx.compose.runtime.remember
2321
import androidx.compose.runtime.snapshots.SnapshotStateList
2422
import androidx.compose.runtime.toMutableStateList
2523
import androidx.compose.ui.Modifier
24+
import androidx.compose.ui.tooling.preview.Preview
2625
import kotlinx.collections.immutable.ImmutableList
2726
import kotlinx.collections.immutable.persistentListOf
28-
import kotlinx.collections.immutable.toImmutableList
2927

3028
@Stable
3129
class MultiChoiceSegmentedButtonRowState(initialCheckedItemIndexes: ImmutableList<Int>) {

0 commit comments

Comments
 (0)