mirror of
https://github.com/openMF/mobile-wallet.git
synced 2026-02-06 11:07:02 +00:00
Completed proto datastore implementation (#1754)
* Proto Datastore Setup for KMM * Completed proto datastore implementation --------- Co-authored-by: Sk Niyaj Ali <niyaj639@gmail.com>
This commit is contained in:
parent
99099fff49
commit
acca07ac4c
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
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" }
|
||||
|
||||
@ -65,6 +65,8 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.shared)
|
||||
|
||||
implementation(projects.core.data)
|
||||
implementation(projects.core.ui)
|
||||
implementation(projects.core.designsystem)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -34,6 +34,7 @@
|
||||
:libs:material3-navigation
|
||||
:libs:mifos-passcode
|
||||
:libs:pullrefresh
|
||||
:shared
|
||||
androidx.activity:activity-compose:1.9.1
|
||||
androidx.activity:activity-ktx:1.9.1
|
||||
androidx.activity:activity:1.9.1
|
||||
@ -128,7 +129,8 @@ androidx.drawerlayout:drawerlayout:1.0.0
|
||||
androidx.emoji2:emoji2-views-helper:1.3.0
|
||||
androidx.emoji2:emoji2:1.3.0
|
||||
androidx.exifinterface:exifinterface:1.3.7
|
||||
androidx.fragment:fragment:1.5.7
|
||||
androidx.fragment:fragment-ktx:1.7.1
|
||||
androidx.fragment:fragment:1.7.1
|
||||
androidx.graphics:graphics-path:1.0.1
|
||||
androidx.hilt:hilt-navigation-compose:1.2.0
|
||||
androidx.hilt:hilt-navigation:1.2.0
|
||||
@ -182,6 +184,12 @@ androidx.window.extensions.core:core:1.0.0
|
||||
androidx.window:window-core-android:1.3.0-rc01
|
||||
androidx.window:window-core:1.3.0-rc01
|
||||
androidx.window:window:1.3.0-rc01
|
||||
co.touchlab:stately-concurrency-jvm:2.0.6
|
||||
co.touchlab:stately-concurrency:2.0.6
|
||||
co.touchlab:stately-concurrent-collections-jvm:2.0.6
|
||||
co.touchlab:stately-concurrent-collections:2.0.6
|
||||
co.touchlab:stately-strict-jvm:2.0.6
|
||||
co.touchlab:stately-strict:2.0.6
|
||||
com.google.accompanist:accompanist-drawablepainter:0.32.0
|
||||
com.google.accompanist:accompanist-pager:0.34.0
|
||||
com.google.android.datatransport:transport-api:3.2.0
|
||||
@ -255,22 +263,43 @@ com.maxkeppeler.sheets-compose-dialogs:calendar:1.3.0
|
||||
com.maxkeppeler.sheets-compose-dialogs:core:1.3.0
|
||||
com.squareup.okhttp3:logging-interceptor:4.12.0
|
||||
com.squareup.okhttp3:okhttp:4.12.0
|
||||
com.squareup.okio:okio-jvm:3.8.0
|
||||
com.squareup.okio:okio:3.8.0
|
||||
com.squareup.okio:okio-jvm:3.9.0
|
||||
com.squareup.okio:okio:3.9.0
|
||||
com.squareup.retrofit2:adapter-rxjava:2.11.0
|
||||
com.squareup.retrofit2:converter-gson:2.11.0
|
||||
com.squareup.retrofit2:retrofit:2.11.0
|
||||
com.squareup.wire:wire-runtime-jvm:5.0.0
|
||||
com.squareup.wire:wire-runtime:5.0.0
|
||||
dev.chrisbanes.snapper:snapper:0.3.0
|
||||
io.coil-kt:coil-base:2.6.0
|
||||
io.coil-kt:coil-compose-base:2.6.0
|
||||
io.coil-kt:coil-compose:2.6.0
|
||||
io.coil-kt:coil:2.6.0
|
||||
io.insert-koin:koin-android:3.6.0-Beta4
|
||||
io.insert-koin:koin-androidx-compose:3.6.0-Beta4
|
||||
io.insert-koin:koin-compose-jvm:1.2.0-Beta4
|
||||
io.insert-koin:koin-compose-viewmodel-jvm:1.2.0-Beta4
|
||||
io.insert-koin:koin-compose-viewmodel:1.2.0-Beta4
|
||||
io.insert-koin:koin-compose:1.2.0-Beta4
|
||||
io.insert-koin:koin-core-jvm:3.6.0-Beta4
|
||||
io.insert-koin:koin-core:3.6.0-Beta4
|
||||
io.michaelrocks:libphonenumber-android:8.13.35
|
||||
io.reactivex:rxandroid:1.1.0
|
||||
io.reactivex:rxjava:1.3.8
|
||||
jakarta.inject:jakarta.inject-api:2.0.1
|
||||
javax.inject:javax.inject:1
|
||||
org.checkerframework:checker-qual:3.12.0
|
||||
org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose:2.8.0-rc03
|
||||
org.jetbrains.androidx.navigation:navigation-compose:2.7.0-alpha06
|
||||
org.jetbrains.compose.components:components-resources-android:1.6.11
|
||||
org.jetbrains.compose.components:components-resources:1.6.11
|
||||
org.jetbrains.compose.components:components-ui-tooling-preview-android:1.6.11
|
||||
org.jetbrains.compose.components:components-ui-tooling-preview:1.6.11
|
||||
org.jetbrains.compose.foundation:foundation:1.6.11
|
||||
org.jetbrains.compose.material3:material3:1.6.11
|
||||
org.jetbrains.compose.runtime:runtime:1.6.11
|
||||
org.jetbrains.compose.ui:ui-tooling-preview:1.6.11
|
||||
org.jetbrains.compose.ui:ui:1.6.11
|
||||
org.jetbrains.kotlin:kotlin-android-extensions-runtime:2.0.20
|
||||
org.jetbrains.kotlin:kotlin-parcelize-runtime:2.0.20
|
||||
org.jetbrains.kotlin:kotlin-stdlib-common:2.0.20
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,4 +19,4 @@ class AndroidPlatform : Platform {
|
||||
actual fun getPlatform(): Platform = AndroidPlatform()
|
||||
|
||||
actual typealias CommonParcelize = Parcelize
|
||||
actual typealias CommonParcelable = Parcelable
|
||||
actual typealias CommonParcelable = Parcelable
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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.commonMain.proto.UserPreferences
|
||||
import org.mifospay.shared.di.AndroidPlatformContextProvider
|
||||
|
||||
actual fun getDataStore(): DataStore<UserPreferences> {
|
||||
val content = requireNotNull(AndroidPlatformContextProvider.context)
|
||||
val producePath = { content.filesDir.resolve(DATA_STORE_FILE_NAME).absolutePath.toPath() }
|
||||
|
||||
return createDataStore(fileSystem = FileSystem.SYSTEM, producePath = producePath)
|
||||
}
|
||||
@ -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(),
|
||||
|
||||
@ -23,4 +23,4 @@ expect fun getPlatform(): Platform
|
||||
expect annotation class CommonParcelize()
|
||||
|
||||
// For Android Parcelable
|
||||
expect interface CommonParcelable
|
||||
expect interface CommonParcelable
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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 { }
|
||||
}
|
||||
single { }
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
@ -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
|
||||
}
|
||||
)
|
||||
|
||||
@ -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<Long>,
|
||||
val shouldRenewPassword: Boolean,
|
||||
val isTwoFactorAuthenticationRequired: Boolean,
|
||||
): CommonParcelable {
|
||||
companion object
|
||||
}
|
||||
)
|
||||
|
||||
@ -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,
|
||||
)
|
||||
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.commonMain.proto.UserPreferences
|
||||
internal const val DATA_STORE_FILE_NAME = "user.preferences_pb"
|
||||
|
||||
expect fun getDataStore(): DataStore<UserPreferences>
|
||||
|
||||
fun createDataStore(
|
||||
fileSystem: FileSystem,
|
||||
producePath: () -> Path,
|
||||
): DataStore<UserPreferences> =
|
||||
DataStoreFactory.create(
|
||||
storage = OkioStorage(
|
||||
fileSystem = fileSystem,
|
||||
producePath = producePath,
|
||||
serializer = UserPreferenceSerializer,
|
||||
),
|
||||
)
|
||||
@ -0,0 +1,169 @@
|
||||
/*
|
||||
* 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.commonMain.proto.Client
|
||||
import org.mifospay.shared.commonMain.proto.User
|
||||
import org.mifospay.shared.commonMain.proto.UserPreferences
|
||||
|
||||
interface UserPreferenceRepository {
|
||||
suspend fun saveToken(token: String)
|
||||
fun getToken(): Flow<String>
|
||||
suspend fun saveFullName(name: String)
|
||||
fun getFullName(): Flow<String>
|
||||
suspend fun saveUsername(name: String)
|
||||
fun getUsername(): Flow<String>
|
||||
suspend fun saveEmail(email: String)
|
||||
fun getEmail(): Flow<String>
|
||||
suspend fun saveMobile(mobile: String)
|
||||
fun getMobile(): Flow<String>
|
||||
fun getUserId(): Flow<Int>
|
||||
suspend fun setUserId(id: Int)
|
||||
fun getClientId(): Flow<Int>
|
||||
suspend fun setClientId(clientId: Int)
|
||||
fun getClientVpa(): Flow<String>
|
||||
suspend fun setClientVpa(vpa: String)
|
||||
fun getAccountId(): Flow<Int>
|
||||
suspend fun setAccountId(accountId: Int)
|
||||
fun getFirebaseRegId(): Flow<String>
|
||||
suspend fun setFirebaseRegId(firebaseRegId: String)
|
||||
fun getUser(): Flow<User>
|
||||
suspend fun setUser(user: User)
|
||||
fun getClient(): Flow<Client>
|
||||
suspend fun setClient(client: Client)
|
||||
}
|
||||
|
||||
class UserPreferenceRepositoryImpl(
|
||||
private val dataStore: DataStore<UserPreferences> = getDataStore(),
|
||||
) : UserPreferenceRepository {
|
||||
|
||||
override suspend fun saveToken(token: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(token = token)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getToken(): Flow<String> {
|
||||
return dataStore.data.map { it.token }
|
||||
}
|
||||
|
||||
override suspend fun saveFullName(name: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(name = name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFullName(): Flow<String> {
|
||||
return dataStore.data.map { it.name }
|
||||
}
|
||||
|
||||
override suspend fun saveUsername(name: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(username = name)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getUsername(): Flow<String> {
|
||||
return dataStore.data.map { it.username }
|
||||
}
|
||||
|
||||
override suspend fun saveEmail(email: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(email = email)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getEmail(): Flow<String> {
|
||||
return dataStore.data.map { it.email }
|
||||
}
|
||||
|
||||
override suspend fun saveMobile(mobile: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(mobile_no = mobile)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getMobile(): Flow<String> {
|
||||
return dataStore.data.map { it.mobile_no }
|
||||
}
|
||||
|
||||
override fun getUserId(): Flow<Int> {
|
||||
return dataStore.data.map { it.user_id }
|
||||
}
|
||||
|
||||
override suspend fun setUserId(id: Int) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(user_id = id)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClientId(): Flow<Int> {
|
||||
return dataStore.data.map { it.client_id }
|
||||
}
|
||||
|
||||
override suspend fun setClientId(clientId: Int) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(client_id = clientId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClientVpa(): Flow<String> {
|
||||
return dataStore.data.map { it.client_vpa }
|
||||
}
|
||||
|
||||
override suspend fun setClientVpa(vpa: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(client_vpa = vpa)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getAccountId(): Flow<Int> {
|
||||
return dataStore.data.map { it.account_id }
|
||||
}
|
||||
|
||||
override suspend fun setAccountId(accountId: Int) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(account_id = accountId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getFirebaseRegId(): Flow<String> {
|
||||
return dataStore.data.map { it.firebase_reg_id }
|
||||
}
|
||||
|
||||
override suspend fun setFirebaseRegId(firebaseRegId: String) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(firebase_reg_id = firebaseRegId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getUser(): Flow<User> {
|
||||
return dataStore.data.map { it.user!! }
|
||||
}
|
||||
|
||||
override suspend fun setUser(user: User) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(user = user)
|
||||
}
|
||||
}
|
||||
|
||||
override fun getClient(): Flow<Client> {
|
||||
return dataStore.data.map { it.client!! }
|
||||
}
|
||||
|
||||
override suspend fun setClient(client: Client) {
|
||||
dataStore.updateData { preferences ->
|
||||
preferences.copy(client = client)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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.commonMain.proto.UserPreferences
|
||||
|
||||
object UserPreferenceSerializer : OkioSerializer<UserPreferences> {
|
||||
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())
|
||||
}
|
||||
}
|
||||
49
shared/src/commonMain/proto/user_preferences.proto
Normal file
49
shared/src/commonMain/proto/user_preferences.proto
Normal file
@ -0,0 +1,49 @@
|
||||
syntax = "proto3";
|
||||
|
||||
option java_package = "org.mifospay.shared.commonMain.proto";
|
||||
option java_multiple_files = true;
|
||||
|
||||
message UserPreferences {
|
||||
string token = 1;
|
||||
string name = 2;
|
||||
string username = 3;
|
||||
string email = 4;
|
||||
string mobile_no = 5;
|
||||
int32 user_id = 6;
|
||||
int32 client_id = 7;
|
||||
string client_vpa = 8;
|
||||
int32 account_id = 9;
|
||||
string firebase_reg_id = 10;
|
||||
Client client = 11;
|
||||
User user = 12;
|
||||
}
|
||||
|
||||
message Client {
|
||||
string name = 1;
|
||||
string image = 2;
|
||||
string external_id = 3;
|
||||
int64 clientId = 4;
|
||||
string display_name = 5;
|
||||
string mobileNo = 6;
|
||||
}
|
||||
|
||||
message User {
|
||||
string username = 1;
|
||||
int64 userId = 2;
|
||||
string base64EncodedAuthenticationKey = 3;
|
||||
bool authenticated = 4;
|
||||
int32 officeId = 5;
|
||||
string officeName = 6;
|
||||
repeated Role roles = 7;
|
||||
repeated string permissions = 8;
|
||||
repeated int64 clients = 9;
|
||||
bool shouldRenewPassword = 10;
|
||||
bool isTwoFactorAuthenticationRequired = 11;
|
||||
}
|
||||
|
||||
message Role {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string description = 3;
|
||||
bool disabled = 4;
|
||||
}
|
||||
@ -20,4 +20,4 @@ class JVMPlatform : Platform {
|
||||
|
||||
actual fun getPlatform(): Platform = JVMPlatform()
|
||||
|
||||
actual interface CommonParcelable
|
||||
actual interface CommonParcelable
|
||||
|
||||
@ -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")
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
@ -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.commonMain.proto.UserPreferences
|
||||
import java.io.File
|
||||
|
||||
actual fun getDataStore(): DataStore<UserPreferences> {
|
||||
val dbFile = File(System.getProperty("java.io.tmpdir"), DATA_STORE_FILE_NAME)
|
||||
|
||||
return createDataStore(
|
||||
fileSystem = FileSystem.SYSTEM,
|
||||
producePath = { dbFile.absolutePath.toPath() },
|
||||
)
|
||||
}
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,4 +17,4 @@ class IOSPlatform : Platform {
|
||||
|
||||
actual fun getPlatform(): Platform = IOSPlatform()
|
||||
|
||||
actual interface CommonParcelable
|
||||
actual interface CommonParcelable
|
||||
|
||||
@ -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")
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
@ -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.commonMain.proto.UserPreferences
|
||||
|
||||
actual fun getDataStore(): DataStore<UserPreferences> {
|
||||
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)
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user