From bf986b1ad7dfb8a95cbad9e19344740529d187a9 Mon Sep 17 00:00:00 2001 From: Aditya-gupta99 Date: Sun, 16 Jun 2024 23:23:37 +0530 Subject: [PATCH 1/2] refactor: refactor center details fragment to compose --- .../java/com/mifos/core/data/di/DataModule.kt | 9 +- .../repository/CenterDetailsRepository.kt | 18 + .../data/repository/CenterListRepository.kt | 2 +- .../CenterDetailsRepositoryImp.kt | 16 +- .../repository_imp/CenterListRepositoryImp.kt | 2 +- .../mifos/core/designsystem/icon/MifosIcon.kt | 10 + .../use_cases/GetCenterDetailsUseCase.kt | 35 ++ .../network/datamanager/DataManagerCenter.kt | 2 +- .../datamanager/DataManagerRunReport.kt | 4 +- .../core/network/services/CenterService.kt | 2 +- .../network/services/RunReportsService.kt | 4 +- .../center_details/CenterDetailsScreen.kt | 386 ++++++++++++++++++ .../center_details/CenterDetailsUiState.kt | 19 + .../center_details/CenterDetailsViewModel.kt | 45 ++ .../center/src/main/res/values/strings.xml | 22 + .../injection/module/RepositoryModule.kt | 9 - .../centerdetails/CenterDetailsFragment.kt | 150 ++----- .../centerdetails/CenterDetailsRepository.kt | 15 - .../centerdetails/CenterDetailsUiState.kt | 22 - .../centerdetails/CenterDetailsViewModel.kt | 67 --- .../online/centerlist/CenterListRepository.kt | 2 +- .../centerlist/CenterListRepositoryImp.kt | 2 +- .../online/centerlist/CenterListViewModel.kt | 29 +- 23 files changed, 599 insertions(+), 273 deletions(-) create mode 100644 core/data/src/main/java/com/mifos/core/data/repository/CenterDetailsRepository.kt rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails => core/data/src/main/java/com/mifos/core/data/repository_imp}/CenterDetailsRepositoryImp.kt (52%) create mode 100644 core/domain/src/main/java/com/mifos/core/domain/use_cases/GetCenterDetailsUseCase.kt create mode 100644 feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt create mode 100644 feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsUiState.kt create mode 100644 feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepository.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsUiState.kt delete mode 100644 mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsViewModel.kt diff --git a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt index f95efe5b2e5..2c7df10eac2 100644 --- a/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt +++ b/core/data/src/main/java/com/mifos/core/data/di/DataModule.kt @@ -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 @@ -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 } \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/CenterDetailsRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/CenterDetailsRepository.kt new file mode 100644 index 00000000000..8b196b89de0 --- /dev/null +++ b/core/data/src/main/java/com/mifos/core/data/repository/CenterDetailsRepository.kt @@ -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 + + suspend fun getCenterSummaryInfo( + centerId: Int, + genericResultSet: Boolean + ): Flow> +} \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository/CenterListRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/CenterListRepository.kt index 74a95b3eaaf..4d1f2f4f894 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository/CenterListRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/CenterListRepository.kt @@ -14,7 +14,7 @@ interface CenterListRepository { fun getAllCenters(): Flow> - fun getCentersGroupAndMeeting(id: Int): Observable + suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations fun allDatabaseCenters(): Observable> } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterDetailsRepositoryImp.kt similarity index 52% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/CenterDetailsRepositoryImp.kt index 56fe0931b9f..90ecea748da 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterDetailsRepositoryImp.kt @@ -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 /** @@ -15,14 +17,14 @@ class CenterDetailsRepositoryImp @Inject constructor( private val dataManagerRunReport: DataManagerRunReport ) : CenterDetailsRepository { - override fun getCentersGroupAndMeeting(id: Int): Observable { - return dataManagerCenter.getCentersGroupAndMeeting(id) + override suspend fun getCentersGroupAndMeeting(id: Int): Flow { + return flow { emit(dataManagerCenter.getCentersGroupAndMeeting(id)) } } - override fun getCenterSummaryInfo( + override suspend fun getCenterSummaryInfo( centerId: Int, genericResultSet: Boolean - ): Observable> { - return dataManagerRunReport.getCenterSummaryInfo(centerId, genericResultSet) + ): Flow> { + return flow { emit(dataManagerRunReport.getCenterSummaryInfo(centerId, genericResultSet)) } } } \ No newline at end of file diff --git a/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterListRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterListRepositoryImp.kt index 497150e4de1..4e428b7aa10 100644 --- a/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterListRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/CenterListRepositoryImp.kt @@ -29,7 +29,7 @@ class CenterListRepositoryImp @Inject constructor(private val dataManagerCenter: ).flow } - override fun getCentersGroupAndMeeting(id: Int): Observable { + override suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations { return dataManagerCenter.getCentersGroupAndMeeting(id) } diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/icon/MifosIcon.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/icon/MifosIcon.kt index ba52728c9e3..c115021a779 100644 --- a/core/designsystem/src/main/java/com/mifos/core/designsystem/icon/MifosIcon.kt +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/icon/MifosIcon.kt @@ -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 } \ No newline at end of file diff --git a/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetCenterDetailsUseCase.kt b/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetCenterDetailsUseCase.kt new file mode 100644 index 00000000000..58e7fe29a52 --- /dev/null +++ b/core/domain/src/main/java/com/mifos/core/domain/use_cases/GetCenterDetailsUseCase.kt @@ -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>>> = 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())) + } + } +} \ No newline at end of file diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt index cc82c5021d6..a3324eb0b09 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCenter.kt @@ -101,7 +101,7 @@ class DataManagerCenter @Inject constructor( * @param id of the center * @return Collection Sheet */ - fun getCentersGroupAndMeeting(id: Int): Observable { + suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations { return mBaseApiManager .centerApi .getCenterWithGroupMembersAndCollectionMeetingCalendar(id) diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerRunReport.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerRunReport.kt index 1d7ae194e89..d4d140a8d4a 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerRunReport.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerRunReport.kt @@ -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 { return mBaseApiManager.runReportsService .getCenterSummaryInfo(centerId, genericResultSet) } diff --git a/core/network/src/main/java/com/mifos/core/network/services/CenterService.kt b/core/network/src/main/java/com/mifos/core/network/services/CenterService.kt index 944f06d888e..7e81deda73a 100644 --- a/core/network/src/main/java/com/mifos/core/network/services/CenterService.kt +++ b/core/network/src/main/java/com/mifos/core/network/services/CenterService.kt @@ -40,7 +40,7 @@ interface CenterService { fun getCenterAccounts(@Path("centerId") centerId: Int): Observable @GET(APIEndPoint.CENTERS + "/{centerId}?associations=groupMembers,collectionMeetingCalendar") - fun getCenterWithGroupMembersAndCollectionMeetingCalendar(@Path("centerId") centerId: Int): Observable + suspend fun getCenterWithGroupMembersAndCollectionMeetingCalendar(@Path("centerId") centerId: Int): CenterWithAssociations @GET(APIEndPoint.CENTERS) fun getAllCentersInOffice( diff --git a/core/network/src/main/java/com/mifos/core/network/services/RunReportsService.kt b/core/network/src/main/java/com/mifos/core/network/services/RunReportsService.kt index 149ec9dc111..37e5b7e1e48 100644 --- a/core/network/src/main/java/com/mifos/core/network/services/RunReportsService.kt +++ b/core/network/src/main/java/com/mifos/core/network/services/RunReportsService.kt @@ -79,8 +79,8 @@ interface RunReportsService { ): Observable @GET(APIEndPoint.RUN_REPORTS + "/GroupSummaryCounts") - fun getCenterSummaryInfo( + suspend fun getCenterSummaryInfo( @Query("R_groupId") centerId: Int, @Query("genericResultSet") genericResultSet: Boolean - ): Observable> + ): List } \ No newline at end of file diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt new file mode 100644 index 00000000000..97fe0136c4e --- /dev/null +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt @@ -0,0 +1,386 @@ +@file:OptIn(ExperimentalMaterial3Api::class) + +package com.mifos.feature.center.center_details + +import androidx.compose.foundation.background +import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.MoreVert +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.outlined.Person +import androidx.compose.material.icons.outlined.PersonOutline +import androidx.compose.material.icons.rounded.ArrowBackIosNew +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.HorizontalDivider +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +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.runtime.LaunchedEffect +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.res.stringResource +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.tooling.preview.Preview +import androidx.compose.ui.tooling.preview.PreviewParameter +import androidx.compose.ui.tooling.preview.PreviewParameterProvider +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.viewmodel.compose.viewModel +import com.mifos.core.common.utils.Utils +import com.mifos.core.designsystem.component.MifosCircularProgress +import com.mifos.core.designsystem.component.MifosMenuDropDownItem +import com.mifos.core.designsystem.component.MifosScaffold +import com.mifos.core.designsystem.component.MifosSweetError +import com.mifos.core.designsystem.icon.MifosIcons +import com.mifos.core.designsystem.theme.Black +import com.mifos.core.designsystem.theme.BluePrimary +import com.mifos.core.designsystem.theme.BluePrimaryDark +import com.mifos.core.designsystem.theme.DarkGray +import com.mifos.core.designsystem.theme.White +import com.mifos.core.objects.group.CenterInfo +import com.mifos.core.objects.group.CenterWithAssociations +import com.mifos.feature.center.R + +@Composable +fun CenterDetailsScreen( + centerId: Int, + onBackPressed: () -> Unit, + onActivateCenter: () -> Unit, + addSavingsAccount: (Int) -> Unit, + groupList: (Int) -> Unit +) { + + val viewModel: CenterDetailsViewModel = viewModel() + val state by viewModel.centerDetailsUiState.collectAsStateWithLifecycle() + + LaunchedEffect(Unit) { + viewModel.loadClientDetails(centerId) + } + + CenterDetailsScreen( + state = state, + onBackPressed = onBackPressed, + onMenuClick = { + when (it) { + MenuItems.ADD_SAVINGS_ACCOUNT -> addSavingsAccount(centerId) + + MenuItems.GROUP_LIST -> groupList(centerId) + } + }, + onRetryClick = { + viewModel.loadClientDetails(centerId) + }, + onActivateCenter = onActivateCenter + ) +} + +@Composable +fun CenterDetailsScreen( + state: CenterDetailsUiState, + onBackPressed: () -> Unit, + onMenuClick: (MenuItems) -> Unit, + onRetryClick: () -> Unit, + onActivateCenter: () -> Unit +) { + + val snackbarHostState = remember { SnackbarHostState() } + var showMenu by remember { mutableStateOf(false) } + var centerActive by remember { mutableStateOf(true) } + + MifosScaffold( + topBar = { + TopAppBar( + colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), + navigationIcon = { + IconButton( + onClick = { onBackPressed() }, + ) { + Icon( + imageVector = MifosIcons.arrowBack, + contentDescription = null, + tint = Black, + ) + } + + }, + title = { + Text( + text = stringResource(id = R.string.feature_center_center), + style = TextStyle( + fontSize = 24.sp, + fontWeight = FontWeight.Medium, + fontStyle = FontStyle.Normal + ), + color = Black, + textAlign = TextAlign.Start + ) + + }, + actions = { + IconButton(onClick = { showMenu = showMenu.not() }) { + Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) + } + DropdownMenu( + modifier = Modifier.background(White), + expanded = showMenu, + onDismissRequest = { showMenu = false } + ) { + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_add_savings_account)) { + onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_group_list)) { + onMenuClick(MenuItems.GROUP_LIST) + showMenu = false + } + } + } + ) + }, + snackbarHostState = snackbarHostState, + bottomBar = { + if (!centerActive) { + Button( + onClick = { onActivateCenter() }, + modifier = Modifier + .fillMaxWidth() + .heightIn(44.dp) + .padding(start = 16.dp, end = 16.dp), + colors = ButtonDefaults.buttonColors( + containerColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary + ) + ) { + Text( + text = stringResource(id = R.string.feature_center_activate_center), + fontSize = 16.sp + ) + } + + } + } + ) { paddingValues -> + Column( + modifier = Modifier.padding(paddingValues) + ) { + when (state) { + is CenterDetailsUiState.Error -> { + MifosSweetError(message = stringResource(id = R.string.feature_center_error_loading_centers)) { + onRetryClick() + } + } + + is CenterDetailsUiState.Loading -> MifosCircularProgress() + + is CenterDetailsUiState.CenterDetails -> { + CenterDetailsContent( + centerWithAssociations = state.centerWithAssociations, + centerInfo = state.centerInfo, + activateCenter = { centerActive = false } + ) + } + } + } + } +} + +@Composable +fun CenterDetailsContent( + centerWithAssociations: CenterWithAssociations, + centerInfo: CenterInfo, + activateCenter: () -> Unit +) { + if (centerWithAssociations.active == false) { + activateCenter() + } + Column { + centerWithAssociations.name?.let { + Text( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + text = it, + style = TextStyle( + fontSize = 24.sp, + fontWeight = FontWeight.SemiBold, + ), + color = Black, + textAlign = TextAlign.Center + ) + } + MifosCenterDetailsText( + icon = MifosIcons.date, + field = stringResource(id = R.string.feature_center_activation_date), + value = Utils.getStringOfDate(centerWithAssociations.activationDate) + ) + MifosCenterDetailsText( + icon = MifosIcons.date, + field = stringResource(id = R.string.feature_center_next_meeting_on), + value = if (centerWithAssociations.collectionMeetingCalendar.calendarInstanceId == null) stringResource( + id = R.string.feature_center_unassigned + ) else Utils.getStringOfDate(centerWithAssociations.collectionMeetingCalendar.nextTenRecurringDates[0]) + ) + centerWithAssociations.collectionMeetingCalendar.humanReadable?.let { + MifosCenterDetailsText( + icon = MifosIcons.eventRepeat, + field = stringResource(id = R.string.feature_center_meeting_frequency), + value = it + ) + } + MifosCenterDetailsText( + icon = MifosIcons.person, + field = stringResource(id = R.string.feature_center_staff_name), + value = if (centerWithAssociations.staffName != null) centerWithAssociations.staffName.toString() else stringResource( + R.string.feature_center_no_staff + ) + ) + + Spacer(modifier = Modifier.height(16.dp)) + HorizontalDivider(modifier = Modifier.padding(start = 16.dp, end = 16.dp)) + + Text( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + text = stringResource(id = R.string.feature_center_summary_info), + style = TextStyle( + fontSize = 24.sp, + fontWeight = FontWeight.SemiBold, + ), + color = Black, + textAlign = TextAlign.Center + ) + + MifosCenterDetailsText( + icon = MifosIcons.person, + field = stringResource(id = R.string.feature_center_active_client), + value = centerInfo.activeClients.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.group, + field = stringResource(id = R.string.feature_center_active_group_loan), + value = centerInfo.activeGroupLoans.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.person, + field = stringResource(id = R.string.feature_center_active_client_loans), + value = centerInfo.activeClientLoans.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.group, + field = stringResource(id = R.string.feature_center_active_group_borrowers), + value = centerInfo.activeGroupBorrowers.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.person, + field = stringResource(id = R.string.feature_center_active_client_borrowers), + value = centerInfo.activeClientBorrowers.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.group, + field = stringResource(id = R.string.feature_center_active_overdue_group_loans), + value = centerInfo.overdueGroupLoans.toString() + ) + MifosCenterDetailsText( + icon = MifosIcons.person, + field = stringResource(id = R.string.feature_center_active_group_loan), + value = centerInfo.overdueClientLoans.toString() + ) + } +} + +@Composable +fun MifosCenterDetailsText(icon: ImageVector, field: String, value: String) { + Row( + modifier = Modifier + .padding(start = 16.dp, end = 16.dp, top = 8.dp, bottom = 8.dp) + .fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically + ) { + Icon( + modifier = Modifier.size(18.dp), + imageVector = icon, + contentDescription = null, + tint = DarkGray + ) + Text( + modifier = Modifier + .weight(1f) + .padding(start = 16.dp), + text = field, + style = TextStyle( + fontSize = 18.sp, + fontWeight = FontWeight.Normal, + fontStyle = FontStyle.Normal + ), + color = Black, + textAlign = TextAlign.Start + ) + Text( + + text = value, + style = TextStyle( + fontSize = 18.sp, + fontWeight = FontWeight.Normal, + fontStyle = FontStyle.Normal + ), + color = DarkGray, + textAlign = TextAlign.Start + ) + } +} + +class CenterDetailsUiStateProvider : PreviewParameterProvider { + + override val values: Sequence + get() = sequenceOf( + CenterDetailsUiState.Loading, + CenterDetailsUiState.Error(R.string.feature_center_error_loading_centers), + CenterDetailsUiState.CenterDetails(CenterWithAssociations(), CenterInfo()) + ) +} + + +@Preview(showBackground = true) +@Composable +private fun CenterDetailsScreenPreview( + @PreviewParameter(CenterDetailsUiStateProvider::class) state: CenterDetailsUiState +) { + CenterDetailsScreen( + state = state, + onBackPressed = {}, + onMenuClick = {}, + onRetryClick = {}, + onActivateCenter = {} + ) +} + +enum class MenuItems { + ADD_SAVINGS_ACCOUNT, + GROUP_LIST +} \ No newline at end of file diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsUiState.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsUiState.kt new file mode 100644 index 00000000000..eb1ce360154 --- /dev/null +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsUiState.kt @@ -0,0 +1,19 @@ +package com.mifos.feature.center.center_details + +import com.mifos.core.objects.group.CenterInfo +import com.mifos.core.objects.group.CenterWithAssociations + +/** + * Created by Aditya Gupta on 06/08/23. + */ +sealed class CenterDetailsUiState { + + data object Loading : CenterDetailsUiState() + + data class Error(val message: Int) : CenterDetailsUiState() + + data class CenterDetails( + val centerWithAssociations: CenterWithAssociations, + val centerInfo: CenterInfo + ) : CenterDetailsUiState() +} \ No newline at end of file diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt new file mode 100644 index 00000000000..b1c48221aa7 --- /dev/null +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsViewModel.kt @@ -0,0 +1,45 @@ +package com.mifos.feature.center.center_details + +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.mifos.core.common.utils.Resource +import com.mifos.core.domain.use_cases.GetCenterDetailsUseCase +import com.mifos.core.objects.group.CenterInfo +import com.mifos.feature.center.R +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asStateFlow +import kotlinx.coroutines.launch +import javax.inject.Inject + + +@HiltViewModel +class CenterDetailsViewModel @Inject constructor( + private val getCenterDetailsUseCase: GetCenterDetailsUseCase +) : ViewModel() { + + private val _centerDetailsUiState = + MutableStateFlow(CenterDetailsUiState.Loading) + val centerDetailsUiState = _centerDetailsUiState.asStateFlow() + + fun loadClientDetails(centerId: Int) = viewModelScope.launch(Dispatchers.IO) { + getCenterDetailsUseCase(centerId, false).collect { result -> + when (result) { + is Resource.Error -> _centerDetailsUiState.value = + CenterDetailsUiState.Error(R.string.feature_center_error_loading_centers) + + is Resource.Loading -> _centerDetailsUiState.value = CenterDetailsUiState.Loading + + is Resource.Success -> { + result.data?.let { + _centerDetailsUiState.value = CenterDetailsUiState.CenterDetails( + it.first, + if (it.second.isNotEmpty()) it.second[0] else CenterInfo() + ) + } + } + } + } + } +} \ No newline at end of file diff --git a/feature/center/src/main/res/values/strings.xml b/feature/center/src/main/res/values/strings.xml index 3ee4a26d3e8..2a5b05610a1 100644 --- a/feature/center/src/main/res/values/strings.xml +++ b/feature/center/src/main/res/values/strings.xml @@ -3,4 +3,26 @@ Failed to load Centers Failed to load Database Centers No More Centers Available ! + + Add Savings Account + Group List + Center + + Activation Date + Next Meeting On + Meeting Frequency + Staff Name + Active Clients + Active Group Loans + Active Client Loans + Active Group Borrowers + Active Client Borrowers + Active Overdue Group Loans + Active Overdue Client Loans + + Unassigned + No Staff + Summary Info + Activate Center + \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt index 46639145ad1..139a5562d97 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/injection/module/RepositoryModule.kt @@ -19,8 +19,6 @@ import com.mifos.core.network.datamanager.DataManagerStaff import com.mifos.core.network.datamanager.DataManagerSurveys import com.mifos.mifosxdroid.online.activate.ActivateRepository import com.mifos.mifosxdroid.online.activate.ActivateRepositoryImp -import com.mifos.mifosxdroid.online.centerdetails.CenterDetailsRepository -import com.mifos.mifosxdroid.online.centerdetails.CenterDetailsRepositoryImp import com.mifos.mifosxdroid.online.centerlist.CenterListRepository import com.mifos.mifosxdroid.online.centerlist.CenterListRepositoryImp import com.mifos.mifosxdroid.dialogfragments.chargedialog.ChargeDialogRepository @@ -178,13 +176,6 @@ class RepositoryModule { return ClientDetailsRepositoryImp(dataManagerClient) } - @Provides - fun providesCenterDetailsRepository( - dataManagerCenter: DataManagerCenter, dataManagerRunReport: DataManagerRunReport - ): CenterDetailsRepository { - return CenterDetailsRepositoryImp(dataManagerCenter, dataManagerRunReport) - } - @Provides fun providesGroupDetailsRepository(dataManagerGroups: DataManagerGroups): GroupDetailsRepository { return GroupDetailsRepositoryImp(dataManagerGroups) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt index ffa3ba11740..7f37a176778 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsFragment.kt @@ -2,21 +2,14 @@ package com.mifos.mifosxdroid.online.centerdetails import android.os.Bundle import android.view.LayoutInflater -import android.view.Menu -import android.view.MenuInflater -import android.view.MenuItem import android.view.View import android.view.ViewGroup -import androidx.lifecycle.ViewModelProvider +import androidx.appcompat.app.AppCompatActivity +import androidx.compose.ui.platform.ComposeView import androidx.navigation.fragment.findNavController -import com.mifos.core.objects.group.CenterInfo -import com.mifos.core.objects.group.CenterWithAssociations -import com.mifos.mifosxdroid.R +import com.mifos.feature.center.center_details.CenterDetailsScreen import com.mifos.mifosxdroid.core.MifosBaseFragment -import com.mifos.mifosxdroid.core.util.Toaster -import com.mifos.mifosxdroid.databinding.FragmentCenterDetailsBinding import com.mifos.utils.Constants -import com.mifos.utils.Utils import dagger.hilt.android.AndroidEntryPoint /** @@ -25,10 +18,6 @@ import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint class CenterDetailsFragment : MifosBaseFragment() { - private lateinit var binding: FragmentCenterDetailsBinding - - private lateinit var viewModel: CenterDetailsViewModel - private var centerId = 0 override fun onCreate(savedInstanceState: Bundle?) { @@ -36,7 +25,6 @@ class CenterDetailsFragment : MifosBaseFragment() { if (arguments != null) { centerId = requireArguments().getInt(Constants.CENTER_ID) } - setHasOptionsMenu(true) } override fun onCreateView( @@ -44,47 +32,35 @@ class CenterDetailsFragment : MifosBaseFragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View { - binding = FragmentCenterDetailsBinding.inflate(inflater, container, false) - viewModel = ViewModelProvider(this)[CenterDetailsViewModel::class.java] - viewModel.loadCentersGroupAndMeeting(centerId) - viewModel.loadSummaryInfo(centerId) - - viewModel.centerDetailsUiState.observe(viewLifecycleOwner) { - when (it) { - is CenterDetailsUiState.ShowCenterDetails -> { - showProgressbar(false) - showCenterDetails(it.centerWithAssociations) - } - - is CenterDetailsUiState.ShowErrorMessage -> { - showProgressbar(false) - showErrorMessage(it.message) - } - - is CenterDetailsUiState.ShowMeetingDetails -> { - showProgressbar(false) - showMeetingDetails(it.centerWithAssociations) - } - - is CenterDetailsUiState.ShowProgressbar -> showProgressbar(it.state) - is CenterDetailsUiState.ShowSummaryInfo -> { - showProgressbar(false) - showSummaryInfo(it.centerInfo) - } + return ComposeView(requireActivity()).apply { + setContent { + CenterDetailsScreen( + centerId = centerId, + onBackPressed = { + requireActivity().onBackPressed() + }, + onActivateCenter = { + onClickActivateCenter() + }, + addSavingsAccount = { centerId -> + addCenterSavingAccount(centerId) + }, + groupList = { centerId -> + loadGroupsOfCenter(centerId) + }) } } - - return binding.root } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - - binding.btnActivateCenter.setOnClickListener { - onClickActivateCenter() - } + override fun onResume() { + super.onResume() + (requireActivity() as AppCompatActivity).supportActionBar?.hide() } + override fun onStop() { + super.onStop() + (requireActivity() as AppCompatActivity).supportActionBar?.show() + } private fun onClickActivateCenter() { val action = CenterDetailsFragmentDirections.actionCenterDetailsFragmentToActivateFragment( @@ -94,80 +70,6 @@ class CenterDetailsFragment : MifosBaseFragment() { findNavController().navigate(action) } - private fun showProgressbar(show: Boolean) { - if (show) { - binding.rlCenter.visibility = View.GONE - showMifosProgressBar() - } else { - binding.rlCenter.visibility = View.VISIBLE - hideMifosProgressBar() - } - } - - private fun showCenterDetails(centerWithAssociations: CenterWithAssociations?) { - centerWithAssociations?.name?.let { setToolbarTitle(it) } - if (centerWithAssociations?.activationDate?.isNotEmpty() == true) { - if (centerWithAssociations.staffName != null) { - binding.tvStaffName.text = centerWithAssociations.staffName - } else { - binding.tvStaffName.setText(R.string.no_staff) - } - binding.tvCenterActivationDate.text = - Utils.getStringOfDate(centerWithAssociations.activationDate) - } - } - - private fun showMeetingDetails(centerWithAssociations: CenterWithAssociations?) { - if (!centerWithAssociations!!.active!!) { - binding.llBottomPanel.visibility = View.VISIBLE - showErrorMessage(R.string.error_center_inactive) - } - if (centerWithAssociations.collectionMeetingCalendar.calendarInstanceId == null) { - binding.tvMeetingDate.text = getString(R.string.unassigned) - if (view != null) { - requireView().findViewById(R.id.row_meeting_frequency).visibility = View.GONE - } - } else { - binding.tvMeetingDate.text = Utils.getStringOfDate( - centerWithAssociations - .collectionMeetingCalendar.nextTenRecurringDates[0] - ) - if (view != null) { - requireView().findViewById(R.id.row_meeting_frequency).visibility = - View.VISIBLE - binding.tvMeetingFrequency.text = centerWithAssociations.collectionMeetingCalendar - .humanReadable - } - } - } - - private fun showSummaryInfo(centerInfos: List) { - val centerInfo = centerInfos[0] - binding.tvActiveClients.text = centerInfo.activeClients.toString() - binding.tvActiveGroupLoans.text = centerInfo.activeGroupLoans.toString() - binding.tvActiveClientLoans.text = centerInfo.activeClientLoans.toString() - binding.tvActiveClientBorrowers.text = centerInfo.activeClientBorrowers.toString() - binding.tvActiveGroupBorrowers.text = centerInfo.activeGroupBorrowers.toString() - binding.tvActiveOverdueClientLoans.text = centerInfo.overdueClientLoans.toString() - binding.tvActiveOverdueGroupLoans.text = centerInfo.overdueGroupLoans.toString() - } - - private fun showErrorMessage(message: Int) { - Toaster.show(binding.root, message) - } - - override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { - inflater.inflate(R.menu.menu_center, menu) - } - - override fun onOptionsItemSelected(item: MenuItem): Boolean { - when (item.itemId) { - R.id.add_savings_account -> addCenterSavingAccount(centerId) - R.id.view_group_list -> loadGroupsOfCenter(centerId) - } - return super.onOptionsItemSelected(item) - } - private fun addCenterSavingAccount(centerId: Int) { val action = CenterDetailsFragmentDirections.actionCenterDetailsFragmentToSavingsAccountFragment( diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepository.kt deleted file mode 100644 index abb64447e33..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsRepository.kt +++ /dev/null @@ -1,15 +0,0 @@ -package com.mifos.mifosxdroid.online.centerdetails - -import com.mifos.core.objects.group.CenterInfo -import com.mifos.core.objects.group.CenterWithAssociations -import rx.Observable - -/** - * Created by Aditya Gupta on 06/08/23. - */ -interface CenterDetailsRepository { - - fun getCentersGroupAndMeeting(id: Int): Observable - - fun getCenterSummaryInfo(centerId: Int, genericResultSet: Boolean): Observable> -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsUiState.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsUiState.kt deleted file mode 100644 index d8f11f132f8..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsUiState.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.mifos.mifosxdroid.online.centerdetails - -import com.mifos.core.objects.group.CenterInfo -import com.mifos.core.objects.group.CenterWithAssociations - -/** - * Created by Aditya Gupta on 06/08/23. - */ -sealed class CenterDetailsUiState { - - data class ShowProgressbar(val state: Boolean) : CenterDetailsUiState() - - data class ShowErrorMessage(val message: Int) : CenterDetailsUiState() - - data class ShowMeetingDetails(val centerWithAssociations: CenterWithAssociations) : - CenterDetailsUiState() - - data class ShowCenterDetails(val centerWithAssociations: CenterWithAssociations) : - CenterDetailsUiState() - - data class ShowSummaryInfo(val centerInfo: List) : CenterDetailsUiState() -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsViewModel.kt deleted file mode 100644 index 4d51e18d5ec..00000000000 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerdetails/CenterDetailsViewModel.kt +++ /dev/null @@ -1,67 +0,0 @@ -package com.mifos.mifosxdroid.online.centerdetails - -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData -import androidx.lifecycle.ViewModel -import com.mifos.core.objects.group.CenterInfo -import com.mifos.core.objects.group.CenterWithAssociations -import com.mifos.mifosxdroid.R -import dagger.hilt.android.lifecycle.HiltViewModel -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import javax.inject.Inject - -/** - * Created by Aditya Gupta on 06/08/23. - */ -@HiltViewModel -class CenterDetailsViewModel @Inject constructor( - private val repository: CenterDetailsRepository -) : ViewModel() { - - private val _centerDetailsUiState = MutableLiveData() - - val centerDetailsUiState: LiveData - get() = _centerDetailsUiState - - fun loadCentersGroupAndMeeting(centerId: Int) { - _centerDetailsUiState.value = CenterDetailsUiState.ShowProgressbar(true) - repository.getCentersGroupAndMeeting(centerId) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _centerDetailsUiState.value = - CenterDetailsUiState.ShowErrorMessage(R.string.failed_to_fetch_Group_and_meeting) - } - - override fun onNext(centerWithAssociations: CenterWithAssociations) { - _centerDetailsUiState.value = - CenterDetailsUiState.ShowMeetingDetails(centerWithAssociations) - _centerDetailsUiState.value = - CenterDetailsUiState.ShowCenterDetails(centerWithAssociations) - } - }) - } - - fun loadSummaryInfo(centerId: Int) { - _centerDetailsUiState.value = CenterDetailsUiState.ShowProgressbar(true) - repository.getCenterSummaryInfo(centerId, false) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _centerDetailsUiState.value = - CenterDetailsUiState.ShowErrorMessage(R.string.failed_to_fetch_center_info) - } - - override fun onNext(centerInfos: List) { - _centerDetailsUiState.value = CenterDetailsUiState.ShowSummaryInfo(centerInfos) - } - }) - } - -} \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt index f36bd8c3ad0..e0c9448df7d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepository.kt @@ -12,7 +12,7 @@ interface CenterListRepository { fun getCenters(paged: Boolean, offset: Int, limit: Int): Observable> - fun getCentersGroupAndMeeting(id: Int): Observable + suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations fun allDatabaseCenters(): Observable> } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt index 1cbc6cd0315..2d757b565b1 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListRepositoryImp.kt @@ -17,7 +17,7 @@ class CenterListRepositoryImp @Inject constructor(private val dataManagerCenter: return dataManagerCenter.getCenters(paged, offset, limit) } - override fun getCentersGroupAndMeeting(id: Int): Observable { + override suspend fun getCentersGroupAndMeeting(id: Int): CenterWithAssociations { return dataManagerCenter.getCentersGroupAndMeeting(id) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt index 374436136c4..fbdcc39efa9 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/centerlist/CenterListViewModel.kt @@ -3,11 +3,13 @@ package com.mifos.mifosxdroid.online.centerlist import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope import com.mifos.core.objects.client.Page import com.mifos.core.objects.group.Center -import com.mifos.core.objects.group.CenterWithAssociations import com.mifos.mifosxdroid.R import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers @@ -105,23 +107,16 @@ class CenterListViewModel @Inject constructor(private val repository: CenterList }) } - fun loadCentersGroupAndMeeting(id: Int) { + fun loadCentersGroupAndMeeting(id: Int) = viewModelScope.launch(Dispatchers.IO) { _centerListUiState.value = CenterListUiState.ShowProgressbar(true) - repository.getCentersGroupAndMeeting(id) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber() { - override fun onCompleted() {} - override fun onError(e: Throwable) { - _centerListUiState.value = - CenterListUiState.ShowMessage(R.string.failed_to_fetch_Group_and_meeting) - } - - override fun onNext(centerWithAssociations: CenterWithAssociations?) { - _centerListUiState.value = - CenterListUiState.ShowCentersGroupAndMeeting(centerWithAssociations, id) - } - }) + try { + val centerWithAssociations = repository.getCentersGroupAndMeeting(id) + _centerListUiState.value = + CenterListUiState.ShowCentersGroupAndMeeting(centerWithAssociations, id) + } catch (exception: Exception) { + _centerListUiState.value = + CenterListUiState.ShowMessage(R.string.failed_to_fetch_Group_and_meeting) + } } /** From bd96d5d3ba12501c3d602aca72f317640ee65308 Mon Sep 17 00:00:00 2001 From: Aditya-gupta99 Date: Wed, 19 Jun 2024 23:03:45 +0530 Subject: [PATCH 2/2] fix : fix scaffold --- .../designsystem/component/MifosScaffold.kt | 57 +++++++- .../center_details/CenterDetailsScreen.kt | 75 +++------- .../center/center_list/ui/CenterListScreen.kt | 10 +- .../ui/CheckerInboxTasksScreen.kt | 44 +----- .../clientDetails/ui/ClientDetailsScreen.kt | 136 +++++++----------- .../ui/IndividualCollectionSheetScreen.kt | 48 +------ .../ui/NewIndividualCollectionSheetScreen.kt | 2 +- .../group_details/GroupDetailsScreen.kt | 108 +++++--------- 8 files changed, 178 insertions(+), 302 deletions(-) diff --git a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt index dacd8e7765a..d2b7906c17f 100644 --- a/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt +++ b/core/designsystem/src/main/java/com/mifos/core/designsystem/component/MifosScaffold.kt @@ -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 = {}, @@ -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, diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt index 97fe0136c4e..1acb56137f8 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_details/CenterDetailsScreen.kt @@ -14,12 +14,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.MoreVert -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.outlined.Person -import androidx.compose.material.icons.outlined.PersonOutline -import androidx.compose.material.icons.rounded.ArrowBackIosNew import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.DropdownMenu @@ -29,8 +23,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton 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.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -114,54 +106,27 @@ fun CenterDetailsScreen( var centerActive by remember { mutableStateOf(true) } MifosScaffold( - topBar = { - TopAppBar( - colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), - navigationIcon = { - IconButton( - onClick = { onBackPressed() }, - ) { - Icon( - imageVector = MifosIcons.arrowBack, - contentDescription = null, - tint = Black, - ) - } - - }, - title = { - Text( - text = stringResource(id = R.string.feature_center_center), - style = TextStyle( - fontSize = 24.sp, - fontWeight = FontWeight.Medium, - fontStyle = FontStyle.Normal - ), - color = Black, - textAlign = TextAlign.Start - ) - - }, - actions = { - IconButton(onClick = { showMenu = showMenu.not() }) { - Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) - } - DropdownMenu( - modifier = Modifier.background(White), - expanded = showMenu, - onDismissRequest = { showMenu = false } - ) { - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_add_savings_account)) { - onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_group_list)) { - onMenuClick(MenuItems.GROUP_LIST) - showMenu = false - } - } + icon = MifosIcons.arrowBack, + title = stringResource(id = R.string.feature_center_center), + onBackPressed = onBackPressed, + actions = { + IconButton(onClick = { showMenu = showMenu.not() }) { + Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) + } + DropdownMenu( + modifier = Modifier.background(White), + expanded = showMenu, + onDismissRequest = { showMenu = false } + ) { + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_add_savings_account)) { + onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT) + showMenu = false } - ) + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_center_group_list)) { + onMenuClick(MenuItems.GROUP_LIST) + showMenu = false + } + } }, snackbarHostState = snackbarHostState, bottomBar = { diff --git a/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt b/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt index 67086a88d0e..10d466d0504 100644 --- a/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt +++ b/feature/center/src/main/java/com/mifos/feature/center/center_list/ui/CenterListScreen.kt @@ -18,8 +18,6 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.material.ExperimentalMaterialApi -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Add import androidx.compose.material.pullrefresh.PullRefreshIndicator import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material.pullrefresh.rememberPullRefreshState @@ -27,6 +25,8 @@ import androidx.compose.material3.CardDefaults import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.OutlinedCard +import androidx.compose.material3.Scaffold +import androidx.compose.material3.SnackbarHost import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -60,7 +60,6 @@ import androidx.paging.compose.collectAsLazyPagingItems import coil.compose.AsyncImage import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosPagingAppendProgress -import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosSweetError import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.designsystem.theme.Black @@ -135,7 +134,7 @@ fun CenterListScreen( } } - MifosScaffold( + Scaffold( modifier = Modifier, topBar = { if (isInSelectionMode) { @@ -146,8 +145,7 @@ fun CenterListScreen( ) } }, - snackbarHostState = snackbarHostState, - bottomBar = { }, + snackbarHost = { SnackbarHost(hostState = snackbarHostState) }, floatingActionButton = { FloatingActionButton( onClick = { createNewCenter() }, diff --git a/feature/checker-inbox-task/src/main/java/com/mifos/feature/checker_inbox_task/ui/CheckerInboxTasksScreen.kt b/feature/checker-inbox-task/src/main/java/com/mifos/feature/checker_inbox_task/ui/CheckerInboxTasksScreen.kt index a0d88f94462..4aca866d34a 100644 --- a/feature/checker-inbox-task/src/main/java/com/mifos/feature/checker_inbox_task/ui/CheckerInboxTasksScreen.kt +++ b/feature/checker-inbox-task/src/main/java/com/mifos/feature/checker_inbox_task/ui/CheckerInboxTasksScreen.kt @@ -8,16 +8,10 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.ArrowBackIosNew import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.Text -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -26,9 +20,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource 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.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp @@ -40,7 +32,7 @@ import com.google.accompanist.swiperefresh.rememberSwipeRefreshState import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosSweetError -import com.mifos.core.designsystem.theme.Black +import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.designsystem.theme.White import com.mifos.feature.checker_inbox_task.R @@ -65,37 +57,9 @@ fun CheckerInboxTasksScreen( } MifosScaffold( - topBar = { - TopAppBar( - colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), - navigationIcon = { - IconButton( - onClick = { onBackPressed() }, - ) { - Icon( - imageVector = Icons.Rounded.ArrowBackIosNew, - contentDescription = null, - tint = Black, - ) - } - - }, - title = { - Text( - text = stringResource(id = R.string.feature_checker_inbox_task_checker_inbox_and_pending_tasks), - style = TextStyle( - fontSize = 24.sp, - fontWeight = FontWeight.Medium, - fontStyle = FontStyle.Normal - ), - color = Black, - textAlign = TextAlign.Start - ) - }, - actions = { } - ) - - }, + icon = MifosIcons.arrowBack, + title = stringResource(id = R.string.feature_checker_inbox_task_checker_Inbox), + onBackPressed = onBackPressed, snackbarHostState = null, bottomBar = { }) { padding -> diff --git a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt index 4725e4d8b55..f493a3c5c00 100644 --- a/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt +++ b/feature/client/src/main/java/com/mifos/feature/client/clientDetails/ui/ClientDetailsScreen.kt @@ -40,7 +40,6 @@ import androidx.compose.material.icons.outlined.Groups import androidx.compose.material.icons.outlined.HomeWork import androidx.compose.material.icons.outlined.MobileFriendly import androidx.compose.material.icons.outlined.Numbers -import androidx.compose.material.icons.rounded.ArrowBackIosNew import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card @@ -51,8 +50,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.IconButton 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.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -93,6 +90,7 @@ import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosMenuDropDownItem import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosSweetError +import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.designsystem.theme.Black import com.mifos.core.designsystem.theme.BluePrimary import com.mifos.core.designsystem.theme.BluePrimaryDark @@ -224,87 +222,59 @@ fun ClientDetailsScreen( } MifosScaffold( - topBar = { - TopAppBar( - colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), - navigationIcon = { - - IconButton( - onClick = { onBackPressed() }, - ) { - Icon( - imageVector = Icons.Rounded.ArrowBackIosNew, - contentDescription = null, - tint = Black, - ) - } - - }, - title = { - Text( - text = stringResource(id = R.string.feature_client), - style = TextStyle( - fontSize = 24.sp, - fontWeight = FontWeight.Medium, - fontStyle = FontStyle.Normal - ), - color = Black, - textAlign = TextAlign.Start - ) - - }, - actions = { - IconButton(onClick = { showMenu = showMenu.not() }) { - Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) - } - DropdownMenu( - modifier = Modifier.background(White), - expanded = showMenu, - onDismissRequest = { showMenu = false } - ) { - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_add_loan_account)) { - addLoanAccount(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_add_savings_account)) { - addSavingsAccount(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_charges)) { - charges(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_documents)) { - documents(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_identifiers)) { - identifiers(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_more_client_info)) { - moreClientInfo(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_notes)) { - notes(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_pinpoint_location)) { - pinpointLocation(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_survey)) { - survey(clientId) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_upload_signature)) { - uploadSignature(clientId) - showMenu = false - } - } + icon = MifosIcons.arrowBack, + title = stringResource(id = R.string.feature_client), + onBackPressed = onBackPressed, + actions = { + IconButton(onClick = { showMenu = showMenu.not() }) { + Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) + } + DropdownMenu( + modifier = Modifier.background(White), + expanded = showMenu, + onDismissRequest = { showMenu = false } + ) { + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_add_loan_account)) { + addLoanAccount(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_add_savings_account)) { + addSavingsAccount(clientId) + showMenu = false } - ) + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_charges)) { + charges(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_documents)) { + documents(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_identifiers)) { + identifiers(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_more_client_info)) { + moreClientInfo(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_notes)) { + notes(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_pinpoint_location)) { + pinpointLocation(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_survey)) { + survey(clientId) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_client_upload_signature)) { + uploadSignature(clientId) + showMenu = false + } + } }, snackbarHostState = snackbarHostState, bottomBar = { diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt index d1fea855731..e8d31d76b32 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/individual_collection_sheet/ui/IndividualCollectionSheetScreen.kt @@ -6,29 +6,16 @@ import androidx.compose.foundation.ExperimentalFoundationApi import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.padding import androidx.compose.foundation.pager.rememberPagerState -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.rounded.ArrowBackIosNew import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton 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.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.res.stringResource -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.tooling.preview.Preview -import androidx.compose.ui.unit.sp import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosTabRow -import com.mifos.core.designsystem.theme.Black -import com.mifos.core.designsystem.theme.White +import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.designsystem.utility.TabContent import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet import com.mifos.feature.collection_sheet.R @@ -57,36 +44,9 @@ fun IndividualCollectionSheetScreen( ) MifosScaffold( - topBar = { - TopAppBar( - colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), - navigationIcon = { - IconButton( - onClick = { onBackPressed() }, - ) { - Icon( - imageVector = Icons.Rounded.ArrowBackIosNew, - contentDescription = null, - tint = Black, - ) - } - - }, - title = { - Text( - text = stringResource(id = R.string.feature_collection_sheet_individual_collection_sheet), - style = TextStyle( - fontSize = 24.sp, - fontWeight = FontWeight.Medium, - fontStyle = FontStyle.Normal - ), - color = Black, - textAlign = TextAlign.Start - ) - - } - ) - }, + icon = MifosIcons.arrowBack, + title = stringResource(id = R.string.feature_collection_sheet_individual_collection_sheet), + onBackPressed = onBackPressed, snackbarHostState = snackbarHostState ) { paddingValues -> Column( diff --git a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt index a9b1df3c83d..9d6c24eb387 100644 --- a/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt +++ b/feature/collection-sheet/src/main/java/com/mifos/feature/individual_collection_sheet/new_individual_collection_sheet/ui/NewIndividualCollectionSheetScreen.kt @@ -131,7 +131,7 @@ fun NewIndividualCollectionSheetScreen( } MifosScaffold( - topBar = { }, + isAppBarPresent = false, snackbarHostState = snackbarHostState ) { paddingValues -> if (showDatePicker) { diff --git a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt b/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt index 184ade71a09..51240e995f9 100644 --- a/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt +++ b/feature/groups/src/main/java/com/mifos/feature/groupsList/group_details/GroupDetailsScreen.kt @@ -1,5 +1,3 @@ -@file:OptIn(ExperimentalMaterial3Api::class) - package com.mifos.feature.groupsList.group_details import androidx.compose.animation.animateContentSize @@ -28,21 +26,16 @@ import androidx.compose.material.icons.outlined.DateRange import androidx.compose.material.icons.outlined.HomeWork import androidx.compose.material.icons.outlined.Numbers import androidx.compose.material.icons.outlined.PersonOutline -import androidx.compose.material.icons.rounded.ArrowBackIosNew import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults -import androidx.compose.material3.Divider import androidx.compose.material3.DropdownMenu -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Icon import androidx.compose.material3.IconButton 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.runtime.LaunchedEffect import androidx.compose.runtime.getValue @@ -71,6 +64,7 @@ import com.mifos.core.designsystem.component.MifosCircularProgress import com.mifos.core.designsystem.component.MifosMenuDropDownItem import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosSweetError +import com.mifos.core.designsystem.icon.MifosIcons import com.mifos.core.designsystem.theme.Black import com.mifos.core.designsystem.theme.BluePrimary import com.mifos.core.designsystem.theme.BluePrimaryDark @@ -161,71 +155,43 @@ fun GroupDetailsScreen( var groupActive by remember { mutableStateOf(true) } MifosScaffold( - topBar = { - TopAppBar( - colors = TopAppBarDefaults.mediumTopAppBarColors(containerColor = White), - navigationIcon = { - - IconButton( - onClick = { onBackPressed() }, - ) { - Icon( - imageVector = Icons.Rounded.ArrowBackIosNew, - contentDescription = null, - tint = Black, - ) - } - - }, - title = { - Text( - text = stringResource(id = R.string.feature_groups_group), - style = TextStyle( - fontSize = 24.sp, - fontWeight = FontWeight.Medium, - fontStyle = FontStyle.Normal - ), - color = Black, - textAlign = TextAlign.Start - ) - - }, - actions = { - IconButton(onClick = { showMenu = showMenu.not() }) { - Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) - } - DropdownMenu( - modifier = Modifier.background(White), - expanded = showMenu, - onDismissRequest = { showMenu = false } - ) { - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_add_loan_account)) { - onMenuClick(MenuItems.ADD_LOAN_ACCOUNT) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_add_savings_account)) { - onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_documents)) { - onMenuClick(MenuItems.DOCUMENTS) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_group_clients)) { - onMenuClick(MenuItems.GROUP_CLIENTS) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_more_group_info)) { - onMenuClick(MenuItems.MORE_GROUP_INFO) - showMenu = false - } - MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_notes)) { - onMenuClick(MenuItems.NOTES) - showMenu = false - } - } + icon = MifosIcons.arrowBack, + title = stringResource(id = R.string.feature_groups_group), + onBackPressed = onBackPressed, + actions = { + IconButton(onClick = { showMenu = showMenu.not() }) { + Icon(imageVector = Icons.Default.MoreVert, contentDescription = null) + } + DropdownMenu( + modifier = Modifier.background(White), + expanded = showMenu, + onDismissRequest = { showMenu = false } + ) { + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_add_loan_account)) { + onMenuClick(MenuItems.ADD_LOAN_ACCOUNT) + showMenu = false } - ) + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_add_savings_account)) { + onMenuClick(MenuItems.ADD_SAVINGS_ACCOUNT) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_documents)) { + onMenuClick(MenuItems.DOCUMENTS) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_group_clients)) { + onMenuClick(MenuItems.GROUP_CLIENTS) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_more_group_info)) { + onMenuClick(MenuItems.MORE_GROUP_INFO) + showMenu = false + } + MifosMenuDropDownItem(option = stringResource(id = R.string.feature_groups_notes)) { + onMenuClick(MenuItems.NOTES) + showMenu = false + } + } }, snackbarHostState = snackbarHostState, bottomBar = {