diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedDetailsScreen.kt b/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedDetailsScreen.kt index 5abfd4e4..50fe89ea 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedDetailsScreen.kt +++ b/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedDetailsScreen.kt @@ -6,6 +6,7 @@ import androidx.compose.animation.core.TweenSpec import androidx.compose.foundation.Image import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.BoxScope import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize @@ -15,7 +16,6 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp @@ -23,30 +23,47 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import co.touchlab.kampkit.android.R import co.touchlab.kampkit.domain.breed.Breed import co.touchlab.kampkit.ui.breedDetails.BreedDetailsViewModel -import co.touchlab.kermit.Logger +import co.touchlab.kampkit.ui.breedDetails.BreedDetailsViewState @Composable -fun BreedDetailsScreen( - viewModel: BreedDetailsViewModel, - log: Logger -) { +fun BreedDetailsScreen(viewModel: BreedDetailsViewModel) { val state by viewModel.detailsState.collectAsStateWithLifecycle() + val error = state.error Box(Modifier.fillMaxSize()) { - state.error?.let { error -> - Text(error, Modifier.align(Alignment.Center), color = Color.Red) - } - if (state.error == null) { - Row(Modifier.align(Alignment.Center)) { - Text(state.breed.name) - Spacer(Modifier.width(4.dp)) - FavoriteIcon( - breed = state.breed, - onClick = viewModel::onFavoriteClick - ) - } + when { + state.isLoading -> Loading() + error != null -> Error(error) + else -> DetailsContents( + state = state, + onFavoriteClick = viewModel::onFavoriteClick + ) } } +} +@Composable +private fun BoxScope.DetailsContents( + state: BreedDetailsViewState, + onFavoriteClick: () -> Unit +) { + Row(Modifier.align(Alignment.Center)) { + Text(state.breed?.name ?: "") + Spacer(Modifier.width(4.dp)) + state.breed?.let { breed -> + FavoriteIcon( + breed = breed, + onClick = onFavoriteClick + ) + } + } +} +@Composable +private fun Error(error: String) { + Text(error) +} +@Composable +fun Loading() { + Text("Loading") } @Composable diff --git a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedsScreen.kt b/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedsScreen.kt index 9b7dcae6..c1bd08b3 100644 --- a/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedsScreen.kt +++ b/app/src/main/kotlin/co/touchlab/kampkit/android/ui/BreedsScreen.kt @@ -112,7 +112,7 @@ fun Empty() { } @Composable -fun Error(error: String) { +private fun Error(error: String) { Column( modifier = Modifier .fillMaxSize() diff --git a/ios/KaMPKitiOS.xcodeproj/project.pbxproj b/ios/KaMPKitiOS.xcodeproj/project.pbxproj index 9ec20cfd..088a4ea6 100644 --- a/ios/KaMPKitiOS.xcodeproj/project.pbxproj +++ b/ios/KaMPKitiOS.xcodeproj/project.pbxproj @@ -113,6 +113,30 @@ path = Breeds; sourceTree = ""; }; + 579753BDA8BAA9A5A399C611 /* bartlomiejpedryc.xcuserdatad */ = { + isa = PBXGroup; + children = ( + 57975F3C51683ABE14191024 /* xcschemes */, + ); + path = bartlomiejpedryc.xcuserdatad; + sourceTree = ""; + }; + 5797556592C6669DF1E7702C /* xcuserdata */ = { + isa = PBXGroup; + children = ( + 579753BDA8BAA9A5A399C611 /* bartlomiejpedryc.xcuserdatad */, + ); + name = xcuserdata; + path = KaMPKitiOS.xcodeproj/xcuserdata; + sourceTree = ""; + }; + 57975F3C51683ABE14191024 /* xcschemes */ = { + isa = PBXGroup; + children = ( + ); + path = xcschemes; + sourceTree = ""; + }; 6278498AD96A4D949D39BF44 /* Frameworks */ = { isa = PBXGroup; children = ( @@ -141,6 +165,7 @@ F1465EFE23AA94BF0055F7C3 /* Products */, DF9BBECBCD175B90105DA8D9 /* Pods */, 6278498AD96A4D949D39BF44 /* Frameworks */, + 5797556592C6669DF1E7702C /* xcuserdata */, ); sourceTree = ""; }; diff --git a/ios/KaMPKitiOS.xcworkspace/xcshareddata/swiftpm/Package.resolved b/ios/KaMPKitiOS.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 00000000..b2334037 --- /dev/null +++ b/ios/KaMPKitiOS.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -0,0 +1,23 @@ +{ + "pins" : [ + { + "identity" : "kmp-nativecoroutines", + "kind" : "remoteSourceControl", + "location" : "https://github.com/rickclephas/KMP-NativeCoroutines.git", + "state" : { + "revision" : "a1269d3052fcc32d3861eaea32b715d58a46fe32", + "version" : "1.0.0-ALPHA-9" + } + }, + { + "identity" : "rxswift", + "kind" : "remoteSourceControl", + "location" : "https://github.com/ReactiveX/RxSwift.git", + "state" : { + "revision" : "9dcaa4b333db437b0fbfaf453fad29069044a8b4", + "version" : "6.6.0" + } + } + ], + "version" : 2 +} diff --git a/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/breedDetails/BreedDetailsViewState.kt b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/breedDetails/BreedDetailsViewState.kt index f188b128..d6e144ec 100644 --- a/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/breedDetails/BreedDetailsViewState.kt +++ b/shared/src/commonMain/kotlin/co/touchlab/kampkit/ui/breedDetails/BreedDetailsViewState.kt @@ -3,7 +3,7 @@ package co.touchlab.kampkit.ui.breedDetails import co.touchlab.kampkit.domain.breed.Breed data class BreedDetailsViewState( - val breed: Breed = Breed(), + val breed: Breed? = null, val error: String? = null, val isLoading: Boolean = false ) {