-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94fa514
commit 4e5e43e
Showing
36 changed files
with
332 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
core/common/src/androidMain/kotlin/dev/androidbroadcast/common/PlatformContext.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package dev.androidbroadcast.common | ||
|
||
import android.content.Context | ||
|
||
public actual typealias PlatformContext = Context |
12 changes: 12 additions & 0 deletions
12
core/common/src/commonMain/kotlin/dev/androidbroadcast/common/Named.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.androidbroadcast.common | ||
|
||
import me.tatarka.inject.annotations.Qualifier | ||
|
||
@Qualifier | ||
@Target( | ||
AnnotationTarget.PROPERTY_GETTER, | ||
AnnotationTarget.FUNCTION, | ||
AnnotationTarget.VALUE_PARAMETER, | ||
AnnotationTarget.TYPE | ||
) | ||
public annotation class Named(val value: String) |
3 changes: 3 additions & 0 deletions
3
core/common/src/commonMain/kotlin/dev/androidbroadcast/common/PlatformContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package dev.androidbroadcast.common | ||
|
||
public expect abstract class PlatformContext |
7 changes: 7 additions & 0 deletions
7
core/common/src/commonMain/kotlin/dev/androidbroadcast/common/Singleton.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.androidbroadcast.common | ||
|
||
import me.tatarka.inject.annotations.Scope | ||
|
||
@Scope | ||
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER) | ||
public annotation class Singleton |
4 changes: 4 additions & 0 deletions
4
core/common/src/jvmMain/kotlin/dev/androidbroadcast/common/PlatformContext.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.androidbroadcast.common | ||
|
||
public actual abstract class PlatformContext { | ||
} |
4 changes: 4 additions & 0 deletions
4
core/common/src/nativeMain/kotlin/dev/androidbroadcast/common/PlatformContext.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package dev.androidbroadcast.common | ||
|
||
public actual abstract class PlatformContext { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/platform/src/androidMain/kotlin/dev/androidbroadcast/news/core/AppComponent.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package dev.androidbroadcast.news.core | ||
|
||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import dev.androidbroadcast.common.AndroidLogcatLogger | ||
import dev.androidbroadcast.common.Logger | ||
import dev.androidbroadcast.common.PlatformContext | ||
import dev.androidbroadcast.news.database.NewsRoomDatabase | ||
import org.koin.android.ext.koin.androidContext | ||
|
||
internal actual fun newsRoomDatabaseBuilder(context: PlatformContext): RoomDatabase.Builder<NewsRoomDatabase> { | ||
return Room.databaseBuilder( | ||
context = context, | ||
klass = NewsRoomDatabase::class.java, | ||
name = "news" | ||
) | ||
} | ||
|
||
internal actual fun newLogger(): Logger = AndroidLogcatLogger() |
25 changes: 0 additions & 25 deletions
25
core/platform/src/androidMain/kotlin/dev/androidbroadcast/news/core/KoinModules.android.kt
This file was deleted.
Oops, something went wrong.
99 changes: 99 additions & 0 deletions
99
core/platform/src/commonMain/kotlin/dev/androidbroadcast/news/core/AppComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package dev.androidbroadcast.news.core | ||
|
||
import androidx.room.RoomDatabase | ||
import dev.androidbroadcast.common.AppDispatchers | ||
import dev.androidbroadcast.common.Logger | ||
import dev.androidbroadcast.common.Named | ||
import dev.androidbroadcast.common.PlatformContext | ||
import dev.androidbroadcast.common.Singleton | ||
import dev.androidbroadcast.news.database.NewsDatabase | ||
import dev.androidbroadcast.news.database.NewsRoomDatabase | ||
import dev.androidbroadcast.newsapi.NewsApi | ||
import kotlinx.serialization.json.Json | ||
import me.tatarka.inject.annotations.Component | ||
import me.tatarka.inject.annotations.KmpComponentCreate | ||
import me.tatarka.inject.annotations.Provides | ||
|
||
@KmpComponentCreate | ||
internal expect fun createAppComponent( | ||
debuggable: Boolean, | ||
baseUrl: String, | ||
apiKey: String, | ||
platformContext: PlatformContext, | ||
): AppComponent | ||
|
||
internal expect fun newsRoomDatabaseBuilder(context: PlatformContext): RoomDatabase.Builder<NewsRoomDatabase> | ||
|
||
internal expect fun newLogger(): Logger | ||
|
||
@Component | ||
@Singleton | ||
public abstract class AppComponent( | ||
@get:Provides @get:Named(ConfigProperties.NewsPlatform.Debug) public val debuggable: Boolean, | ||
@get:Provides @get:Named(ConfigProperties.NewsApi.BaseUrl) protected val baseUrl: String, | ||
@get:Provides @get:Named(ConfigProperties.NewsApi.ApiKey) protected val apiKey: String, | ||
@get:Provides protected val platformContext: PlatformContext, | ||
) { | ||
|
||
@Singleton | ||
@Provides | ||
protected fun json(): Json { | ||
return Json { | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
explicitNulls = false | ||
} | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
protected fun newsApi( | ||
@Named(ConfigProperties.NewsApi.BaseUrl) baseUrl: String, | ||
@Named(ConfigProperties.NewsApi.ApiKey) apiKey: String, | ||
json: Json, | ||
): NewsApi { | ||
return NewsApi( | ||
baseUrl = baseUrl, | ||
apiKey = apiKey, | ||
json = json | ||
) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
protected fun appDispatchers(): AppDispatchers = AppDispatchers() | ||
|
||
@Singleton | ||
@Provides | ||
protected fun newsDatabase( | ||
dispatchers: AppDispatchers, | ||
context: PlatformContext, | ||
): NewsDatabase { | ||
return NewsDatabase( | ||
databaseBuilder = newsRoomDatabaseBuilder(context), | ||
dispatcher = dispatchers.io | ||
) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
protected fun logger(): Logger = newLogger() | ||
|
||
public companion object { | ||
|
||
public val appComponent: AppComponent | ||
get() = checkNotNull(_appComponent) | ||
|
||
private var _appComponent: AppComponent? = null | ||
|
||
internal fun create( | ||
debuggable: Boolean, | ||
baseUrl: String, | ||
apiKey: String, | ||
platformContext: PlatformContext, | ||
): AppComponent { | ||
this._appComponent = createAppComponent(debuggable, baseUrl, apiKey, platformContext) | ||
return appComponent | ||
} | ||
} | ||
} |
48 changes: 0 additions & 48 deletions
48
core/platform/src/commonMain/kotlin/dev/androidbroadcast/news/core/KoinModules.kt
This file was deleted.
Oops, something went wrong.
48 changes: 10 additions & 38 deletions
48
core/platform/src/commonMain/kotlin/dev/androidbroadcast/news/core/NewsAppPlatform.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,26 @@ | ||
package dev.androidbroadcast.news.core | ||
|
||
import coil3.ImageLoader | ||
import coil3.PlatformContext | ||
import coil3.SingletonImageLoader | ||
import org.koin.core.component.KoinComponent | ||
import org.koin.core.component.KoinScopeComponent | ||
import org.koin.core.context.startKoin | ||
import org.koin.core.logger.Level | ||
import org.koin.core.scope.Scope | ||
import org.koin.dsl.KoinAppDeclaration | ||
import dev.androidbroadcast.common.PlatformContext | ||
import kotlin.properties.Delegates.notNull | ||
|
||
public class NewsAppPlatform : | ||
KoinComponent, | ||
KoinScopeComponent, | ||
SingletonImageLoader.Factory { | ||
override val scope: Scope | ||
// Root scope id taken from Koin source code | ||
get() = getKoin().getScope("_root_") | ||
|
||
public var appComponent: AppComponent by notNull() | ||
private set | ||
|
||
public fun start( | ||
debug: Boolean, | ||
newsApiKey: String, | ||
newsApiBaseUrl: String, | ||
targetAppDeclaration: KoinAppDeclaration = {} | ||
platformContext: PlatformContext, | ||
) { | ||
startKoin { | ||
modules( | ||
appKoinModule, | ||
targetKoinModule | ||
) | ||
|
||
properties( | ||
mapOf( | ||
ConfigProperties.NewsPlatform.Debug to debug, | ||
ConfigProperties.NewsApi.ApiKey to newsApiKey, | ||
ConfigProperties.NewsApi.BaseUrl to newsApiBaseUrl | ||
) | ||
) | ||
|
||
if (debug) { | ||
printLogger(Level.DEBUG) | ||
} | ||
|
||
targetAppDeclaration() | ||
} | ||
appComponent = AppComponent.create(debug, newsApiBaseUrl, newsApiKey, platformContext) | ||
} | ||
|
||
override fun newImageLoader(context: PlatformContext): ImageLoader = | ||
newImageLoader( | ||
context, | ||
debug = getKoin().getProperty(ConfigProperties.NewsPlatform.Debug, false) | ||
) | ||
override fun newImageLoader(context: coil3.PlatformContext): ImageLoader { | ||
return newImageLoader(context, debug = appComponent.debuggable) | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
core/platform/src/iosMain/kotlin/dev/androidbroadcast/news/core/AppComponent.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.androidbroadcast.news.core | ||
|
||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.sqlite.driver.bundled.BundledSQLiteDriver | ||
import dev.androidbroadcast.common.Logger | ||
import dev.androidbroadcast.common.PlatformContext | ||
import dev.androidbroadcast.common.PrintLogger | ||
import dev.androidbroadcast.news.database.NewsRoomDatabase | ||
import dev.androidbroadcast.news.database.instantiateNewsRoomDatabase | ||
import platform.Foundation.NSHomeDirectory | ||
|
||
internal actual fun newsRoomDatabaseBuilder(context: PlatformContext): RoomDatabase.Builder<NewsRoomDatabase> { | ||
return Room.databaseBuilder<NewsRoomDatabase>( | ||
name = "${NSHomeDirectory()}/news.db", | ||
factory = { instantiateNewsRoomDatabase() } | ||
).setDriver(BundledSQLiteDriver()) | ||
} | ||
|
||
internal actual fun newLogger(): Logger = PrintLogger() |
Oops, something went wrong.