Skip to content

Commit

Permalink
Merge branch 'openMF:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtutumo authored Jul 3, 2024
2 parents 82f8a07 + 882b07f commit a32a4f2
Show file tree
Hide file tree
Showing 45 changed files with 1,876 additions and 986 deletions.
15 changes: 15 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 @@ -5,6 +5,9 @@ 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.ClientIdentifiersRepository
import com.mifos.core.data.repository.ClientChargeRepository
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.data.repository.GroupDetailsRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
Expand All @@ -14,6 +17,9 @@ 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.ClientIdentifiersRepositoryImp
import com.mifos.core.data.repository_imp.ClientChargeRepositoryImp
import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
Expand Down Expand Up @@ -56,4 +62,13 @@ abstract class DataModule {

@Binds
internal abstract fun bindPathTrackingRepository(impl: PathTrackingRepositoryImp): PathTrackingRepository

@Binds
internal abstract fun bindClientChargeRepository(impl: ClientChargeRepositoryImp): ClientChargeRepository

@Binds
internal abstract fun bindCreateNewCenterRepository(impl: CreateNewCenterRepositoryImp): CreateNewCenterRepository

@Binds
internal abstract fun bindClientIdentifiersRepository(impl: ClientIdentifiersRepositoryImp): ClientIdentifiersRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.mifos.core.data.paging_source

import androidx.paging.PagingSource
import androidx.paging.PagingState
import com.mifos.core.network.datamanager.DataManagerCharge
import com.mifos.core.objects.client.Charges
import com.mifos.core.objects.client.Page
import kotlinx.coroutines.suspendCancellableCoroutine
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

class ClientChargesPagingSource(
private val clientId: Int,
private val dataManagerCharge: DataManagerCharge
) :
PagingSource<Int, Charges>() {

override fun getRefreshKey(state: PagingState<Int, Charges>): Int? {
return state.anchorPosition?.let { position ->
state.closestPageToPosition(position)?.prevKey?.plus(10) ?: state.closestPageToPosition(
position
)?.nextKey?.minus(10)
}
}

override suspend fun load(params: LoadParams<Int>): LoadResult<Int, Charges> {
val position = params.key ?: 0
return try {
val getClientCharges = getClientChargeList(clientId, position)
val clientChargesList = getClientCharges.first
val totalCharges = getClientCharges.second
LoadResult.Page(
data = clientChargesList,
prevKey = if (position <= 0) null else position - 10,
nextKey = if (position >= totalCharges) null else position + 10
)
} catch (exception: Exception) {
LoadResult.Error(exception)
}
}

private suspend fun getClientChargeList(
clientId: Int,
position: Int
): Pair<List<Charges>, Int> {
return suspendCancellableCoroutine { continuation ->
dataManagerCharge.getClientCharges(clientId = clientId, offset = position, 10)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Charges>>() {
override fun onCompleted() {
}

override fun onError(exception: Throwable) {
continuation.resumeWithException(exception)
}

override fun onNext(page: Page<Charges>) {
continuation.resume(Pair(page.pageItems, page.totalFilteredRecords))
}
})
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.mifos.core.data.repository

import androidx.paging.PagingData
import com.mifos.core.objects.client.Charges
import kotlinx.coroutines.flow.Flow

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

fun getClientCharges(clientId: Int): Flow<PagingData<Charges>>

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.clientidentifiers
package com.mifos.core.data.repository

import com.mifos.core.objects.noncore.Identifier
import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.mifos.mifosxdroid.online.createnewcenter
package com.mifos.core.data.repository

import com.mifos.core.data.CenterPayload
import com.mifos.core.objects.organisation.Office
import com.mifos.core.objects.response.SaveResponse
import rx.Observable

/**
* Created by Aditya Gupta on 10/08/23.
*/
interface CreateNewCenterRepository {

fun offices(): Observable<List<Office>>

fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.mifos.core.data.repository_imp

import androidx.paging.Pager
import androidx.paging.PagingConfig
import androidx.paging.PagingData
import com.mifos.core.data.paging_source.ClientChargesPagingSource
import com.mifos.core.data.repository.ClientChargeRepository
import com.mifos.core.network.datamanager.DataManagerCharge
import com.mifos.core.objects.client.Charges
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

/**
* Created by Aditya Gupta on 08/08/23.
*/
class ClientChargeRepositoryImp @Inject constructor(private val dataManagerCharge: DataManagerCharge) :
ClientChargeRepository {

override fun getClientCharges(
clientId: Int
): Flow<PagingData<Charges>> {
return Pager(
config = PagingConfig(
pageSize = 10
), pagingSourceFactory = {
ClientChargesPagingSource(clientId, dataManagerCharge)
}
).flow
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mifos.mifosxdroid.online.clientidentifiers
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.ClientIdentifiersRepository
import com.mifos.core.network.datamanager.DataManagerClient
import com.mifos.core.objects.noncore.Identifier
import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse
Expand All @@ -23,5 +24,4 @@ class ClientIdentifiersRepositoryImp @Inject constructor(private val dataManager
return dataManagerClient.deleteClientIdentifier(clientId, identifierId)
}


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.mifos.mifosxdroid.online.createnewcenter
package com.mifos.core.data.repository_imp

import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.objects.organisation.Office
import com.mifos.core.objects.response.SaveResponse
import rx.Observable
import javax.inject.Inject
Expand All @@ -13,10 +13,6 @@ import javax.inject.Inject
class CreateNewCenterRepositoryImp @Inject constructor(private val dataManagerCenter: DataManagerCenter) :
CreateNewCenterRepository {

override fun offices(): Observable<List<Office>> {
return dataManagerCenter.offices
}

override fun createCenter(centerPayload: CenterPayload): Observable<SaveResponse> {
return dataManagerCenter.createCenter(centerPayload)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.ArrowDropUp
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.ExposedDropdownMenuDefaults
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
Expand All @@ -38,7 +34,8 @@ fun MifosTextFieldDropdown(
onValueChanged: (String) -> Unit,
onOptionSelected: (Int, String) -> Unit,
label: Int,
options: List<String>
options: List<String>,
readOnly: Boolean = false
) {
var isExpended by remember { mutableStateOf(false) }

Expand All @@ -63,12 +60,9 @@ fun MifosTextFieldDropdown(
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon = {
val image =
if (isExpended) Icons.Default.ArrowDropUp else Icons.Default.ArrowDropDown
IconButton(onClick = { isExpended = !isExpended }) {
Icon(imageVector = image, null)
}
}
ExposedDropdownMenuDefaults.TrailingIcon(isExpended)
},
readOnly = readOnly
)

ExposedDropdownMenu(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.mifos.core.designsystem.icon

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.AssignmentTurnedIn
import androidx.compose.material.icons.outlined.DateRange
import androidx.compose.material.icons.outlined.EventRepeat
import androidx.compose.material.icons.outlined.Group
Expand All @@ -12,6 +13,7 @@ import androidx.compose.material.icons.rounded.Delete
import androidx.compose.material.icons.rounded.FilterList
import androidx.compose.material.icons.rounded.KeyboardArrowDown
import androidx.compose.material.icons.rounded.KeyboardArrowUp
import androidx.compose.material.icons.rounded.MoreVert
import androidx.compose.material.icons.rounded.PersonOutline
import androidx.compose.material.icons.rounded.Search
import androidx.compose.material.icons.rounded.Sync
Expand All @@ -31,4 +33,6 @@ object MifosIcons {
val delete = Icons.Rounded.Delete
val arrowUp = Icons.Rounded.KeyboardArrowUp
val arrowDown = Icons.Rounded.KeyboardArrowDown
val moreVert = Icons.Rounded.MoreVert
val fileTask = Icons.Default.AssignmentTurnedIn
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ val DarkGray = Color(0xFF696969)
val LightGray = Color(0xFFD3D3D3)
val BluePrimary = Color(0xFF2D5BA8)
val BluePrimaryDark = Color(0xFF9BB1E3)
val BlueSecondary = Color(0xFFD7E2FC)
val BlueSecondary = Color(0xFFD7E2FC)
val LightGreen = Color(0xFF99CC00)
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,18 @@ val aboutItemTextStyleBold = TextStyle(
textAlign = TextAlign.Center,
fontSize = 24.sp,
fontWeight = FontWeight.SemiBold
)

val identifierTextStyleDark = TextStyle(
color = Color.Black,
textAlign = TextAlign.Start,
fontSize = 16.sp,
fontWeight = FontWeight.Normal
)

val identifierTextStyleLight = TextStyle(
color = DarkGray,
textAlign = TextAlign.Start,
fontSize = 16.sp,
fontWeight = FontWeight.Normal
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.CenterPayload
import com.mifos.core.data.repository.CreateNewCenterRepository
import com.mifos.core.objects.response.SaveResponse
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class CreateNewCenterUseCase @Inject constructor(private val repository: CreateNewCenterRepository) {

suspend operator fun invoke(centerPayload: CenterPayload): Flow<Resource<SaveResponse>> =
callbackFlow {
try {
trySend(Resource.Loading())
repository.createCenter(centerPayload)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<SaveResponse>() {
override fun onCompleted() {}

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

override fun onNext(saveResponse: SaveResponse) {
trySend(Resource.Success(saveResponse))
}
})

awaitClose { channel.close() }

} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.ClientIdentifiersRepository
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import org.apache.fineract.client.models.DeleteClientsClientIdIdentifiersIdentifierIdResponse
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class DeleteIdentifierUseCase @Inject constructor(private val repository: ClientIdentifiersRepository) {

suspend operator fun invoke(
clientId: Int,
identifierId: Int
): Flow<Resource<DeleteClientsClientIdIdentifiersIdentifierIdResponse>> = callbackFlow {
try {
trySend(Resource.Loading())
repository.deleteClientIdentifier(clientId = clientId, identifierId = identifierId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object :
Subscriber<DeleteClientsClientIdIdentifiersIdentifierIdResponse>() {
override fun onCompleted() {}

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

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

awaitClose { channel.close() }
} catch (exception: Exception) {
trySend(Resource.Error(exception.message.toString()))
}
}
}
Loading

0 comments on commit a32a4f2

Please sign in to comment.