@@ -21,6 +21,7 @@ import com.mifos.core.data.repository.ClientDetailsRepository
2121import com.mifos.core.datastore.UserPreferencesRepository
2222import com.mifos.core.domain.useCases.GetClientDetailsUseCase
2323import com.mifos.core.domain.useCases.UploadClientImageUseCase
24+ import com.mifos.core.ui.util.ImageToByteArray
2425import com.mifos.core.ui.util.ImageUtil
2526import com.mifos.feature.client.utils.createImageRequestBody
2627import com.mifos.room.entities.accounts.loans.LoanAccountEntity
@@ -47,7 +48,6 @@ import kotlin.io.encoding.ExperimentalEncodingApi
4748class ClientDetailsViewModel (
4849 private val uploadClientImageUseCase : UploadClientImageUseCase ,
4950 private val getClientDetailsUseCase : GetClientDetailsUseCase ,
50- private val prefManager : UserPreferencesRepository ,
5151 private val clientDetailsRepo : ClientDetailsRepository ,
5252 savedStateHandle : SavedStateHandle ,
5353) : ViewModel() {
@@ -75,7 +75,7 @@ class ClientDetailsViewModel(
7575
7676 init {
7777 viewModelScope.launch {
78- getUserPhoto ()
78+ getUserProfile ()
7979 }
8080 }
8181 private fun uploadImage (id : Int , imageFile : PlatformFile ) = viewModelScope.launch {
@@ -159,44 +159,16 @@ class ClientDetailsViewModel(
159159 }
160160 }
161161
162- suspend fun getUserPhoto (){
162+ suspend fun getUserProfile (){
163163 clientDetailsRepo.getImage(clientId.value).collect { result->
164164 when (result)
165165 {
166166 is DataState .Error -> {}
167167 DataState .Loading -> _showLoading .value = true
168168 is DataState .Success -> {
169- setUserProfile (result.data)
169+ _profileImage .value = ImageToByteArray (result.data)
170170 }
171171 }
172-
173- }
174- }
175-
176- @OptIn(ExperimentalEncodingApi ::class )
177- private fun setUserProfile (image : String? ) {
178-
179- Logger .e(" Revanth" ){
180- image.toString()
181- }
182- if (image.isNullOrBlank()) return
183-
184- // val base64String = image.substringAfter(",", image)
185- // if (!base64String.matches(Regex("^[A-Za-z0-9+/=]+$"))) return
186- val base64String = image.substringAfter(" ," )
187-
188- val cleanBase64 = base64String
189- .replace(" \\ s" .toRegex(), " " )
190- .replace(" [^A-Za-z0-9+/=]" .toRegex(), " " )
191-
192- try {
193- val decodedBytes = Base64 .decode(cleanBase64)
194- val decodedBitmap = ImageUtil .compressImage(decodedBytes)
195- _profileImage .value= decodedBitmap
196- } catch (e: Exception ) {
197- Logger .e(" Mifos" ){
198- e.toString()
199- }
200172 }
201173 }
202174}
0 commit comments