Skip to content

Commit

Permalink
feat(core:model): Migrate model module to KMP (#2732)
Browse files Browse the repository at this point in the history
* feat(core:model): Migrate model module to KMP

* Change properties from var to val and remove unnecessary annotations

* remove inheritance of Account in ShareAccount, SavingAccount and LoanAccount

* replace ArrayList() with emptyList() and improve numeric literal consistency
  • Loading branch information
HekmatullahAmin authored Jan 10, 2025
1 parent 174ccd2 commit cb3975c
Show file tree
Hide file tree
Showing 177 changed files with 2,276 additions and 2,427 deletions.
27 changes: 12 additions & 15 deletions core/model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
*/
plugins {
alias(libs.plugins.mifos.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.mifos.kmp.library)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.kotlin.parcelize)
}
Expand All @@ -21,17 +20,15 @@ android {
}
}

dependencies {

api(projects.core.common)

implementation(libs.jetbrains.kotlin.jdk7)
implementation(libs.kotlinx.serialization.json)

// For Serialized name
implementation(libs.squareup.retrofit.converter.gson)

testImplementation(libs.junit)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.androidx.test.espresso.core)
kotlin {
androidTarget {
compilerOptions {
freeCompilerArgs.addAll("-P", "plugin:org.jetbrains.kotlin.parcelize:additionalAnnotation=org.mifos.mobile.core.model.Parcelize")
}
}
sourceSets {
commonMain.dependencies {
implementation(libs.kotlinx.serialization.json)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2025 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-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.model

import android.os.Parcelable
import kotlinx.parcelize.IgnoredOnParcel
import kotlinx.parcelize.RawValue

actual typealias Parcelable = Parcelable

actual typealias IgnoredOnParcel = IgnoredOnParcel

actual typealias RawValue = RawValue
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright 2025 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-mobile/blob/master/LICENSE.md
*/
package org.mifos.mobile.core.model

annotation class Parcelize()

expect interface Parcelable

expect annotation class IgnoredOnParcel()

@Target(AnnotationTarget.TYPE)
expect annotation class RawValue()
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

@Parcelize
data class Charge(
val clientId: Int? = null,
val chargeId: Int? = null,
val name: String? = null,
val dueDate: ArrayList<Int?> = ArrayList(),
val dueDate: ArrayList<Int?> = arrayListOf(),
val chargeTimeType: ChargeTimeType? = null,
val chargeCalculationType: ChargeCalculationType? = null,
val currency: Currency? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

@Parcelize
@Serializable
data class ChargeCalculationType(
var id: Int = 0,
var code: String? = null,
var value: String? = null,
val id: Int = 0,
val code: String? = null,
val value: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

/**
* Created by michaelsosnick on 12/11/16.
*/

@Parcelize
data class ChargeTimeType(
var id: Int = 0,
var code: String? = null,
var value: String? = null,
val id: Int = 0,
val code: String? = null,
val value: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ package org.mifos.mobile.core.model.entity
* Created by dilpreet on 3/7/17.
*/

data class CheckboxStatus @JvmOverloads constructor(
var status: String?,
var color: Int,
var isChecked: Boolean = false,
data class CheckboxStatus(
val status: String?,
val color: Int,
val isChecked: Boolean = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

/**
* Created by michaelsosnick on 12/11/16.
*/

@Parcelize
data class Currency(
var code: String? = null,
var name: String? = null,
var decimalPlaces: Int = 0,
var displaySymbol: String? = null,
var nameCode: String? = null,
var displayLabel: String? = null,
val code: String? = null,
val name: String? = null,
val decimalPlaces: Int = 0,
val displaySymbol: String? = null,
val nameCode: String? = null,
val displayLabel: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

/**
* Created by dilpreet on 12/8/17.
*/

@Parcelize
data class FAQ @JvmOverloads constructor(
var question: String? = null,
var answer: String? = null,
var isSelected: Boolean = false,
data class FAQ constructor(
val question: String? = null,
val answer: String? = null,
val isSelected: Boolean = false,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

@Parcelize
@Serializable
data class MifosNotification(
var timeStamp: Long,
var msg: String? = null,
var read: Boolean? = null,
val timeStamp: Long,
val msg: String? = null,
val read: Boolean? = null,
) : Parcelable {
fun isRead(): Boolean {
return read == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ package org.mifos.mobile.core.model.entity
*/
data class Page<T>(

var totalFilteredRecords: Int = 0,
var pageItems: List<T> = ArrayList(),
val totalFilteredRecords: Int = 0,
val pageItems: List<T> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

/**
* Created by ishankhanna for mifos android-client on 09/02/14.
Expand All @@ -24,16 +24,16 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class Timeline(
var submittedOnDate: List<Int> = ArrayList(),
var submittedByUsername: String? = null,
var submittedByFirstname: String? = null,
var submittedByLastname: String? = null,
var activatedOnDate: List<Int> = ArrayList(),
var activatedByUsername: String? = null,
var activatedByFirstname: String? = null,
var activatedByLastname: String? = null,
var closedOnDate: List<Int> = ArrayList(),
var closedByUsername: String? = null,
var closedByFirstname: String? = null,
var closedByLastname: String? = null,
val submittedOnDate: List<Int> = emptyList(),
val submittedByUsername: String? = null,
val submittedByFirstname: String? = null,
val submittedByLastname: String? = null,
val activatedOnDate: List<Int> = emptyList(),
val activatedByUsername: String? = null,
val activatedByFirstname: String? = null,
val activatedByLastname: String? = null,
val closedOnDate: List<Int> = emptyList(),
val closedByUsername: String? = null,
val closedByFirstname: String? = null,
val closedByLastname: String? = null,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize
import org.mifos.mobile.core.model.entity.client.Type

/**
Expand All @@ -21,22 +21,22 @@ import org.mifos.mobile.core.model.entity.client.Type
@Parcelize
data class Transaction(

var id: Long? = null,
val id: Long? = null,

var officeId: Long? = null,
val officeId: Long? = null,

var officeName: String? = null,
val officeName: String? = null,

var type: Type,
val type: Type,

var date: List<Int> = ArrayList(),
val date: List<Int> = emptyList(),

var currency: Currency? = null,
val currency: Currency? = null,

var amount: Double? = null,
val amount: Double? = null,

var submittedOnDate: List<Int> = ArrayList(),
val submittedOnDate: List<Int> = emptyList(),

var reversed: Boolean? = null,
val reversed: Boolean? = null,

) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ package org.mifos.mobile.core.model.entity
*/
class UpdatePasswordPayload {

var password: String? = null
val password: String? = null

var repeatPassword: String? = null
val repeatPassword: String? = null
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
package org.mifos.mobile.core.model.entity

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.SerialName
import org.mifos.mobile.core.model.Parcelable
import org.mifos.mobile.core.model.Parcelize

/**
* @author Vishwajeet
Expand All @@ -20,26 +20,26 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class User(
val userId: Long = 0,
@SerializedName("authenticated")
@SerialName("authenticated")
val isAuthenticated: Boolean = false,
val username: String? = null,
val officeId: Long = 0,
val officeName: String? = null,
val roles: ArrayList<Role> = ArrayList(),
val roles: ArrayList<Role> = arrayListOf(),
val base64EncodedAuthenticationKey: String? = null,
val permissions: ArrayList<String> = ArrayList(),
val permissions: ArrayList<String> = arrayListOf(),
val shouldRenewPassword: Boolean = false,
val isTwoFactorAuthenticationRequired: Boolean = false,
) : Parcelable

@Parcelize
data class Role(
@SerializedName("id")
@SerialName("id")
val id: Long = 0,
@SerializedName("name")
@SerialName("name")
val name: String? = null,
@SerializedName("description")
@SerialName("description")
val description: String? = null,
@SerializedName("disabled")
@SerialName("disabled")
val disabled: Boolean = false,
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ package org.mifos.mobile.core.model.entity.accounts
import org.mifos.mobile.core.model.entity.accounts.loan.LoanAccount

data class LoanAccountsListResponse(
var loanAccounts: List<LoanAccount> = ArrayList(),
val loanAccounts: List<LoanAccount> = emptyList(),
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ package org.mifos.mobile.core.model.entity.accounts
import org.mifos.mobile.core.model.entity.accounts.savings.SavingAccount

data class SavingAccountsListResponse(
var savingsAccounts: List<SavingAccount> = ArrayList(),
val savingsAccounts: List<SavingAccount> = emptyList(),
)
Loading

0 comments on commit cb3975c

Please sign in to comment.