Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.mifos.mobile.core.network.services

import de.jensklingenberg.ktorfit.http.GET
import de.jensklingenberg.ktorfit.http.Headers
import de.jensklingenberg.ktorfit.http.Path
import de.jensklingenberg.ktorfit.http.Query
import io.ktor.client.statement.HttpResponse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class KtorInterceptor(
scope.requestPipeline.intercept(HttpRequestPipeline.State) {
context.header(CONTENT_TYPE, "application/json")
context.header("Accept", "application/json")
context.header("Accept", "*/*")
context.header(HEADER_TENANT, DEFAULT)

plugin.getToken()?.let { token ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import coil3.ImageLoader
import coil3.compose.LocalPlatformContext
import coil3.compose.rememberAsyncImagePainter
import coil3.request.ImageRequest
import org.mifos.mobile.core.designsystem.theme.MifosMobileTheme
import org.mifos.mobile.core.ui.utils.DevicePreview

Expand All @@ -32,18 +30,19 @@ fun MifosUserImage(
username: String? = null,
) {
val context = LocalPlatformContext.current
val uploadedImage by remember { mutableStateOf<ByteArray?>(null) }

val painter = rememberAsyncImagePainter(
model = uploadedImage,
imageLoader = ImageLoader(context),
)
if (bitmap == null) {
MifosTextUserImage(
text = username?.firstOrNull()?.toString() ?: "M",
modifier = modifier,
)
} else {
val painter = rememberAsyncImagePainter(
model = ImageRequest.Builder(context)
.data(bitmap)
.build(),
imageLoader = ImageLoader(context),
)
Image(
modifier = modifier
.clip(CircleShape)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,16 @@ internal class SettingsViewModel(
private fun setUserProfile(image: String?) {
if (image.isNullOrBlank()) return

// Extract the base64 part, removing any data URI prefix
val base64String = image.substringAfter(",", image)

// Basic validation for a base64 string
if (!base64String.matches(Regex("^[A-Za-z0-9+/=]+$"))) return

// Extract the Base64 payload after the standard data URL prefix (more robust than first comma)
val afterPrefix = image.substringAfter("base64,", image)
// Remove any whitespace/newlines that can appear in API responses
val cleaned = afterPrefix.replace(Regex("\\s+"), "")
try {
val decodedBytes = Base64.decode(base64String)
val bitmap = ImageUtil.compressImage(decodedBytes)
updateState { it.copy(profileImage = bitmap) }
val decodedBytes = Base64.decode(cleaned)
val compressedImageBytes = ImageUtil.compressImage(decodedBytes)
if (compressedImageBytes.isNotEmpty()) {
updateState { it.copy(profileImage = compressedImageBytes) }
}
} catch (e: Exception) {
// Log the error but fail silently in the UI
println(e.message)
Expand Down
Loading