Skip to content

Instantly share code, notes, and snippets.

View alibahaaa's full-sized avatar
❤️‍🔥
Coding with love and passion

Ali Baha alibahaaa

❤️‍🔥
Coding with love and passion
View GitHub Profile
@alibahaaa
alibahaaa / KMM_interface_repository.kt
Last active June 25, 2022 14:07
KMM interface repository
interface Repository {
suspend fun getOrigami() : List<Entity>
}
import kotlinx.serialization.Serializable
@Serializable
data class Entity(
val id: Int = 0,
val name: String = "",
val image: String = "",
val description: String = ""
)
class GetOrigamiUseCase(private val repository: Repository) {
suspend fun invoke() = repository.getOrigami()
}
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.serialization.kotlinx.json.*
import kotlinx.serialization.json.Json
fun createJson() = Json { isLenient = true; ignoreUnknownKeys = true }
fun createHttpClient(
json: Json
) = HttpClient {
import io.ktor.client.*
import io.ktor.client.call.*
import io.ktor.client.request.*
import org.koin.core.component.KoinComponent
interface RemoteDatasource {
suspend fun fetchOrigami(): List<Entity>
}
class RemoteDatasourceImpl(
class RepositoryImpl(
private val remoteDatasource: RemoteDatasource
) : KoinComponent , Repository {
override suspend fun getOrigami(): List<Entity> = remoteDatasource.fetchOrigami()
}
import org.koin.core.Koin
import org.koin.core.context.startKoin
import org.koin.core.parameter.parametersOf
import org.koin.dsl.KoinAppDeclaration
import org.koin.dsl.module
import kotlin.reflect.KClass
fun initKoin(appDeclaration: KoinAppDeclaration = {}) = startKoin {
appDeclaration()
modules(commonModule, platformModule())
val ktorVersion = "2.0.2"
val koinVersion = "3.2.0"
val serializationVersion = "1.3.2"
val commonMain by getting {
dependencies {
// Ktor
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-serialization:$ktorVersion")
plugins {
kotlin("multiplatform")
id("com.android.library")
kotlin("plugin.serialization") version "1.5.0"
}
val coroutinesVersion = "1.6.1"
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutinesVersion")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion")
val koinVersion = "3.2.0"
implementation("io.insert-koin:koin-android:$koinVersion")
val composeVersion = "1.1.1"
implementation("androidx.compose.ui:ui:$composeVersion")
implementation("androidx.compose.material:material:$composeVersion")