Skip to content

Instantly share code, notes, and snippets.

View romainbsl's full-sized avatar

Romain Boisselle romainbsl

View GitHub Profile
repositories {
// your repositories
jcenter()
}
kotlin {
jvm("android")
ios()
sourceSets {
// Auth API
interface AuthApi {
suspend fun authenticate(pid: Int, deviceId: String): Token
}
class AuthApiImpl : ClientApi(), AuthApi {
override suspend fun authenticate(pid: Int, deviceId: String)=
client.get<Token> { / * implementation */ }
}
// Token repository
interface TokenRepository {
// Login MVP definition
class Login {
interface Presenter {
fun checkAuthentication()
fun authenticate(secret: String)
}
interface View : BaseView {
fun onLoginSuccess()
}
/**
* Participant API
*/
interface ParticipantApi {
suspend fun getAll(): List<Participant>
suspend fun create(participant: Participant) : Participant
suspend fun update(participant: Participant) : Participant
suspend fun delete(participant: Participant) : Boolean
suspend fun postPhoto(participant: Participant, input: Input, extension: String) : String
}
val loginModule = DI.Module("login") {
bind<TokenRepository>() with singleton { TokenRepositoryImpl(instance()) }
bind("isLoggedIn") from provider { instance<TokenRepository>().isLoggedIn() }
bind<AuthApi>() with singleton { AuthApiImpl() }
bind<LoginPresenter>() with provider { LoginPresenterImpl(di) }
}
val participantModule = DI.Module("participant") {
bind<ParticipantRepository>() with singleton { ParticipantRepositoryImpl(instance()) }
bind<ParticipantApi>() with singleton { ParticipantApiImpl(instance()) }
bind<ParticipantCreation.Presenter>() with provider { ParticipantCreationPresenterImpl(di) }
bind<VoteCreation.Presenter>() with provider { VoteCreationPresenterImpl(di) }
bind<PhotoUpload.Presenter>() with provider { PhotoUploadPresenterImpl(di) }
bind<ParticipantList.Presenter>() with provider { ParticipantListPresenterImpl(di) }
@ThreadLocal
object CommonInjector {
val kodeinContainer = DI.lazy {
importAll(databaseModule, loginModule, participantModule)
}
// Direct access to the presenters
fun participantListPresenter() = kodeinContainer.direct.instance<ParticipantList.Presenter>()
fun participantCreationPresenter() = kodeinContainer.direct.instance<ParticipantCreation.Presenter>()
fun voteCreationPresenter() = kodeinContainer.direct.instance<VoteCreation.Presenter>()
val kodeinContainer = DI.lazy {
importAll(databaseModule, loginModule, participantModule)
}
kotlin {
// ...
sourceSets {
// ...
val commonTest by getting {
dependencies {
implementation(kotlin("test-common"))
implementation(kotlin("test-annotations-common"))
}
}
kotlin {
// ...
sourceSets {
// ...
val jvmTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(kotlin("test-junit"))
}
}