-
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
d930a99
commit 56ed776
Showing
46 changed files
with
380 additions
and
241 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ kotlin { | |
jvm() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ kotlin { | |
jvm() | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
|
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
27 changes: 27 additions & 0 deletions
27
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,27 @@ | ||
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 | ||
|
||
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() | ||
|
||
internal actual fun createAppComponent( | ||
debuggable: Boolean, | ||
baseUrl: String, | ||
apiKey: String, | ||
platformContext: PlatformContext | ||
): AppComponent { | ||
return AppComponent::class.create(debuggable, baseUrl, apiKey, platformContext) | ||
} |
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.PlatformContext | ||
import dev.androidbroadcast.common.Singleton | ||
import dev.androidbroadcast.news.data.ArticlesRepository | ||
import dev.androidbroadcast.news.database.NewsDatabase | ||
import dev.androidbroadcast.news.database.NewsRoomDatabase | ||
import dev.androidbroadcast.newsapi.NewsApi | ||
import kotlinx.serialization.ExperimentalSerializationApi | ||
import kotlinx.serialization.json.Json | ||
import me.tatarka.inject.annotations.Component | ||
import me.tatarka.inject.annotations.Provides | ||
import kotlin.properties.Delegates.notNull | ||
|
||
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( | ||
public val debuggable: Boolean, | ||
protected val baseUrl: String, | ||
protected val apiKey: String, | ||
protected val platformContext: PlatformContext, | ||
) { | ||
|
||
public abstract val articlesRepository: ArticlesRepository | ||
|
||
public abstract val newsDatabase: NewsDatabase | ||
|
||
@ExperimentalSerializationApi | ||
@Singleton | ||
@Provides | ||
internal fun providesJson(): Json { | ||
return Json { | ||
isLenient = true | ||
ignoreUnknownKeys = true | ||
explicitNulls = false | ||
} | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
internal fun providesNewsApi( | ||
json: Json, | ||
): NewsApi { | ||
return NewsApi( | ||
baseUrl = baseUrl, | ||
apiKey = apiKey, | ||
json = json | ||
) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
internal fun providesAppDispatchers(): AppDispatchers = AppDispatchers() | ||
|
||
@Singleton | ||
@Provides | ||
internal fun providesNewsDatabase( | ||
dispatchers: AppDispatchers, | ||
): NewsDatabase { | ||
return NewsDatabase( | ||
databaseBuilder = newsRoomDatabaseBuilder(platformContext), | ||
dispatcher = dispatchers.io | ||
) | ||
} | ||
|
||
@Singleton | ||
@Provides | ||
internal fun providesLogger(): Logger = newLogger() | ||
|
||
public companion object { | ||
|
||
public var appComponent: AppComponent by notNull() | ||
private set | ||
|
||
internal fun create( | ||
debuggable: Boolean, | ||
baseUrl: String, | ||
apiKey: String, | ||
platformContext: PlatformContext, | ||
): AppComponent { | ||
appComponent = createAppComponent(debuggable, baseUrl, apiKey, platformContext) | ||
return appComponent | ||
} | ||
} | ||
} |
Oops, something went wrong.