Skip to content

Commit

Permalink
Merge branch 'master' into check
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 authored Apr 16, 2024
2 parents 49a5589 + 207cee1 commit a54c55a
Show file tree
Hide file tree
Showing 28 changed files with 1,610 additions and 600 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ This is an Android Application built on top of the [MifosX](https://mifosforge.j

## Join Us on Slack

Mifos boasts an active and vibrant contributor community, Please join us on [slack](https://mifos.slack.com/). Once you've joined the mifos slack community, please join the `#android-client` channel to engage with android-client development.
Mifos boasts an active and vibrant contributor community, Please join us on [slack](https://join.slack.com/t/mifos/shared_invite/zt-2f4nr6tk3-ZJlHMi1lc0R19FFEHxdvng). Once you've joined the mifos slack community, please join the `#android-client` channel to engage with android-client development.

## Demo credentials
Fineract Instance: gsoc.mifos.community
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This project is licensed under the open source MPL V2.
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.model.user
package com.mifos.core.common.model.user

/**
* Created by ishankhanna on 09/02/14.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This project is licensed under the open source MPL V2.
* See https://github.com/openMF/android-client/blob/master/LICENSE.md
*/
package com.mifos.core.data.model.user
package com.mifos.core.common.model.user

class User {
var username: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object BaseUrl {

const val PROTOCOL_HTTPS = "https://"

const val API_ENDPOINT = "gsoc.mifos.community"
const val API_ENDPOINT = "demo.mifos.community"

const val API_PATH = "/fineract-provider/api/v1/"

Expand Down
24 changes: 24 additions & 0 deletions core/common/src/main/java/com/mifos/core/common/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mifos.core.common.utils

import java.text.DateFormat
import java.util.Calendar
import java.util.TimeZone

object Utils {

fun getStringOfDate(dateObj: List<Int?>): String {
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
dateObj.getOrNull(0)?.let { year ->
calendar.set(Calendar.YEAR, year)
}
dateObj.getOrNull(1)?.let { month ->
calendar.set(Calendar.MONTH, month - 1)
}
dateObj.getOrNull(2)?.let { day ->
calendar.set(Calendar.DAY_OF_MONTH, day)
}
val dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM)
return dateFormat.format(calendar.time)
}

}
20 changes: 20 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.mifos.core.data.di

import com.mifos.core.data.repository.ClientDetailsRepository
import com.mifos.core.data.repository_imp.ClientDetailsRepositoryImp
import com.mifos.core.network.datamanager.DataManagerClient
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent

@Module
@InstallIn(SingletonComponent::class)
object RepositoryModule {

@Provides
fun providesClientDetailsRepository(dataManagerClient: DataManagerClient): ClientDetailsRepository =
ClientDetailsRepositoryImp(dataManagerClient)


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mifos.core.data.repository

import com.mifos.core.objects.accounts.ClientAccounts
import com.mifos.core.objects.client.Client
import okhttp3.MultipartBody
import okhttp3.ResponseBody
import rx.Observable

/**
* Created by Aditya Gupta on 06/08/23.
*/
interface ClientDetailsRepository {

fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable<ResponseBody>

fun deleteClientImage(clientId: Int): Observable<ResponseBody>

fun getClientAccounts(clientId: Int): Observable<ClientAccounts>

fun getClient(clientId: Int): Observable<Client>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.ClientDetailsRepository
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.objects.accounts.ClientAccounts
import com.mifos.core.objects.client.Client
import okhttp3.MultipartBody
import okhttp3.ResponseBody
import rx.Observable
import javax.inject.Inject

/**
* Created by Aditya Gupta on 06/08/23.
*/
class ClientDetailsRepositoryImp @Inject constructor(private val dataManagerClient: DataManagerClient) :
ClientDetailsRepository {

override fun uploadClientImage(id: Int, file: MultipartBody.Part?): Observable<ResponseBody> {
return dataManagerClient.uploadClientImage(id, file)
}

override fun deleteClientImage(clientId: Int): Observable<ResponseBody> {
return dataManagerClient.deleteClientImage(clientId)
}

override fun getClientAccounts(clientId: Int): Observable<ClientAccounts> {
return dataManagerClient.getClientAccounts(clientId)
}

override fun getClient(clientId: Int): Observable<Client> {
return dataManagerClient.getClient(clientId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package com.mifos.core.datastore
import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import com.mifos.core.common.model.user.User
import com.mifos.core.common.utils.Constants
import com.mifos.core.objects.user.User
import dagger.hilt.android.qualifiers.ApplicationContext
import org.apache.fineract.client.models.PostAuthenticationResponse
import org.mifos.core.sharedpreference.UserPreferences
Expand All @@ -27,7 +27,7 @@ class PrefManager @Inject constructor(
PreferenceManager.getDefaultSharedPreferences(context)

override fun getUser(): User {
return gson.fromJson(preference.getString(USER_DETAILS,""),User::class.java)
return gson.fromJson(preference.getString(USER_DETAILS, ""), User::class.java)
}

override fun saveUser(user: User) {
Expand Down
6 changes: 6 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -62,4 +63,9 @@ dependencies {

// coil
implementation("io.coil-kt:coil-compose:2.5.0")

//DBFlow dependencies
kapt("com.github.raizlabs.dbflow.dbflow:dbflow-processor:3.1.1")
implementation("com.github.raizlabs.dbflow.dbflow:dbflow:3.1.1")
kapt("com.github.raizlabs.dbflow:dbflow-processor:4.2.4")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.mifos.core.designsystem.component

import androidx.compose.foundation.layout.padding
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mifos.core.designsystem.R

@Composable
fun MifosMenuDropDownItem(option: String, onClick: () -> Unit) {
DropdownMenuItem(text = {
Text(
modifier = Modifier.padding(6.dp),
text = option, style = TextStyle(
fontSize = 17.sp
)
)
}, onClick = { onClick() })
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
package com.mifos.core.designsystem.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.Dialog
import com.mifos.core.designsystem.R
import com.mifos.core.designsystem.theme.DarkGray
import com.mifos.core.designsystem.theme.White

/**
* Created by Aditya Gupta on 21/02/24.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
package com.mifos.core.network.di

import android.content.Context
import androidx.core.os.trace
import coil.ImageLoader
import coil.util.DebugLogger
import com.mifos.core.datastore.PrefManager
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import okhttp3.Call
import okhttp3.OkHttpClient
import org.mifos.core.apimanager.BaseApiManager
import javax.inject.Singleton

Expand Down Expand Up @@ -32,4 +39,24 @@ object NetworkModule {
)
return baseManager
}

@Provides
@Singleton
fun okHttpCallFactory(): Call.Factory = trace("MifosHttpClient") {
OkHttpClient.Builder().build()
}


@Provides
@Singleton
fun provideImageLoader(
okHttpCallFactory: dagger.Lazy<Call.Factory>,
@ApplicationContext context: Context
): ImageLoader {
return ImageLoader.Builder(context)
.callFactory { okHttpCallFactory.get() }
.apply {
logger(DebugLogger())
}.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.mifos.core.network.utils

import android.content.Context
import coil.ImageLoader
import coil.request.ImageRequest
import coil.request.ImageResult
import com.mifos.core.datastore.PrefManager
import com.mifos.core.network.MifosInterceptor
import dagger.hilt.android.qualifiers.ApplicationContext
import javax.inject.Inject

class ImageLoaderUtils @Inject constructor(
private val prefManager: PrefManager,
private val imageLoader: ImageLoader,
@ApplicationContext private val context: Context
) {

private fun buildImageUrl(clientId: Int): String {
return (prefManager.getInstanceUrl()
+ "clients/"
+ clientId
+ "/images?maxHeight=120&maxWidth=120")
}

suspend fun loadImage(clientId: Int): ImageResult {
val request = ImageRequest.Builder(context)
.data(buildImageUrl(clientId))
.addHeader(MifosInterceptor.HEADER_TENANT, prefManager.getTenant())
.addHeader(MifosInterceptor.HEADER_AUTH, prefManager.getToken())
.addHeader("Accept", "application/octet-stream")
.build()
return imageLoader.execute(request)
}
}
6 changes: 6 additions & 0 deletions feature/client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,10 @@ dependencies {
// Mongo Realm
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1")
implementation("io.realm.kotlin:library-base:1.11.0")

// permission
implementation("com.google.accompanist:accompanist-permissions:0.31.1-alpha")

// compose lifecycle
implementation("androidx.lifecycle:lifecycle-runtime-compose:2.7.0")
}
7 changes: 6 additions & 1 deletion feature/client/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.CAMERA"/>
<uses-feature android:name="android.hardware.camera.any"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mifos.feature.client.clientDetails.domain.usecase

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.ClientDetailsRepository
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import okhttp3.ResponseBody
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

/**
* Created by Aditya Gupta on 18/03/24.
*/

class DeleteClientImageUseCase @Inject constructor(private val repository: ClientDetailsRepository) {

operator fun invoke(clientId: Int): Flow<Resource<ResponseBody>> = callbackFlow {
try {
trySend(Resource.Loading())
repository.deleteClientImage(clientId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<ResponseBody>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
trySend(Resource.Error("Failed to delete image"))
}

override fun onNext(response: ResponseBody) {
trySend(Resource.Success(response))
}
})

awaitClose { channel.close() }

} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
}
}

}
Loading

0 comments on commit a54c55a

Please sign in to comment.