-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: [:core:common] KMP Migration (#1768)
* Feat: [:core:common] KMP Migration * Updated Usage Declaration
- Loading branch information
Showing
48 changed files
with
255 additions
and
179 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
core/common/src/androidMain/kotlin/org/mifospay/common/DebugUtil.kt
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
core/common/src/androidMain/kotlin/org/mifospay/common/FileUtils.kt
This file was deleted.
Oops, something went wrong.
34 changes: 0 additions & 34 deletions
34
core/common/src/androidMain/kotlin/org/mifospay/common/Utils.kt
This file was deleted.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
core/common/src/androidMain/kotlin/org/mifospay/core/common/FileUtils.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mifospay.core.common | ||
|
||
|
||
// JVM and Android implementation | ||
actual fun createPlatformFileUtils(): FileUtils = CommonFileUtils() |
17 changes: 17 additions & 0 deletions
17
core/common/src/androidMain/kotlin/org/mifospay/core/common/Utils.android.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mifospay.core.common | ||
|
||
import java.text.NumberFormat | ||
import java.util.Currency | ||
|
||
actual class CurrencyFormatter { | ||
actual fun format( | ||
balance: Double?, | ||
currencyCode: String?, | ||
maximumFractionDigits: Int?, | ||
): String { | ||
val balanceFormatter = NumberFormat.getCurrencyInstance() | ||
balanceFormatter.maximumFractionDigits = maximumFractionDigits ?: 0 | ||
balanceFormatter.currency = Currency.getInstance(currencyCode) | ||
return balanceFormatter.format(balance) | ||
} | ||
} |
23 changes: 0 additions & 23 deletions
23
core/common/src/androidMain/kotlin/org/mifospay/core/network/di/CoroutineScopesModule.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
core/common/src/commonMain/kotlin/org/mifospay/core/common/DebugUtil.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.core.common | ||
|
||
import co.touchlab.kermit.Logger | ||
|
||
object DebugUtil { | ||
|
||
private val logger = Logger.withTag("QXZ") | ||
|
||
fun log(vararg objects: Any): Array<out Any> { | ||
val stringToPrint = objects.joinToString(", ") | ||
logger.d { stringToPrint } | ||
return objects | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
core/common/src/commonMain/kotlin/org/mifospay/core/common/FileUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.mifospay.core.common | ||
|
||
import co.touchlab.kermit.Logger | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import okio.FileSystem | ||
import okio.Path.Companion.toPath | ||
import okio.SYSTEM | ||
|
||
|
||
interface FileUtils { | ||
suspend fun writeInputStreamDataToFile(inputStream: ByteArray, filePath: String): Boolean | ||
|
||
companion object { | ||
val logger = Logger.withTag("FileUtils") | ||
} | ||
} | ||
|
||
expect fun createPlatformFileUtils(): FileUtils | ||
|
||
class CommonFileUtils : FileUtils { | ||
override suspend fun writeInputStreamDataToFile( | ||
inputStream: ByteArray, | ||
filePath: String, | ||
): Boolean = | ||
withContext(Dispatchers.Default) { | ||
try { | ||
val path = filePath.toPath() | ||
FileSystem.SYSTEM.write(path) { | ||
write(inputStream) | ||
} | ||
|
||
true | ||
} catch (e: Exception) { | ||
FileUtils.logger.e { "Error writing file: ${e.message}" } | ||
false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
core/common/src/commonMain/kotlin/org/mifospay/core/common/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.mifospay.core.common | ||
|
||
expect class CurrencyFormatter { | ||
fun format(balance: Double?, currencyCode: String?, maximumFractionDigits: Int?): String | ||
} | ||
|
||
fun <T> List<T>.toArrayList(): ArrayList<T> { | ||
return ArrayList(this) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
core/common/src/jvmMain/kotlin/org/mifospay/core/common/FileUtils.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package org.mifospay.core.common | ||
|
||
// JVM and Android implementation | ||
actual fun createPlatformFileUtils(): FileUtils = CommonFileUtils() | ||
|
17 changes: 17 additions & 0 deletions
17
core/common/src/jvmMain/kotlin/org/mifospay/core/common/Utils.jvm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mifospay.core.common | ||
|
||
import java.text.NumberFormat | ||
import java.util.Currency | ||
|
||
actual class CurrencyFormatter { | ||
actual fun format( | ||
balance: Double?, | ||
currencyCode: String?, | ||
maximumFractionDigits: Int?, | ||
): String { | ||
val numberFormat = NumberFormat.getCurrencyInstance() | ||
numberFormat.maximumFractionDigits = maximumFractionDigits ?: 0 | ||
numberFormat.currency = Currency.getInstance(currencyCode) | ||
return numberFormat.format(balance) | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/common/src/nativeMain/kotlin/org/mifospay/core/common/FileUtils.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.mifospay.core.common | ||
|
||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.refTo | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
|
||
// iOS implementation | ||
@OptIn(ExperimentalForeignApi::class) | ||
actual fun createPlatformFileUtils(): FileUtils = object : FileUtils { | ||
override suspend fun writeInputStreamDataToFile(inputStream: ByteArray, filePath: String): Boolean = | ||
withContext(Dispatchers.Default) { | ||
try { | ||
val nsData = inputStream.toNSData() | ||
nsData.writeToFile(filePath, true) | ||
true | ||
} catch (e: Exception) { | ||
FileUtils.logger.e { "Error writing file: ${e.message}" } | ||
false | ||
} | ||
} | ||
|
||
private fun ByteArray.toNSData(): NSData = NSData.create(bytes = this.refTo(0), length = this.size.toULong()) | ||
} |
17 changes: 17 additions & 0 deletions
17
core/common/src/nativeMain/kotlin/org/mifospay/core/common/Utils.native.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.mifospay.core.common | ||
|
||
import platform.Foundation.NSNumberFormatter | ||
|
||
actual class CurrencyFormatter { | ||
actual fun format( | ||
balance: Double?, | ||
currencyCode: String?, | ||
maximumFractionDigits: Int?, | ||
): String { | ||
val numberFormatter = NSNumberFormatter() | ||
numberFormatter.numberStyle = NSNumberFormatterCurrencyStyle | ||
numberFormatter.currencyCode = currencyCode | ||
numberFormatter.maximumFractionDigits = maximumFractionDigits ?: 0 | ||
return numberFormatter.stringFromNumber(balance ?: 0.0) ?: "" | ||
} | ||
} |
Oops, something went wrong.