Skip to content

Commit

Permalink
Update Android sample. Fix dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
kpgalligan committed Sep 19, 2023
1 parent 437ac68 commit e6c4391
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
5 changes: 5 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ androidx-activity-compose = "1.7.2"
android-desugaring = "2.0.3"
koin = "3.4.3"

sharedlib = "0.4.+"

[libraries]
compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "composeCompiler" }

Expand Down Expand Up @@ -69,6 +71,9 @@ compose-activity = { module = "androidx.activity:activity-compose", version.ref
android-desugaring = { module = "com.android.tools:desugar_jdk_libs", version.ref = "android-desugaring" }
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }

sharedlib-analytics = { module = "co.touchlab.kmmbridgekickstartskie:analytics-android-debug", version.ref = "sharedlib" }
sharedlib-breeds = { module = "co.touchlab.kmmbridgekickstartskie:breeds-android-debug", version.ref = "sharedlib" }

[bundles]
ktor-common = ["ktor-client-core", "ktor-client-logging", "ktor-client-serialization", "ktor-client-contentNegotiation"]
app-ui = [
Expand Down
24 changes: 22 additions & 2 deletions testapps/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@ android {
}
}

val remoteBuild = false

if (remoteBuild) {
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/touchlab-lab/KMMBridgeKickStartSKIE")
credentials {
username = project.property("GITHUB_PACKAGES_USERNAME") as String
password = project.property("GITHUB_PACKAGES_PASSWORD") as String
}
}
}
}

dependencies {
implementation(project(":analytics"))
implementation(project(":breeds"))
if (remoteBuild) {
implementation(libs.sharedlib.breeds)
implementation(libs.sharedlib.analytics)
} else {
implementation(project(":analytics"))
implementation(project(":breeds"))
}
implementation(libs.bundles.app.ui)
implementation(libs.koin.android)
coreLibraryDesugaring(libs.android.desugaring)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.Divider
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.*
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
Expand All @@ -29,6 +25,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.rememberCoroutineScope
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.tooling.preview.Preview
Expand Down Expand Up @@ -67,7 +64,6 @@ fun MainScreenContent(
dataEvent: BreedDataEvent,
breedList: List<Breed>,
onRefresh: () -> Unit = {},
onError: (String) -> Unit = {},
onFavorite: (Breed) -> Unit = {}
) {
Surface(
Expand All @@ -76,21 +72,34 @@ fun MainScreenContent(
) {
val refreshState = rememberPullRefreshState(dataEvent is BreedDataEvent.Loading, onRefresh)

Box(Modifier.pullRefresh(refreshState)) {
when(dataEvent){
is BreedDataEvent.Error -> Error(dataEvent.reason.name)
BreedDataEvent.Initial -> Empty()
BreedDataEvent.Loading -> Empty()
BreedDataEvent.RefreshedSuccess -> {
if(breedList.isEmpty()){
Empty()
}else {
Success(successData = breedList, favoriteBreed = onFavorite)
}
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
when (dataEvent) {
is BreedDataEvent.Error -> Text(dataEvent.reason.name, color = Color.Red)
BreedDataEvent.Initial -> Text("")
BreedDataEvent.Loading -> Text("Loading...")
BreedDataEvent.RefreshedSuccess -> Text("Success")
}

when (dataState) {
is BreedDataState.Cached -> Button(onRefresh) { Text("Refresh") }
BreedDataState.Empty -> Button(onRefresh) { Text("Load Data") }
BreedDataEvent.Loading -> Button(onRefresh, enabled = false) { Text("Refresh") }
}

PullRefreshIndicator(dataEvent is BreedDataEvent.Loading, refreshState, Modifier.align(Alignment.TopCenter))
Box(Modifier.pullRefresh(refreshState)) {
when (dataState) {
is BreedDataState.Cached, BreedDataEvent.Loading -> Success(
successData = breedList,
favoriteBreed = onFavorite
)
BreedDataState.Empty -> Empty()
}
PullRefreshIndicator(
dataEvent is BreedDataEvent.Loading,
refreshState,
Modifier.align(Alignment.TopCenter)
)
}
}
}
}
Expand Down Expand Up @@ -160,7 +169,7 @@ fun FavoriteIcon(breed: Breed) {
animationSpec = TweenSpec(
durationMillis = 500,
easing = FastOutSlowInEasing
)
), label = "favFade"
) { fav ->
if (fav) {
Image(
Expand Down

0 comments on commit e6c4391

Please sign in to comment.