Skip to content

Commit

Permalink
refactor: refactor checker inbox to compose (#2111)
Browse files Browse the repository at this point in the history
* refactor: refactor checker inbox to compose

* feat: added alert dailog

* feat: added alert dailog

* refactor: refactor checker inbox to compose

* fix: code clean up

* fix: fix merge conflict
  • Loading branch information
Aditya-gupta99 authored Jun 21, 2024
1 parent 6b9fd65 commit f421d3a
Show file tree
Hide file tree
Showing 35 changed files with 1,118 additions and 852 deletions.
5 changes: 5 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package com.mifos.core.data.di

import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.data.repository.CenterListRepository
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.data.repository_imp.CenterDetailsRepositoryImp
import com.mifos.core.data.repository_imp.CenterListRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxRepositoryImp
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
Expand Down Expand Up @@ -40,4 +42,7 @@ abstract class DataModule {

@Binds
internal abstract fun bindCenterDetailsRepository(impl: CenterDetailsRepositoryImp): CenterDetailsRepository

@Binds
internal abstract fun bindCheckerInboxRepository(impl: CheckerInboxRepositoryImp): CheckerInboxRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.mifos.core.data.repository

import com.mifos.core.network.GenericResponse
import com.mifos.core.objects.checkerinboxandtasks.CheckerInboxSearchTemplate
import com.mifos.core.objects.checkerinboxandtasks.CheckerTask
import kotlinx.coroutines.flow.Flow

interface CheckerInboxRepository {

suspend fun loadCheckerTasks(
actionName: String? = null, entityName: String? = null,
resourceId: Int? = null
): List<CheckerTask>

suspend fun approveCheckerEntry(auditId: Int): GenericResponse

suspend fun rejectCheckerEntry(auditId: Int): GenericResponse

suspend fun deleteCheckerEntry(auditId: Int): GenericResponse

suspend fun loadSearchTemplate(): CheckerInboxSearchTemplate

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mifos.core.data.repository

import com.mifos.core.objects.checkerinboxandtasks.CheckerTask
import com.mifos.core.objects.checkerinboxandtasks.RescheduleLoansTask
import kotlinx.coroutines.flow.Flow
import rx.Observable


Expand All @@ -11,11 +12,11 @@ import rx.Observable

interface CheckerInboxTasksRepository {

fun getRescheduleLoansTaskList(): Observable<List<RescheduleLoansTask>>
suspend fun getRescheduleLoansTaskList(): Flow<List<RescheduleLoansTask>>

fun getCheckerTaskList(
suspend fun getCheckerTaskList(
actionName: String? = null, entityName: String? = null,
resourceId: Int? = null
): Observable<List<CheckerTask>>
): Flow<List<CheckerTask>>

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

import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.network.GenericResponse
import com.mifos.core.network.datamanager.DataManagerCheckerInbox
import com.mifos.core.objects.checkerinboxandtasks.CheckerInboxSearchTemplate
import com.mifos.core.objects.checkerinboxandtasks.CheckerTask
import javax.inject.Inject

class CheckerInboxRepositoryImp @Inject constructor(
private val dataManagerCheckerInbox: DataManagerCheckerInbox
) : CheckerInboxRepository {

override suspend fun loadCheckerTasks(
actionName: String?,
entityName: String?,
resourceId: Int?
): List<CheckerTask> {
return dataManagerCheckerInbox.getCheckerTaskList()
}

override suspend fun approveCheckerEntry(auditId: Int): GenericResponse {
return dataManagerCheckerInbox.approveCheckerEntry(auditId)
}

override suspend fun rejectCheckerEntry(auditId: Int): GenericResponse {
return dataManagerCheckerInbox.rejectCheckerEntry(auditId)
}

override suspend fun deleteCheckerEntry(auditId: Int): GenericResponse {
return dataManagerCheckerInbox.deleteCheckerEntry(auditId)
}

override suspend fun loadSearchTemplate(): CheckerInboxSearchTemplate {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.network.datamanager.DataManagerCheckerInbox
import com.mifos.core.objects.checkerinboxandtasks.CheckerTask
import com.mifos.core.objects.checkerinboxandtasks.RescheduleLoansTask
import rx.Observable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject


Expand All @@ -15,15 +16,15 @@ import javax.inject.Inject
class CheckerInboxTasksRepositoryImp @Inject constructor(private val dataManagerCheckerInbox: DataManagerCheckerInbox) :
CheckerInboxTasksRepository {

override fun getRescheduleLoansTaskList(): Observable<List<RescheduleLoansTask>> {
return dataManagerCheckerInbox.getRechdeduleLoansTaskList()
override suspend fun getRescheduleLoansTaskList(): Flow<List<RescheduleLoansTask>> {
return flow { emit(dataManagerCheckerInbox.getRechdeduleLoansTaskList()) }
}

override fun getCheckerTaskList(
override suspend fun getCheckerTaskList(
actionName: String?,
entityName: String?,
resourceId: Int?
): Observable<List<CheckerTask>> {
return dataManagerCheckerInbox.getCheckerTaskList()
): Flow<List<CheckerTask>> {
return flow { emit(dataManagerCheckerInbox.getCheckerTaskList()) }
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package com.mifos.core.objects.checkerinboxandtasks

import com.google.gson.annotations.SerializedName
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import java.sql.Timestamp
import java.text.SimpleDateFormat
import java.util.Date

data class CheckerTask(@SerializedName("id") var id: Int,
@SerializedName("madeOnDate") var madeOnDate: Long,
@SerializedName("processingResult") var status: String,
@SerializedName("maker") var maker: String,
@SerializedName("actionName") var action: String,
@SerializedName("entityName") var entity: String,
@SerializedName("resourceId") var resourceId: String) {
@Parcelize
data class CheckerTask(
var id: Int,
var madeOnDate: Long,
var processingResult: String,
var maker: String,
var actionName: String,
var entityName: String,
var resourceId: String
) : Parcelable {

var selectedFlag = false

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.mifos.core.objects.checkerinboxandtasks

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize

data class RescheduleLoansTask (@SerializedName("id") var id: Int,
@SerializedName("clientName") var clientName: String,
@SerializedName("loanAccountNumber") var loanAccountNo: String,
@SerializedName("rescheduleFromDate") var rescheduleFromDate: Array<Int>,
@SerializedName("actionName") var action: String,
@SerializedName("rescheduleReasonCodeValue")
var rescheduleReasonCodeValue: RescheduleReasonCodeValue)
@Parcelize
data class RescheduleLoansTask(
var id: Int,
var clientName: String,
var loanAccountNumber: String,
var rescheduleFromDate: Array<Int>,
var actionName: String,
var rescheduleReasonCodeValue: RescheduleReasonCodeValue
) : Parcelable
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
package com.mifos.core.objects.checkerinboxandtasks

data class RescheduleReasonCodeValue (var id : Int, var name : String,
var active : Boolean, var mandatory : Boolean)
import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class RescheduleReasonCodeValue(
var id: Int,
var name: String,
var active: Boolean,
var mandatory: Boolean
) : Parcelable
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.mifos.core.designsystem.component

import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource

@Composable
fun MifosDialogBox(
showDialogState: Boolean,
onDismiss: () -> Unit,
title: Int,
message: Int? = null,
confirmButtonText: Int,
onConfirm: () -> Unit,
dismissButtonText: Int
) {
if (showDialogState) {
AlertDialog(
onDismissRequest = onDismiss,
title = { Text(text = stringResource(id = title)) },
text = {
if (message != null) {
Text(text = stringResource(id = message))
}
},
confirmButton = {
TextButton(
onClick = {
onConfirm()
}
) {
Text(stringResource(id = confirmButtonText))
}
},
dismissButton = {
TextButton(onClick = onDismiss) {
Text(stringResource(id = dismissButtonText))
}
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import androidx.compose.material.icons.outlined.EventRepeat
import androidx.compose.material.icons.outlined.Group
import androidx.compose.material.icons.rounded.Add
import androidx.compose.material.icons.rounded.ArrowBackIosNew
import androidx.compose.material.icons.rounded.Check
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.FilterList
import androidx.compose.material.icons.rounded.PersonOutline
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.icons.rounded.Sync

object MifosIcons {
val Add = Icons.Rounded.Add
Expand All @@ -15,4 +21,10 @@ object MifosIcons {
val eventRepeat = Icons.Outlined.EventRepeat
val date = Icons.Outlined.DateRange
val arrowBack = Icons.Rounded.ArrowBackIosNew
val search = Icons.Rounded.Search
val filter = Icons.Rounded.FilterList
val sync = Icons.Rounded.Sync
val check = Icons.Rounded.Check
val close = Icons.Rounded.Close
val delete = Icons.Rounded.Delete
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.network.GenericResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class ApproveCheckerUseCase @Inject constructor(val repository: CheckerInboxRepository) {

suspend operator fun invoke(auditId: Int): Flow<Resource<GenericResponse>> = flow {
try {
emit(Resource.Loading())
val response = repository.approveCheckerEntry(auditId)
emit(Resource.Success(response))
} catch (exception: Exception) {
emit(Resource.Error(exception.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.CheckerInboxRepository
import com.mifos.core.network.GenericResponse
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class DeleteCheckerUseCase @Inject constructor(private val repository: CheckerInboxRepository) {

operator fun invoke(auditId: Int): Flow<Resource<GenericResponse>> = flow {
try {
emit(Resource.Loading())
val response = repository.deleteCheckerEntry(auditId)
emit(Resource.Success(response))
} catch (exception: Exception) {
emit(Resource.Error(exception.message.toString()))
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package com.mifos.core.domain.use_cases

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


Expand All @@ -19,33 +15,17 @@ import javax.inject.Inject
class GetCheckerInboxBadgesUseCase @Inject constructor(
private val repository: CheckerInboxTasksRepository
) {
operator fun invoke(): Flow<Resource<Pair<Int, Int>>> = callbackFlow {
operator fun invoke(): Flow<Resource<Pair<Int, Int>>> = flow {
try {
trySend(Resource.Loading())
Observable.zip(
repository.getCheckerTaskList(),
repository.getRescheduleLoansTaskList()
) { checkerTasks, rescheduleLoanTasks ->
Pair(checkerTasks.size, rescheduleLoanTasks.size)
}.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Pair<Int, Int>>() {
override fun onCompleted() {

}

override fun onError(error: Throwable) {
trySend(Resource.Error(error.message.toString()))
}

override fun onNext(badges: Pair<Int, Int>) {
trySend(Resource.Success(badges))
}
})

awaitClose { channel.close() }
emit(Resource.Loading())
repository.getCheckerTaskList()
.zip(repository.getRescheduleLoansTaskList()) { checkerTasks, rescheduleLoanTasks ->
Pair(checkerTasks.size, rescheduleLoanTasks.size)
}.collect {
emit(Resource.Success(it))
}
} catch (e: Exception) {
trySend(Resource.Error(e.message.toString()))
emit(Resource.Error(e.message.toString()))
}
}
}
Loading

0 comments on commit f421d3a

Please sign in to comment.