diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt index 4804014a6..da0e58814 100644 --- a/desktop/src/jvmMain/kotlin/Main.kt +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -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, diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 83b58e0de..60788599c 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 2e34947f4..6e2e36b57 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -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 { diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt new file mode 100644 index 000000000..acefcdb24 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt @@ -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() +} \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt new file mode 100644 index 000000000..97d7c5de7 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt index aa1c6061d..8b6bdb51a 100644 --- a/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt @@ -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 \ No newline at end of file diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/di/Modules.android.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/di/Modules.android.kt new file mode 100644 index 000000000..ff4565bf5 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/di/Modules.android.kt @@ -0,0 +1,7 @@ +package org.mifospay.shared.di + +import org.koin.dsl.module + +actual val platformModule = module { + +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt index 878509f2b..e78ba62f7 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt @@ -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, + ) + } } } diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt index a91487eaa..9e1cb142b 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt @@ -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 \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt new file mode 100644 index 000000000..8118b5804 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt @@ -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 { } +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt new file mode 100644 index 000000000..cc9e1d053 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt @@ -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) + } +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Client.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Client.kt new file mode 100644 index 000000000..f57b526ad --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Client.kt @@ -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 +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Role.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Role.kt new file mode 100644 index 000000000..197248545 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Role.kt @@ -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 +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/User.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/User.kt new file mode 100644 index 000000000..86ebec769 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/User.kt @@ -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, + val permissions: List, + val clients: List, + val shouldRenewPassword: Boolean, + val isTwoFactorAuthenticationRequired: Boolean, +): CommonParcelable { + companion object +} diff --git a/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt b/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt index 7ee8e94f4..651f9f0bb 100644 --- a/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt +++ b/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt @@ -19,3 +19,5 @@ class JVMPlatform : Platform { } actual fun getPlatform(): Platform = JVMPlatform() + +actual interface CommonParcelable \ No newline at end of file diff --git a/shared/src/desktopMain/kotlin/org/mifospay/shared/di/Modules.desktop.kt b/shared/src/desktopMain/kotlin/org/mifospay/shared/di/Modules.desktop.kt new file mode 100644 index 000000000..81933fcf7 --- /dev/null +++ b/shared/src/desktopMain/kotlin/org/mifospay/shared/di/Modules.desktop.kt @@ -0,0 +1,6 @@ +package org.mifospay.shared.di + +import org.koin.core.module.Module + +actual val platformModule: Module + get() = TODO("Not yet implemented") \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt b/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt new file mode 100644 index 000000000..2b3c9bdc1 --- /dev/null +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt @@ -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() +} \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt b/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt index 26a133df8..7f17b0104 100644 --- a/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt @@ -16,3 +16,5 @@ class IOSPlatform : Platform { } actual fun getPlatform(): Platform = IOSPlatform() + +actual interface CommonParcelable \ No newline at end of file diff --git a/shared/src/iosMain/kotlin/org/mifospay/shared/di/Modules.ios.kt b/shared/src/iosMain/kotlin/org/mifospay/shared/di/Modules.ios.kt new file mode 100644 index 000000000..81933fcf7 --- /dev/null +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/di/Modules.ios.kt @@ -0,0 +1,6 @@ +package org.mifospay.shared.di + +import org.koin.core.module.Module + +actual val platformModule: Module + get() = TODO("Not yet implemented") \ No newline at end of file