Skip to content

Commit

Permalink
Add Coil
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-ramotar committed Apr 23, 2024
1 parent 0598289 commit 263ab9a
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 10 deletions.
3 changes: 3 additions & 0 deletions experimental/sample/octonaut/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ dependencies {
api(libs.circuit.foundation)

ksp(libs.kotlinInject.compiler)
implementation(libs.coil.compose)
implementation(libs.coil.network)
implementation(libs.ktor.client.android)

implementation(project(":experimental:sample:octonaut:xplat:foundation:di:api"))
implementation(project(":experimental:sample:octonaut:xplat:foundation:networking:impl"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import coil3.ComponentRegistry
import coil3.ImageLoader
import coil3.annotation.ExperimentalCoilApi
import coil3.compose.setSingletonImageLoaderFactory
import coil3.network.ktor.KtorNetworkFetcherFactory
import com.slack.circuit.foundation.Circuit
import com.slack.circuit.foundation.CircuitCompositionLocals
import com.slack.circuit.foundation.CircuitContent
Expand All @@ -30,6 +35,7 @@ import org.mobilenativefoundation.sample.octonaut.android.app.theme.OctonautThem
import org.mobilenativefoundation.sample.octonaut.xplat.foundation.networking.api.GetUserQuery


@OptIn(ExperimentalCoilApi::class)
@Inject
class MainActivity : ComponentActivity() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,21 @@ class RealOctonautMarketDispatcher(
id = it.id,
email = it.email,
name = it.name ?: "",
login = it.name ?: "",
repositoryIds = it.repositories.nodes?.mapNotNull { it?.id } ?: emptyList()
login = it.login,
avatarUrl = it.avatarUrl.toString(),
repositories = it.repositories.nodes?.mapNotNull { repo -> repo?.id } ?: emptyList(),
starredRepositories = it.starredRepositories.nodes?.mapNotNull { repo -> repo?.id }
?: emptyList(),
organizations = it.organizations.nodes?.mapNotNull { org -> org?.id } ?: emptyList(),
pinnedItems = it.pinnedItems.let { pinnedItems -> List(pinnedItems.totalCount) { "" } },
socialAccounts = it.socialAccounts.nodes?.mapNotNull { socialAccount ->
socialAccount?.let {
User.SocialAccount(
socialAccount.displayName,
socialAccount.provider.name
)
}
} ?: emptyList()
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ data class User(
val login: String,
val name: String,
val email: String,
val repositoryIds: List<String>
)
val avatarUrl: String,
val repositories: List<String>,
val starredRepositories: List<String>,
val organizations: List<String>,
val pinnedItems: List<String>,
val socialAccounts: List<SocialAccount>
) {
data class SocialAccount(
val displayName: String,
val provider: String
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ kotlin {
api(project(":experimental:sample:octonaut:xplat:common:market"))
api(project(":experimental:sample:octonaut:xplat:feat:homeTab:api"))
api(project(":experimental:sample:octonaut:xplat:foundation:di:api"))
implementation(libs.coil.compose)
implementation(libs.coil.network)
implementation(libs.ktor)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package org.mobilenativefoundation.sample.octonaut.xplat.feat.homeTab.impl

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImagePainter
import coil3.compose.rememberAsyncImagePainter
import me.tatarka.inject.annotations.Inject
import org.mobilenativefoundation.sample.octonaut.xplat.feat.homeTab.api.HomeTab

Expand All @@ -12,13 +19,24 @@ class HomeTabUi : HomeTab.Ui {
@Composable
override fun Content(state: HomeTab.State, modifier: Modifier) {
Column {
val headingText = when (state) {
HomeTab.State.Initial -> "Initial"
is HomeTab.State.Loaded -> state.user.login
is HomeTab.State.Loading -> "Loading"
when (state) {
HomeTab.State.Initial -> Text("Initial")
is HomeTab.State.Loaded -> LoadedContent(state)
is HomeTab.State.Loading -> Text("Loading")
}
}
}

@Composable
private fun LoadedContent(state: HomeTab.State.Loaded) {
Text(state.user.login)

val painter = rememberAsyncImagePainter(state.user.avatarUrl)

Image(painter = painter, contentDescription = "", modifier = Modifier.size(60.dp).clip(CircleShape))

Text(headingText)
state.user.repositories.forEach {
Text(it)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,42 @@
query GetUser($login: String!) {
user(login: $login) {
id
login
name
email
avatarUrl
socialAccounts(first: 10) {
nodes {
displayName
provider
}
}
repositories(first: 20) {
nodes {
id
name
}
}

starredRepositories(first: 20) {
nodes {
id
name
}
}

organizations(first: 10){
nodes {
id
name
}
}

pinnedItems(first: 10){
totalCount
}


}
}

Expand Down
8 changes: 7 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ market = "0.0.1-alpha01"
truth = "1.1.3"
compose-compiler = "1.5.11"
androidx-activity = "1.8.2"
coil = "3.0.0-alpha06"

agp = "8.2.0"
buildkonfig = "0.15.1"
Expand Down Expand Up @@ -55,7 +56,7 @@ jacoco-gradle-plugin = { group = "org.jacoco", name = "org.jacoco.core", version
maven-publish-plugin = { group = "com.vanniktech", name = "gradle-maven-publish-plugin", version.ref = "mavenPublishPlugin" }
kover-plugin = { group = "org.jetbrains.kotlinx", name = "kover", version.ref = "kover" }
atomic-fu-gradle-plugin = { group = "org.jetbrains.kotlinx", name = "atomicfu-gradle-plugin", version.ref = "atomicFu" }
kmmBridge-gradle-plugin = { group = "co.touchlab.faktory.kmmbridge", name = "co.touchlab.faktory.kmmbridge.gradle.plugin", version.ref = "kmmBridge" }
kmmBridge-gradle-plugin = { group = "co.touchlab.faktory.kmmbridge", name = "co.touchlab.faktory.kmmbridge.gradle.plugin", version.ref = "kmmBridge" }

kotlinx-atomic-fu = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicFu" }
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "baseKotlin" }
Expand Down Expand Up @@ -87,6 +88,11 @@ androidx-compose-activity = { module = "androidx.activity:activity-compose", ver
androidx-core = { module = "androidx.core:core-ktx", version = "1.12.0" }
apollo-runtime = { module = "com.apollographql.apollo3:apollo-runtime", version.ref = "apolloVerson" }
apollo-normalized-cache = { module = "com.apollographql.apollo3:apollo-normalized-cache", version.ref = "apolloVerson" }
coil = { module = "io.coil-kt.coil3:coil", version.ref = "coil" }
coil-compose = { module = "io.coil-kt.coil3:coil-compose", version.ref = "coil" }
coil-network = {module = "io.coil-kt.coil3:coil-network-ktor", version.ref = "coil"}
ktor = {module = "io.ktor:ktor-client-core", version.ref = "ktor"}
ktor-client-android = {module = "io.ktor:ktor-client-android", version.ref = "ktor"}

# Gradle Plugins
android-desugarJdkLibs = { module = "com.android.tools:desugar_jdk_libs", version.ref = "desugar" }
Expand Down

0 comments on commit 263ab9a

Please sign in to comment.