Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions cmp-android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,19 @@

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
android:grantUriPermissions="true"
tools:replace="android:authorities">

<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/fileproviderpath" />
android:resource="@xml/file_paths"
tools:replace="android:resource" />
</provider>



<!-- Disable Firebase analytics by default. This setting is overwritten for the `prod` flavor -->
<meta-data
android:name="firebase_analytics_collection_deactivated"
Expand Down
8 changes: 8 additions & 0 deletions cmp-shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,18 @@ kotlin {
implementation(libs.koin.compose.viewmodel)
}







desktopMain.dependencies {
// Desktop specific dependencies
implementation(compose.desktop.currentOs)
implementation(compose.desktop.common)


}
}
}
7 changes: 7 additions & 0 deletions cmp-shared/src/commonMain/kotlin/cmp/shared/SharedApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import cmp.navigation.ComposeApp



@Composable
fun SharedApp(
modifier: Modifier = Modifier,
) {
ComposeApp(modifier)

}




1 change: 1 addition & 0 deletions feature/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ kotlin {
implementation(libs.coil.network.okhttp)
implementation(libs.play.services.location)
implementation(libs.kotlinx.coroutines.play.services)
// implementation("io.github.swapnil-musale:kmp-pdf-viewer:1.0.3")
}
}
}
Expand Down
13 changes: 13 additions & 0 deletions feature/client/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,18 @@
android:name="com.google.android.geo.API_KEY"
android:value="@string/feature_client_pinpoint_google_maps_key" />

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

</application>



</manifest>
4 changes: 4 additions & 0 deletions feature/client/src/androidMain/res/xml/file_paths.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="external_files" path="." />
</paths>
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ internal fun ClientDetailsScreen(
uploadImage = {
galleryLauncher.launch()
},

deleteImage = {
clientDetailsViewModel.deleteClientImage(clientId)
showSelectImageDialog = false
Expand Down Expand Up @@ -406,6 +407,7 @@ private fun MifosClientDetailsScreen(
value = it,
)
}

client?.mobileNo?.let {
MifosClientDetailsText(
icon = MifosIcons.MobileFriendly,
Expand Down Expand Up @@ -813,6 +815,7 @@ private fun MifosSelectImageDialog(
textAlign = TextAlign.Center,
)
}

Button(
onClick = { deleteImage() },
colors = ButtonDefaults.buttonColors(MaterialTheme.colorScheme.secondary),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ class ClientDetailsViewModel(
private val _showLoading = MutableStateFlow(true)
val showLoading = _showLoading.asStateFlow()

// private val _lastUploadedFilePath = MutableStateFlow<String?>(null)
// val lastUploadedFilePath = _lastUploadedFilePath.asStateFlow()


init {
viewModelScope.launch {
getUserProfile()
Expand Down Expand Up @@ -88,6 +92,30 @@ class ClientDetailsViewModel(
}
}

private fun uploadImages(id: Int, imageFile: PlatformFile) = viewModelScope.launch {
uploadClientImageUseCase(id, createImageRequestBody(imageFile)).collect { result ->
when (result) {
is DataState.Error -> {
_clientDetailsUiState.value =
ClientDetailsUiState.ShowError(result.message)
_showLoading.value = false
}

is DataState.Loading -> {
_showLoading.value = true
}

is DataState.Success -> {
_clientDetailsUiState.value = ClientDetailsUiState.ShowUploadImageSuccessfully(
result.data,
)
getUserProfile()
_showLoading.value = false
}
}
}
}

fun deleteClientImage(clientId: Int) = viewModelScope.launch {
_showLoading.value = true
try {
Expand Down Expand Up @@ -130,8 +158,10 @@ class ClientDetailsViewModel(
viewModelScope.launch {
try {
_showLoading.value = true
val compressed = compressImage(imageFile, clientId.toString())

uploadImage(clientId, compressed)
uploadImages(clientId, compressed)

} catch (e: Exception) {
_showLoading.value = false
_clientDetailsUiState.value = ClientDetailsUiState.ShowError(e.message ?: "Unexpected error")
Expand All @@ -150,4 +180,6 @@ class ClientDetailsViewModel(
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ private class ClientIdentifiersDialogUiStatePreview :
get() = sequenceOf(
ClientIdentifierDialogUiState.Loading,
ClientIdentifierDialogUiState.Error(Res.string.feature_client_failed_to_load_client_identifiers),

ClientIdentifierDialogUiState.IdentifierCreatedSuccessfully,

)
}

Expand Down
8 changes: 7 additions & 1 deletion feature/document/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@ kotlin {
implementation(libs.filekit.compose)
implementation(libs.filekit.dialog.compose)
implementation(compose.components.uiToolingPreview)

}
}
}

dependencies {
debugImplementation(compose.uiTooling)
}
}

//dependencies {
// implementation(libs.material)
//
//}
37 changes: 28 additions & 9 deletions feature/document/src/androidMain/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright 2024 Mifos Initiative
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

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/.
<!-- Permissions needed by this feature -->
<uses-feature android:name="android.hardware.camera.any" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />

<application
android:name="com.mifos.feature.document.MyApp"
android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MifosClient">

<!-- FileProvider for PDF & Image Preview -->
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>
</application>

See https://github.com/openMF/android-client/blob/master/LICENSE.md
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mifos.feature.document.utils

import android.app.Application

// Global application context (Android only)
lateinit var appContext: Application


class MyApp : Application() {
override fun onCreate() {
super.onCreate()
appContext = this
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.mifos.feature.document.utils

import android.content.Intent
import android.net.Uri
import androidx.core.content.FileProvider
import java.io.File

actual fun openPdf(path: String) {
val file = File(path)
val uri: Uri = FileProvider.getUriForFile(
appContext,
"${appContext.packageName}.fileprovider",
file
)

val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "application/pdf")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

appContext.startActivity(Intent.createChooser(intent, "Open PDF"))
}

actual fun openImage(filePath: String) {
// ✅ Use appContext instead of getApplicationContext()
val file = File(filePath)
val uri = FileProvider.getUriForFile(
appContext,
"${appContext.packageName}.fileprovider",
file
)

val intent = Intent(Intent.ACTION_VIEW).apply {
setDataAndType(uri, "image/*")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}

appContext.startActivity(intent)
}
Loading
Loading