Skip to content

Commit

Permalink
Initial koin setup for dependency injection (openMF#1749)
Browse files Browse the repository at this point in the history
* Added koin dependencies

* Koin structure setup

* Koin initialized for androidMain and IosMain

* PreferencesHelper di implemented,required data models added

* PreferencesHelper implemented for desktopMain

* PreferencesHelper removed for datastore implementation
  • Loading branch information
AdityaKumdale authored Aug 27, 2024
1 parent dc95c55 commit 99099ff
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 10 deletions.
2 changes: 2 additions & 0 deletions desktop/src/jvmMain/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import org.mifospay.shared.MainView
import org.mifospay.shared.di.initKoin

fun main() {
application {
initKoin()
val windowState = rememberWindowState()
Window(
onCloseRequest = ::exitApplication,
Expand Down
11 changes: 11 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ room = "2.6.1"
roborazzi = "1.26.0"
retrofitKotlinxSerializationJson = "1.0.0"
spotlessVersion = "6.23.3"

koin = "3.6.0-Beta4"
koinComposeMultiplatform = "1.2.0-Beta4"

sheets_compose_dialogs_core = "1.3.0"
secrets = "2.0.1"
truth = "1.4.2"
Expand All @@ -77,7 +81,14 @@ targetSdk = "34"
[bundles]
androidx-compose-ui-test = ["androidx-compose-ui-test", "androidx-compose-ui-test-manifest"]


[libraries]
koin-android = { module = "io.insert-koin:koin-android", version.ref = "koin" }
koin-androidx-compose = { module = "io.insert-koin:koin-androidx-compose", version.ref = "koin" }
koin-core = { module = "io.insert-koin:koin-core", version.ref = "koin" }
koin-compose = { module = "io.insert-koin:koin-compose", version.ref = "koinComposeMultiplatform" }
koin-compose-viewmodel = { module = "io.insert-koin:koin-compose-viewmodel", version.ref = "koinComposeMultiplatform" }

accompanist-pager = { module = "com.google.accompanist:accompanist-pager", version.ref = "accompanistPagerVersion" }

androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref = "activityVersion" }
Expand Down
15 changes: 15 additions & 0 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.jetbrainsCompose)
id("kotlin-parcelize")
}

kotlin {
Expand All @@ -50,10 +51,24 @@ kotlin {
}

sourceSets {
androidMain.dependencies {
implementation(compose.preview)
implementation(libs.androidx.activity.compose)

implementation(libs.koin.android)
implementation(libs.koin.androidx.compose)
}

commonMain.dependencies {
//put your multiplatform dependencies here
implementation(compose.material)
implementation(compose.material3)
implementation(libs.kotlinx.datetime)
implementation(libs.kotlinx.serialization.json)
implementation(libs.squareup.retrofit.converter.gson)
api(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.koin.compose.viewmodel)
}

val desktopMain by getting {
Expand Down
23 changes: 23 additions & 0 deletions shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.mifospay.shared

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContent {
App()
}
}
}

@Preview
@Composable
fun AppAndroidPreview() {
App()
}
15 changes: 15 additions & 0 deletions shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.mifospay.shared

import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.mifospay.shared.di.initKoin

class MyApplication: Application() {

override fun onCreate() {
super.onCreate()
initKoin {
androidContext(this@MyApplication)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
*/
package org.mifospay.shared

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

class AndroidPlatform : Platform {
override val name: String = "Android ${android.os.Build.VERSION.SDK_INT}"
}

actual fun getPlatform(): Platform = AndroidPlatform()

actual typealias CommonParcelize = Parcelize
actual typealias CommonParcelable = Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.mifospay.shared.di

import org.koin.dsl.module

actual val platformModule = module {

}
23 changes: 13 additions & 10 deletions shared/src/commonMain/kotlin/org/mifospay/shared/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,21 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import org.koin.compose.KoinContext

@Composable
fun App() {
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Text(
text = "MifosWallet",
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold),
color = MaterialTheme.colorScheme.onSurface,
)
KoinContext{
Box(
modifier = Modifier
.fillMaxSize(),
contentAlignment = Alignment.Center,
) {
Text(
text = "MifosWallet",
style = MaterialTheme.typography.titleLarge.copy(fontWeight = FontWeight.Bold),
color = MaterialTheme.colorScheme.onSurface,
)
}
}
}
10 changes: 10 additions & 0 deletions shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,13 @@ interface Platform {
}

expect fun getPlatform(): Platform

// For Android @Parcelize
@OptIn(ExperimentalMultiplatform::class)
@OptionalExpectation
@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.BINARY)
expect annotation class CommonParcelize()

// For Android Parcelable
expect interface CommonParcelable
10 changes: 10 additions & 0 deletions shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.mifospay.shared.di

import org.koin.core.module.Module
import org.koin.dsl.module

expect val platformModule: Module

val sharedModule = module {
single { }
}
11 changes: 11 additions & 0 deletions shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.mifospay.shared.di

import org.koin.core.context.startKoin
import org.koin.dsl.KoinAppDeclaration

fun initKoin(config: KoinAppDeclaration? = null) {
startKoin {
config?.invoke(this)
modules(sharedModule, platformModule)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.shared.modal.domain

import org.mifospay.shared.CommonParcelable
import org.mifospay.shared.CommonParcelize

@CommonParcelize
data class Client(
var name: String? = null,
var image: String,
var externalId: String? = null,
var clientId: Long = 0L,
var displayName: String,
var mobileNo: String,
) : CommonParcelable{
companion object
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.shared.modal.domain

import org.mifospay.shared.CommonParcelable
import org.mifospay.shared.CommonParcelize

@CommonParcelize
data class Role(
var id: String? = null,
var name: String? = null,
var description: String? = null,
val disabled: Boolean,
): CommonParcelable {
companion object
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 Mifos Initiative
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md
*/
package org.mifospay.shared.modal.domain

import org.mifospay.shared.CommonParcelable
import org.mifospay.shared.CommonParcelize

@CommonParcelize
data class User(
val username: String,
val userId: Long = 0,
val base64EncodedAuthenticationKey: String,
val authenticated: Boolean = false,
val officeId: Int,
val officeName: String,
val roles: List<Role>,
val permissions: List<String>,
val clients: List<Long>,
val shouldRenewPassword: Boolean,
val isTwoFactorAuthenticationRequired: Boolean,
): CommonParcelable {
companion object
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ class JVMPlatform : Platform {
}

actual fun getPlatform(): Platform = JVMPlatform()

actual interface CommonParcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifospay.shared.di

import org.koin.core.module.Module

actual val platformModule: Module
get() = TODO("Not yet implemented")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.mifospay.shared

import androidx.compose.ui.window.ComposeUIViewController
import org.mifospay.shared.di.initKoin

fun MainViewController() = ComposeUIViewController(
configure = {
initKoin()
}
) {
App()
}
2 changes: 2 additions & 0 deletions shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ class IOSPlatform : Platform {
}

actual fun getPlatform(): Platform = IOSPlatform()

actual interface CommonParcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mifospay.shared.di

import org.koin.core.module.Module

actual val platformModule: Module
get() = TODO("Not yet implemented")

0 comments on commit 99099ff

Please sign in to comment.