Initial koin setup for dependency injection (#1749)

* 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
This commit is contained in:
Aditya Kumdale 2024-08-27 06:39:14 +05:30 committed by GitHub
parent dc95c55df4
commit 99099fff49
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 229 additions and 10 deletions

View File

@ -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,

View File

@ -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"
@ -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" }

View File

@ -24,6 +24,7 @@ plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.compose.compiler)
alias(libs.plugins.jetbrainsCompose)
id("kotlin-parcelize")
}
kotlin {
@ -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 {

View File

@ -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()
}

View File

@ -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)
}
}
}

View File

@ -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

View File

@ -0,0 +1,7 @@
package org.mifospay.shared.di
import org.koin.dsl.module
actual val platformModule = module {
}

View File

@ -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,
)
}
}
}

View File

@ -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

View File

@ -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 { }
}

View File

@ -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)
}
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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
}

View File

@ -19,3 +19,5 @@ class JVMPlatform : Platform {
}
actual fun getPlatform(): Platform = JVMPlatform()
actual interface CommonParcelable

View File

@ -0,0 +1,6 @@
package org.mifospay.shared.di
import org.koin.core.module.Module
actual val platformModule: Module
get() = TODO("Not yet implemented")

View File

@ -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()
}

View File

@ -16,3 +16,5 @@ class IOSPlatform : Platform {
}
actual fun getPlatform(): Platform = IOSPlatform()
actual interface CommonParcelable

View File

@ -0,0 +1,6 @@
package org.mifospay.shared.di
import org.koin.core.module.Module
actual val platformModule: Module
get() = TODO("Not yet implemented")