diff --git a/build.gradle.kts b/build.gradle.kts index 68dd014bc..8431176ea 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,6 @@ plugins { alias(libs.plugins.android.application) apply false alias(libs.plugins.android.library) apply false alias(libs.plugins.android.test) apply false - alias(libs.plugins.compose.compiler) apply false alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.kotlin.parcelize) apply false @@ -30,6 +29,11 @@ plugins { // Plugin applied to allow module graph generation alias(libs.plugins.module.graph) apply true alias(libs.plugins.spotless) apply true + // Multiplatform plugins + alias(libs.plugins.jetbrainsCompose) apply false + alias(libs.plugins.compose.compiler) apply false + alias(libs.plugins.kotlinMultiplatform) apply false + alias(libs.plugins.wire) apply false } val detektFormatting = libs.detekt.formatting diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 60788599c..8acfbc853 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -62,10 +62,6 @@ 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" @@ -74,6 +70,12 @@ zxingVersion = "3.5.3" # Multiplatform Dependencies compose-plugin = "1.6.11" +koin = "3.6.0-Beta4" +koinComposeMultiplatform = "1.2.0-Beta4" + +datastore = "1.1.1" +wire = "5.0.0-alpha03" + compileSdk = "34" minSdk = "24" targetSdk = "34" @@ -201,6 +203,9 @@ truth = { group = "com.google.truth", name = "truth", version.ref = "truth" } detekt-formatting = { group = "io.gitlab.arturbosch.detekt", name = "detekt-formatting", version.ref = "detekt" } twitter-detekt-compose = { group = "com.twitter.compose.rules", name = "detekt", version.ref = "twitter-detekt-compose" } +#Multiplatform Libraries +datastore = { module = "androidx.datastore:datastore-core-okio", version.ref = "datastore" } + # Dependencies of the included build-logic android-gradlePlugin = { group = "com.android.tools.build", name = "gradle", version.ref = "androidGradlePlugin" } android-tools-common = { group = "com.android.tools", name = "common", version.ref = "androidTools" } @@ -233,12 +238,15 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } +kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } module-graph = { id = "com.jraska.module.graph.assertion", version.ref = "moduleGraph" } protobuf = { id = "com.google.protobuf", version.ref = "protobufPlugin" } roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" } room = { id = "androidx.room", version.ref = "room" } secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" } spotless = { id = "com.diffplug.spotless", version.ref = "spotlessVersion" } +# Multiplatform Plugins +wire = { id = "com.squareup.wire", version.ref = "wire" } # Plugins defined by this project mifospay-android-application = { id = "mifospay.android.application", version = "unspecified" } diff --git a/mifospay/build.gradle.kts b/mifospay/build.gradle.kts index f5b5c358e..ef519cd2b 100644 --- a/mifospay/build.gradle.kts +++ b/mifospay/build.gradle.kts @@ -65,6 +65,8 @@ android { } dependencies { + implementation(projects.shared) + implementation(projects.core.data) implementation(projects.core.ui) implementation(projects.core.designsystem) diff --git a/shared/build.gradle.kts b/shared/build.gradle.kts index 6e2e36b57..df9426c84 100644 --- a/shared/build.gradle.kts +++ b/shared/build.gradle.kts @@ -20,20 +20,19 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget * See https://github.com/openMF/mobile-wallet/blob/master/LICENSE.md */ plugins { - kotlin("multiplatform") + alias(libs.plugins.kotlinMultiplatform) alias(libs.plugins.android.library) alias(libs.plugins.compose.compiler) alias(libs.plugins.jetbrainsCompose) + alias(libs.plugins.wire) id("kotlin-parcelize") } kotlin { - jvmToolchain(21) - androidTarget { @OptIn(ExperimentalKotlinGradlePluginApi::class) - compilerOptions() { - jvmTarget = JvmTarget.JVM_1_8 + compilerOptions { + jvmTarget.set(JvmTarget.JVM_11) } } @@ -61,14 +60,20 @@ kotlin { commonMain.dependencies { //put your multiplatform dependencies here - implementation(compose.material) + implementation(compose.runtime) implementation(compose.material3) + implementation(compose.ui) + implementation(compose.components.resources) + implementation(compose.components.uiToolingPreview) + 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) + + implementation(libs.datastore) } val desktopMain by getting { @@ -82,14 +87,33 @@ kotlin { task("testClasses") } +wire { + kotlin {} + sourcePath { + srcDir("src/commonMain/proto") + } +} + android { namespace = "org.mifospay.shared" compileSdk = 34 + defaultConfig { minSdk = 24 } + + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } + compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + + dependencies { + debugImplementation(compose.uiTooling) } } diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt index acefcdb24..e65339b5a 100644 --- a/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/MainActivity.kt @@ -1,3 +1,12 @@ +/* + * 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 import android.os.Bundle @@ -20,4 +29,4 @@ class MainActivity : ComponentActivity() { @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 index 97d7c5de7..6fccb03bf 100644 --- a/shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt @@ -1,10 +1,19 @@ +/* + * 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 import android.app.Application import org.koin.android.ext.koin.androidContext import org.mifospay.shared.di.initKoin -class MyApplication: Application() { +class MyApplication : Application() { override fun onCreate() { super.onCreate() @@ -12,4 +21,4 @@ class MyApplication: Application() { 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 8b6bdb51a..909044b97 100644 --- a/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/Platform.android.kt @@ -19,4 +19,4 @@ class AndroidPlatform : Platform { actual fun getPlatform(): Platform = AndroidPlatform() actual typealias CommonParcelize = Parcelize -actual typealias CommonParcelable = Parcelable \ No newline at end of file +actual typealias CommonParcelable = Parcelable diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/di/AndroidPlatformContextProvider.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/di/AndroidPlatformContextProvider.kt new file mode 100644 index 000000000..9c6908224 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/di/AndroidPlatformContextProvider.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.di + +import android.content.Context + +object AndroidPlatformContextProvider { + private var appContext: Context? = null + + val context: Context? + get() = appContext + + fun setContext(context: Context) { + appContext = context + } +} 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 index ff4565bf5..8d463b4df 100644 --- a/shared/src/androidMain/kotlin/org/mifospay/shared/di/Modules.android.kt +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/di/Modules.android.kt @@ -1,7 +1,15 @@ +/* + * 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.di import org.koin.dsl.module actual val platformModule = module { - -} \ No newline at end of file +} diff --git a/shared/src/androidMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.android.kt b/shared/src/androidMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.android.kt new file mode 100644 index 000000000..153d180d6 --- /dev/null +++ b/shared/src/androidMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.android.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.preferences + +import androidx.datastore.core.DataStore +import okio.FileSystem +import okio.Path.Companion.toPath +import org.mifospay.shared.common.proto.UserPreferences +import org.mifospay.shared.di.AndroidPlatformContextProvider + +actual fun getDataStore(): DataStore { + val content = requireNotNull(AndroidPlatformContextProvider.context) + val producePath = { content.filesDir.resolve(DATA_STORE_FILE_NAME).absolutePath.toPath() } + + return createDataStore(fileSystem = FileSystem.SYSTEM, producePath = producePath) +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt index e78ba62f7..8e9fb5365 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/App.kt @@ -11,8 +11,8 @@ package org.mifospay.shared import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.material.Text import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -21,7 +21,7 @@ import org.koin.compose.KoinContext @Composable fun App() { - KoinContext{ + KoinContext { Box( modifier = Modifier .fillMaxSize(), diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt index 9e1cb142b..00ed0030d 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/Platform.kt @@ -23,4 +23,4 @@ expect fun getPlatform(): Platform expect annotation class CommonParcelize() // For Android Parcelable -expect interface CommonParcelable \ No newline at end of file +expect interface CommonParcelable diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/di/KoinModule.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/di/KoinModule.kt new file mode 100644 index 000000000..1af847cd6 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/di/KoinModule.kt @@ -0,0 +1,20 @@ +/* + * 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.di + +import org.koin.core.context.startKoin +import org.koin.dsl.KoinAppDeclaration + +fun initKoin(config: KoinAppDeclaration? = null) { + startKoin { + config?.invoke(this) + modules(sharedModule, platformModule) + } +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt index 8118b5804..9708d1fec 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt @@ -1,3 +1,12 @@ +/* + * 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.di import org.koin.core.module.Module @@ -6,5 +15,5 @@ import org.koin.dsl.module expect val platformModule: Module val sharedModule = module { - single { } -} \ No newline at end of file + single { } +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt deleted file mode 100644 index cc9e1d053..000000000 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 index f57b526ad..60f1e2d05 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Client.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Client.kt @@ -9,10 +9,6 @@ */ 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, @@ -20,6 +16,4 @@ data class Client( 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 index 197248545..29bd13e8d 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Role.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/Role.kt @@ -9,15 +9,9 @@ */ 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 index 86ebec769..dad50bcc7 100644 --- a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/User.kt +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/User.kt @@ -9,10 +9,6 @@ */ 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, @@ -25,6 +21,4 @@ data class User( val clients: List, val shouldRenewPassword: Boolean, val isTwoFactorAuthenticationRequired: Boolean, -): CommonParcelable { - companion object -} +) diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/UserData.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/UserData.kt new file mode 100644 index 000000000..4191ecd67 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/modal/domain/UserData.kt @@ -0,0 +1,17 @@ +/* + * 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 + +data class UserData( + val authToken: String, + val user: String, + val userEmail: String, + val client: String, +) diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.kt new file mode 100644 index 000000000..0b36f7879 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.kt @@ -0,0 +1,33 @@ +/* + * 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.preferences + +import androidx.datastore.core.DataStore +import androidx.datastore.core.DataStoreFactory +import androidx.datastore.core.okio.OkioStorage +import okio.FileSystem +import okio.Path +import org.mifospay.shared.common.proto.UserPreferences + +internal const val DATA_STORE_FILE_NAME = "user.preferences_pb" + +expect fun getDataStore(): DataStore + +fun createDataStore( + fileSystem: FileSystem, + producePath: () -> Path, +): DataStore = + DataStoreFactory.create( + storage = OkioStorage( + fileSystem = fileSystem, + producePath = producePath, + serializer = UserPreferenceSerializer, + ), + ) diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceRepository.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceRepository.kt new file mode 100644 index 000000000..a5ce0c182 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceRepository.kt @@ -0,0 +1,49 @@ +/* + * 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.preferences + +import androidx.datastore.core.DataStore +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map +import org.mifospay.shared.common.proto.UserPreferences +import org.mifospay.shared.modal.domain.UserData + +interface UserPreferenceRepository { + suspend fun updateUserConfig(userConfig: UserData) + + fun getUserConfig(): Flow +} + +class UserPreferenceRepositoryImpl( + private val dataStore: DataStore = getDataStore(), +) : UserPreferenceRepository { + + override suspend fun updateUserConfig(userConfig: UserData) { + dataStore.updateData { preferences -> + preferences.copy( + auth_token = userConfig.authToken, + user = userConfig.user, + user_email = userConfig.userEmail, + client = userConfig.client, + ) + } + } + + override fun getUserConfig(): Flow { + return dataStore.data.map { data -> + UserData( + authToken = data.auth_token, + user = data.user, + userEmail = data.user_email, + client = data.client, + ) + } + } +} diff --git a/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceSerializer.kt b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceSerializer.kt new file mode 100644 index 000000000..695a57e67 --- /dev/null +++ b/shared/src/commonMain/kotlin/org/mifospay/shared/preferences/UserPreferenceSerializer.kt @@ -0,0 +1,33 @@ +/* + * 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.preferences + +import androidx.datastore.core.okio.OkioSerializer +import okio.BufferedSink +import okio.BufferedSource +import okio.IOException +import org.mifospay.shared.common.proto.UserPreferences + +object UserPreferenceSerializer : OkioSerializer { + override val defaultValue: UserPreferences + get() = UserPreferences() + + override suspend fun readFrom(source: BufferedSource): UserPreferences { + try { + return UserPreferences.ADAPTER.decode(source) + } catch (exception: IOException) { + throw Exception(exception.message ?: "Serialization Exception") + } + } + + override suspend fun writeTo(t: UserPreferences, sink: BufferedSink) { + sink.write(t.encode()) + } +} diff --git a/shared/src/commonMain/proto/user_preferences.proto b/shared/src/commonMain/proto/user_preferences.proto new file mode 100644 index 000000000..f4008970f --- /dev/null +++ b/shared/src/commonMain/proto/user_preferences.proto @@ -0,0 +1,13 @@ +syntax = "proto3"; + +option java_package = "org.mifospay.shared.common.proto"; +option java_multiple_files = true; + +message UserPreferences { + string auth_token = 1; + string user = 2; + string user_email = 3; + string client = 4; + + // NEXT AVAILABLE ID: 5 +} 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 651f9f0bb..fcc74d588 100644 --- a/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt +++ b/shared/src/desktopMain/kotlin/org/mifospay/shared/Platform.desktop.kt @@ -20,4 +20,4 @@ class JVMPlatform : Platform { actual fun getPlatform(): Platform = JVMPlatform() -actual interface CommonParcelable \ No newline at end of file +actual interface CommonParcelable 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 index 81933fcf7..e7cbc9318 100644 --- a/shared/src/desktopMain/kotlin/org/mifospay/shared/di/Modules.desktop.kt +++ b/shared/src/desktopMain/kotlin/org/mifospay/shared/di/Modules.desktop.kt @@ -1,6 +1,15 @@ +/* + * 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.di import org.koin.core.module.Module actual val platformModule: Module - get() = TODO("Not yet implemented") \ No newline at end of file + get() = TODO("Not yet implemented") diff --git a/shared/src/desktopMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.desktop.kt b/shared/src/desktopMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.desktop.kt new file mode 100644 index 000000000..9b455f0f1 --- /dev/null +++ b/shared/src/desktopMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.desktop.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.preferences + +import androidx.datastore.core.DataStore +import okio.FileSystem +import okio.Path.Companion.toPath +import org.mifospay.shared.common.proto.UserPreferences +import java.io.File + +actual fun getDataStore(): DataStore { + val dbFile = File(System.getProperty("java.io.tmpdir"), DATA_STORE_FILE_NAME) + + return createDataStore( + fileSystem = FileSystem.SYSTEM, + producePath = { dbFile.absolutePath.toPath() }, + ) +} diff --git a/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt b/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt index 2b3c9bdc1..1f5f6765a 100644 --- a/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/MainViewController.kt @@ -1,12 +1,21 @@ +/* + * 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 import androidx.compose.ui.window.ComposeUIViewController import org.mifospay.shared.di.initKoin -fun MainViewController() = ComposeUIViewController( +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 7f17b0104..22fb77da7 100644 --- a/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/Platform.ios.kt @@ -17,4 +17,4 @@ class IOSPlatform : Platform { actual fun getPlatform(): Platform = IOSPlatform() -actual interface CommonParcelable \ No newline at end of file +actual interface CommonParcelable 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 index 81933fcf7..e7cbc9318 100644 --- a/shared/src/iosMain/kotlin/org/mifospay/shared/di/Modules.ios.kt +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/di/Modules.ios.kt @@ -1,6 +1,15 @@ +/* + * 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.di import org.koin.core.module.Module actual val platformModule: Module - get() = TODO("Not yet implemented") \ No newline at end of file + get() = TODO("Not yet implemented") diff --git a/shared/src/iosMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.ios.kt b/shared/src/iosMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.ios.kt new file mode 100644 index 000000000..7d9e5ebbc --- /dev/null +++ b/shared/src/iosMain/kotlin/org/mifospay/shared/preferences/DataStoreModule.ios.kt @@ -0,0 +1,33 @@ +/* + * 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.preferences + +import androidx.datastore.core.DataStore +import okio.FileSystem +import okio.Path.Companion.toPath +import org.mifospay.shared.common.proto.UserPreferences + +actual fun getDataStore(): DataStore { + return createDataStore( + fileSystem = FileSystem.SYSTEM, + producePath = { "${documentDirectory()}/$DATA_STORE_FILE_NAME".toPath() }, + ) +} + +private fun documentDirectory(): String { + val documentDirectory = NSFileManager.defaultManager.URLForDirectory( + directory = NSDocumentDirectory, + inDomain = NSUserDomainMask, + appropriateForURL = null, + create = false, + error = null, + ) + return requireNotNull(documentDirectory?.path) +}