Skip to content

Commit

Permalink
refac to follow standard layout
Browse files Browse the repository at this point in the history
  • Loading branch information
kotlitecture committed Jun 30, 2024
1 parent a5df0fe commit 356c741
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Overview

- Component package: `app.data.source.database.sqldelight`
- DI integration: `app.di.datasource.ProvidesSqlDelightSource`
- DI integration: `app.di.data.SqlDelightSourceModule`

The integration includes the following components:

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Overview

The data source is available within the class `shared.data.source.http.HttpSource`. An instance of this class can be obtained through dependency injection (DI) as a singleton in `app.di.datasource.ProvidesHttpSource`.
- DI integration: `app.di.data.HttpSourceModule`
- Data source: `shared.data.source.http.HttpSource`

The class provides the next functionality:

Expand All @@ -12,12 +13,12 @@ To start using, just inject it to your DI managed class.

```kotlin
class ApiSource(
private val httpSource: HttpSource = get()
private val httpSource: HttpSource
) {

suspend fun getIp(): String {
val ktor = httpSource.ktor
return ktor.get("https://api64.ipify.org").body<String>()
fun getIp(): String {
val client = httpSource.client
return client.get("https://api64.ipify.org").body<String>()
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Overview

- DI integration: `app.di.datasource.ProvidesPagingSource`
- DI integration: `app.di.data.PagingSourceModule`
- Data source: `app.data.source.paging.AppPagingSource`
- UI component: `shared.design.component.AppPagingList`

Expand Down
28 changes: 14 additions & 14 deletions template/app/src/commonMain/kotlin/kotli/app/di/DI.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package kotli.app.di

import kotli.app.di.datasource.ProvidesAnalyticsSource
import kotli.app.di.datasource.ProvidesCacheSource
import kotli.app.di.datasource.ProvidesConfigSource
import kotli.app.di.datasource.ProvidesHttpSource
import kotli.app.di.datasource.ProvidesKeyValueSource
import kotli.app.di.datasource.ProvidesPagingSource
import kotli.app.di.datasource.ProvidesSqlDelightSource
import kotli.app.di.data.analyticsSourceModule
import kotli.app.di.data.cacheSourceModule
import kotli.app.di.data.configSourceModule
import kotli.app.di.data.httpSourceModule
import kotli.app.di.data.keyValueSourceModule
import kotli.app.di.data.pagingSourceModule
import kotli.app.di.data.sqlDelightSourceModule
import kotli.app.di.state.ProvidesAppState
import kotli.app.di.state.ProvidesNavigationBarState
import kotli.app.di.state.ProvidesNavigationState
Expand All @@ -16,13 +16,13 @@ import org.koin.core.context.startKoin
val koinDI = startKoin {
printLogger()
modules(
ProvidesAnalyticsSource,
ProvidesConfigSource,
ProvidesCacheSource,
ProvidesHttpSource,
ProvidesKeyValueSource,
ProvidesPagingSource,
ProvidesSqlDelightSource,
analyticsSourceModule,
configSourceModule,
cacheSourceModule,
httpSourceModule,
keyValueSourceModule,
pagingSourceModule,
sqlDelightSourceModule,
ProvidesNavigationBarState,
ProvidesNavigationState,
ProvidesThemeStore,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.analytics.AppAnalyticsSource
import shared.data.source.analytics.AnalyticsSource
import org.koin.dsl.bind
import org.koin.dsl.module

val ProvidesAnalyticsSource = module {
val analyticsSourceModule = module {
single { AppAnalyticsSource() }.bind(AnalyticsSource::class)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.cache.AppCacheSource
import org.koin.dsl.bind
import org.koin.dsl.module
import shared.data.source.cache.CacheSource

val ProvidesCacheSource = module {
val cacheSourceModule = module {
single { AppCacheSource() }.bind(CacheSource::class)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.config.AppConfigSource
import shared.data.source.config.ConfigSource
import org.koin.dsl.bind
import org.koin.dsl.module

val ProvidesConfigSource = module {
val configSourceModule = module {
single { AppConfigSource() }.bind(ConfigSource::class)
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.config.AppConfigSource
import org.koin.dsl.module
import shared.data.source.http.HttpSource

val ProvidesHttpSource = module {
val httpSourceModule = module {
single {
val config: AppConfigSource = get()
HttpSource(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.keyvalue.AppKeyValueSource
import shared.data.source.keyvalue.KeyValueSource
import org.koin.dsl.bind
import org.koin.dsl.module

val ProvidesKeyValueSource = module {
val keyValueSourceModule = module {
single { AppKeyValueSource() }.bind(KeyValueSource::class)
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.config.AppConfigSource
import kotli.app.data.source.paging.AppPagingSource
import org.koin.dsl.module

val ProvidesPagingSource = module {
val pagingSourceModule = module {
single { AppPagingSource(get<AppConfigSource>().getPagingPageSize()) }
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package kotli.app.di.datasource
package kotli.app.di.data

import kotli.app.data.source.database.sqldelight.AppSqlDelightSource
import org.koin.dsl.module

val ProvidesSqlDelightSource = module {
val sqlDelightSourceModule = module {
single { AppSqlDelightSource() }
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BasicHttpViewModel(
delay(500)
ipState.set("Proceed fetching…")
val url = "https://api64.ipify.org?format=json"
val ipData = httpSource.ktor.get(url).body<IpData>()
val ipData = httpSource.client.get(url).body<IpData>()
ipState.set(ipData.ip)
} catch (e: Throwable) {
if (!e.isCancellationException() && !e.isHttpTimeoutException()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HttpSource(
) : DataSource {

/** https://ktor.io/docs/client-create-multiplatform-application.html */
val ktor by lazy {
val client by lazy {
HttpClient {
install(ContentNegotiation) {
json(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import androidx.compose.runtime.Immutable
@Immutable
abstract class Store {

/** Store object to hold the [DataLoading]. */
/** State object to hold the [DataLoading]. */
val loadingState: DataState<DataLoading> by lazy(::DataState)

/**
Expand Down

0 comments on commit 356c741

Please sign in to comment.