Skip to content

Commit

Permalink
Proto Datastore Setup for KMM
Browse files Browse the repository at this point in the history
  • Loading branch information
niyajali committed Aug 27, 2024
1 parent 99099ff commit 854db36
Show file tree
Hide file tree
Showing 30 changed files with 404 additions and 64 deletions.
6 changes: 5 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 12 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down
2 changes: 2 additions & 0 deletions mifospay/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ android {
}

dependencies {
implementation(projects.shared)

implementation(projects.core.data)
implementation(projects.core.ui)
implementation(projects.core.designsystem)
Expand Down
42 changes: 33 additions & 9 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,4 +29,4 @@ class MainActivity : ComponentActivity() {
@Composable
fun AppAndroidPreview() {
App()
}
}
13 changes: 11 additions & 2 deletions shared/src/androidMain/kotlin/org/mifospay/shared/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
/*
* 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()
initKoin {
androidContext(this@MyApplication)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ class AndroidPlatform : Platform {
actual fun getPlatform(): Platform = AndroidPlatform()

actual typealias CommonParcelize = Parcelize
actual typealias CommonParcelable = Parcelable
actual typealias CommonParcelable = Parcelable
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.di

import android.content.Context

object AndroidPlatformContextProvider {
private var appContext: Context? = null

val context: Context?
get() = appContext

fun setContext(context: Context) {
appContext = context
}
}
Original file line number Diff line number Diff line change
@@ -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 {

}
}
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.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<UserPreferences> {
val content = requireNotNull(AndroidPlatformContextProvider.context)
val producePath = { content.filesDir.resolve(DATA_STORE_FILE_NAME).absolutePath.toPath() }

return createDataStore(fileSystem = FileSystem.SYSTEM, producePath = producePath)
}
4 changes: 2 additions & 2 deletions shared/src/commonMain/kotlin/org/mifospay/shared/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@ import org.koin.compose.KoinContext

@Composable
fun App() {
KoinContext{
KoinContext {
Box(
modifier = Modifier
.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ expect fun getPlatform(): Platform
expect annotation class CommonParcelize()

// For Android Parcelable
expect interface CommonParcelable
expect interface CommonParcelable
20 changes: 20 additions & 0 deletions shared/src/commonMain/kotlin/org/mifospay/shared/di/KoinModule.kt
Original file line number Diff line number Diff line change
@@ -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)
}
}
13 changes: 11 additions & 2 deletions shared/src/commonMain/kotlin/org/mifospay/shared/di/Modules.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -6,5 +15,5 @@ import org.koin.dsl.module
expect val platformModule: Module

val sharedModule = module {
single { }
}
single { }
}
11 changes: 0 additions & 11 deletions shared/src/commonMain/kotlin/org/mifospay/shared/di/initKoin.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
*/
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
}
)
Loading

0 comments on commit 854db36

Please sign in to comment.