Skip to content

Commit

Permalink
refactor: refactor Center details fragment to compose (#2112)
Browse files Browse the repository at this point in the history
* refactor: refactor center details fragment to compose

* fix : fix scaffold
  • Loading branch information
Aditya-gupta99 authored Jun 19, 2024
1 parent 8fa9130 commit 6b9fd65
Show file tree
Hide file tree
Showing 30 changed files with 722 additions and 520 deletions.
9 changes: 7 additions & 2 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
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.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.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.GroupDetailsRepositoryImp
Expand All @@ -31,8 +33,11 @@ abstract class DataModule {
): GroupsListRepository

@Binds
internal abstract fun provideGroupDetailsRepository(impl : GroupDetailsRepositoryImp) : GroupDetailsRepository
internal abstract fun provideGroupDetailsRepository(impl: GroupDetailsRepositoryImp): GroupDetailsRepository

@Binds
internal abstract fun bindCenterListRepository(impl: CenterListRepositoryImp): CenterListRepository

@Binds
internal abstract fun bindCenterDetailsRepository(impl: CenterDetailsRepositoryImp): CenterDetailsRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.mifos.core.data.repository

import com.mifos.core.objects.group.CenterInfo
import com.mifos.core.objects.group.CenterWithAssociations
import kotlinx.coroutines.flow.Flow

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

suspend fun getCentersGroupAndMeeting(id: Int): Flow<CenterWithAssociations>

suspend fun getCenterSummaryInfo(
centerId: Int,
genericResultSet: Boolean
): Flow<List<CenterInfo>>
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CenterListRepository {

fun getAllCenters(): Flow<PagingData<Center>>

fun getCentersGroupAndMeeting(id: Int): Observable<CenterWithAssociations>
suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations

fun allDatabaseCenters(): Observable<Page<Center>>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.mifos.mifosxdroid.online.centerdetails
package com.mifos.core.data.repository_imp

import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.network.datamanager.DataManagerCenter
import com.mifos.core.network.datamanager.DataManagerRunReport
import com.mifos.core.objects.group.CenterInfo
import com.mifos.core.objects.group.CenterWithAssociations
import rx.Observable
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

/**
Expand All @@ -15,14 +17,14 @@ class CenterDetailsRepositoryImp @Inject constructor(
private val dataManagerRunReport: DataManagerRunReport
) : CenterDetailsRepository {

override fun getCentersGroupAndMeeting(id: Int): Observable<CenterWithAssociations> {
return dataManagerCenter.getCentersGroupAndMeeting(id)
override suspend fun getCentersGroupAndMeeting(id: Int): Flow<CenterWithAssociations> {
return flow { emit(dataManagerCenter.getCentersGroupAndMeeting(id)) }
}

override fun getCenterSummaryInfo(
override suspend fun getCenterSummaryInfo(
centerId: Int,
genericResultSet: Boolean
): Observable<List<CenterInfo>> {
return dataManagerRunReport.getCenterSummaryInfo(centerId, genericResultSet)
): Flow<List<CenterInfo>> {
return flow { emit(dataManagerRunReport.getCenterSummaryInfo(centerId, genericResultSet)) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CenterListRepositoryImp @Inject constructor(private val dataManagerCenter:
).flow
}

override fun getCentersGroupAndMeeting(id: Int): Observable<CenterWithAssociations> {
override suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations {
return dataManagerCenter.getCentersGroupAndMeeting(id)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.mifos.core.designsystem.component

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.sp
import com.mifos.core.designsystem.theme.Black
import com.mifos.core.designsystem.theme.White

@Composable
fun MifosScaffold(
modifier: Modifier = Modifier,
topBar: @Composable () -> Unit,
isAppBarPresent: Boolean = true,
icon: ImageVector? = null,
title: String? = null,
onBackPressed: () -> Unit = {},
actions: @Composable () -> Unit = {},
snackbarHostState: SnackbarHostState?,
bottomBar: @Composable () -> Unit = {},
floatingActionButton: @Composable () -> Unit = {},
Expand All @@ -20,7 +39,41 @@ fun MifosScaffold(

Scaffold(
modifier = modifier,
topBar = topBar,
topBar = {
if (isAppBarPresent) {
TopAppBar(
colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White),
navigationIcon = {
if (icon != null) {
IconButton(
onClick = { onBackPressed() },
) {
Icon(
imageVector = icon,
contentDescription = null,
tint = Black,
)
}
}
},
title = {
title?.let {
Text(
text = it,
style = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
fontStyle = FontStyle.Normal
),
color = Black,
textAlign = TextAlign.Start
)
}
},
actions = { actions() }
)
}
},
snackbarHost = { snackbarHostState?.let { SnackbarHost(it) } },
containerColor = White,
bottomBar = bottomBar,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
package com.mifos.core.designsystem.icon

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.DateRange
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.PersonOutline

object MifosIcons {
val Add = Icons.Rounded.Add
val person = Icons.Rounded.PersonOutline
val group = Icons.Outlined.Group
val eventRepeat = Icons.Outlined.EventRepeat
val date = Icons.Outlined.DateRange
val arrowBack = Icons.Rounded.ArrowBackIosNew
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.mifos.core.domain.use_cases

import com.mifos.core.common.utils.Resource
import com.mifos.core.data.repository.CenterDetailsRepository
import com.mifos.core.objects.group.CenterInfo
import com.mifos.core.objects.group.CenterWithAssociations
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.zip
import javax.inject.Inject

class GetCenterDetailsUseCase @Inject constructor(private val repository: CenterDetailsRepository) {

suspend operator fun invoke(
centerId: Int,
genericResultSet: Boolean
): Flow<Resource<Pair<CenterWithAssociations, List<CenterInfo>>>> = flow {
try {
emit(Resource.Loading())
repository.getCentersGroupAndMeeting(centerId)
.zip(
repository.getCenterSummaryInfo(
centerId,
genericResultSet
)
) { centerGroup, centerInfo ->
Pair(centerGroup, centerInfo)
}.collect {
emit(Resource.Success(it))
}
} catch (exception: Exception) {
emit(Resource.Error(exception.message.toString()))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class DataManagerCenter @Inject constructor(
* @param id of the center
* @return Collection Sheet
*/
fun getCentersGroupAndMeeting(id: Int): Observable<CenterWithAssociations> {
suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations {
return mBaseApiManager
.centerApi
.getCenterWithGroupMembersAndCollectionMeetingCalendar(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class DataManagerRunReport @Inject constructor(val mBaseApiManager: BaseApiManag
.getRunReportWithQuery(reportName, options)
}

fun getCenterSummaryInfo(
suspend fun getCenterSummaryInfo(
centerId: Int,
genericResultSet: Boolean
): Observable<List<CenterInfo>> {
): List<CenterInfo> {
return mBaseApiManager.runReportsService
.getCenterSummaryInfo(centerId, genericResultSet)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface CenterService {
fun getCenterAccounts(@Path("centerId") centerId: Int): Observable<CenterAccounts>

@GET(APIEndPoint.CENTERS + "/{centerId}?associations=groupMembers,collectionMeetingCalendar")
fun getCenterWithGroupMembersAndCollectionMeetingCalendar(@Path("centerId") centerId: Int): Observable<CenterWithAssociations>
suspend fun getCenterWithGroupMembersAndCollectionMeetingCalendar(@Path("centerId") centerId: Int): CenterWithAssociations

@GET(APIEndPoint.CENTERS)
fun getAllCentersInOffice(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ interface RunReportsService {
): Observable<FullParameterListResponse>

@GET(APIEndPoint.RUN_REPORTS + "/GroupSummaryCounts")
fun getCenterSummaryInfo(
suspend fun getCenterSummaryInfo(
@Query("R_groupId") centerId: Int,
@Query("genericResultSet") genericResultSet: Boolean
): Observable<List<CenterInfo>>
): List<CenterInfo>
}
Loading

0 comments on commit 6b9fd65

Please sign in to comment.