From 68f2813899f176c508ba75ea82c2d1163adbc86d Mon Sep 17 00:00:00 2001 From: Aditya Gupta <94394661+Aditya-gupta99@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:26:18 +0530 Subject: [PATCH] refactor: move data table screens to data table module (#2199) --- .../java/com/mifos/core/data/di/DataModule.kt | 10 ++ .../repository}/DataTableListRepository.kt | 2 +- .../data/repository}/DataTableRepository.kt | 2 +- .../DataTableListRepositoryImp.kt | 6 +- .../repository_imp}/DataTableRepositoryImp.kt | 3 +- .../data_table/dataTable}/DataTableScreen.kt | 15 +- .../data_table/dataTable}/DataTableUiState.kt | 2 +- .../dataTable}/DataTableViewModel.kt | 11 +- .../dataTableList}/DataTableListScreen.kt | 100 +++++++++-- .../dataTableList}/DataTableListUiState.kt | 13 +- .../dataTableList}/DataTableListViewModel.kt | 31 +--- .../data_table/dataTableList/FormSpinner.kt | 47 +++++ .../data_table/dataTableList/FormWidget.kt | 162 ++++++++++++++++++ .../src/main/res/values/strings.xml | 11 ++ .../mifosxdroid/components/Navigation.kt | 2 +- .../injection/module/RepositoryModule.kt | 20 --- .../online/datatable/DataTableFragment.kt | 4 +- .../DataTableListFragment.kt | 67 +------- 18 files changed, 367 insertions(+), 141 deletions(-) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment => core/data/src/main/java/com/mifos/core/data/repository}/DataTableListRepository.kt (90%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable => core/data/src/main/java/com/mifos/core/data/repository}/DataTableRepository.kt (82%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment => core/data/src/main/java/com/mifos/core/data/repository_imp}/DataTableListRepositoryImp.kt (84%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable => core/data/src/main/java/com/mifos/core/data/repository_imp}/DataTableRepositoryImp.kt (82%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable}/DataTableScreen.kt (93%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable}/DataTableUiState.kt (89%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable}/DataTableViewModel.kt (86%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList}/DataTableListScreen.kt (75%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList}/DataTableListUiState.kt (59%) rename {mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment => feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList}/DataTableListViewModel.kt (89%) create mode 100644 feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt create mode 100644 feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.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 740007bc8fc..09ea33be4d3 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 @@ -13,6 +13,8 @@ import com.mifos.core.data.repository.ClientIdentifiersRepository import com.mifos.core.data.repository.CreateNewCenterRepository import com.mifos.core.data.repository.CreateNewGroupRepository import com.mifos.core.data.repository.DataTableDataRepository +import com.mifos.core.data.repository.DataTableListRepository +import com.mifos.core.data.repository.DataTableRepository import com.mifos.core.data.repository.DataTableRowDialogRepository import com.mifos.core.data.repository.DocumentListRepository import com.mifos.core.data.repository.GenerateCollectionSheetRepository @@ -51,6 +53,8 @@ import com.mifos.core.data.repository_imp.ClientIdentifiersRepositoryImp import com.mifos.core.data.repository_imp.CreateNewCenterRepositoryImp import com.mifos.core.data.repository_imp.CreateNewGroupRepositoryImp import com.mifos.core.data.repository_imp.DataTableDataRepositoryImp +import com.mifos.core.data.repository_imp.DataTableListRepositoryImp +import com.mifos.core.data.repository_imp.DataTableRepositoryImp import com.mifos.core.data.repository_imp.DataTableRowDialogRepositoryImp import com.mifos.core.data.repository_imp.DocumentListRepositoryImp import com.mifos.core.data.repository_imp.GenerateCollectionSheetRepositoryImp @@ -199,4 +203,10 @@ abstract class DataModule { @Binds internal abstract fun bindLoanTransactionsRepository(impl: LoanTransactionsRepositoryImp): LoanTransactionsRepository + + @Binds + internal abstract fun bindDataTableRepository(impl: DataTableRepositoryImp): DataTableRepository + + @Binds + internal abstract fun bindDataTableListRepository(impl: DataTableListRepositoryImp): DataTableListRepository } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/DataTableListRepository.kt similarity index 90% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/DataTableListRepository.kt index db47dec5422..e94938bfdc4 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/DataTableListRepository.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment +package com.mifos.core.data.repository import com.mifos.core.data.GroupLoanPayload import com.mifos.core.data.LoansPayload diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepository.kt b/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt similarity index 82% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepository.kt rename to core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt index 95045731f91..bf33a44a7a2 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepository.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository/DataTableRepository.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.datatable +package com.mifos.core.data.repository import com.mifos.core.objects.noncore.DataTable import rx.Observable diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableListRepositoryImp.kt similarity index 84% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableListRepositoryImp.kt index fec7e5a0b8c..e667adfa450 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableListRepositoryImp.kt @@ -1,7 +1,8 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment +package com.mifos.core.data.repository_imp import com.mifos.core.data.GroupLoanPayload import com.mifos.core.data.LoansPayload +import com.mifos.core.data.repository.DataTableListRepository import com.mifos.core.network.DataManager import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.network.datamanager.DataManagerLoan @@ -15,7 +16,8 @@ import javax.inject.Inject * Created by Aditya Gupta on 10/08/23. */ class DataTableListRepositoryImp @Inject constructor( - private val dataManagerLoan: DataManagerLoan, private val dataManager: DataManager, + private val dataManagerLoan: DataManagerLoan, + private val dataManager: DataManager, private val dataManagerClient: DataManagerClient ) : DataTableListRepository { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepositoryImp.kt b/core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableRepositoryImp.kt similarity index 82% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepositoryImp.kt rename to core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableRepositoryImp.kt index 131f858e6cd..f49ef5fd0d0 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableRepositoryImp.kt +++ b/core/data/src/main/java/com/mifos/core/data/repository_imp/DataTableRepositoryImp.kt @@ -1,5 +1,6 @@ -package com.mifos.mifosxdroid.online.datatable +package com.mifos.core.data.repository_imp +import com.mifos.core.data.repository.DataTableRepository import com.mifos.core.network.datamanager.DataManagerDataTable import com.mifos.core.objects.noncore.DataTable import rx.Observable diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt similarity index 93% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt index 13aa4caf664..0b24c252faf 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableScreen.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.datatable +package com.mifos.feature.data_table.dataTable import android.widget.Toast import androidx.compose.foundation.layout.Box @@ -8,7 +8,6 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.pullrefresh.pullRefresh import androidx.compose.material3.Card import androidx.compose.material3.CardDefaults import androidx.compose.material3.ExperimentalMaterial3Api @@ -16,7 +15,6 @@ import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Text import androidx.compose.material3.pulltorefresh.PullToRefreshContainer -import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -39,10 +37,9 @@ 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.icon.MifosIcons -import com.mifos.core.objects.noncore.ColumnHeader import com.mifos.core.objects.noncore.DataTable import com.mifos.core.ui.components.MifosEmptyUi -import com.mifos.mifosxdroid.R +import com.mifos.feature.data_table.R /** * Created on 27/06/2024 (11:38 PM) by Pronay Sarker @@ -86,7 +83,7 @@ fun DataTableScreen( MifosScaffold( icon = MifosIcons.arrowBack, - title = stringResource(id = R.string.datatables), + title = stringResource(id = R.string.feature_data_table_title), onBackPressed = navigateBack, snackbarHostState = snackbarHostState ) { @@ -105,7 +102,7 @@ fun DataTableScreen( } DataTableUiState.ShowEmptyDataTables -> { - MifosEmptyUi(text = stringResource(id = R.string.empty_data_table)) + MifosEmptyUi(text = stringResource(id = R.string.feature_data_table_empty_data_table)) } is DataTableUiState.ShowError -> { @@ -137,7 +134,7 @@ fun DataTableScreen( } else { Toast.makeText( context, - context.resources.getText(R.string.error_not_connected_internet), + context.resources.getText(R.string.feature_data_table_error_not_connected_internet), Toast.LENGTH_SHORT, ).show() } @@ -218,7 +215,7 @@ class DataTablePreviewProvider : PreviewParameterProvider { DataTableUiState.ShowEmptyDataTables, DataTableUiState.ShowProgressbar, DataTableUiState.ShowDataTables(dataTable), - DataTableUiState.ShowError(R.string.failed_to_fetch_datatable) + DataTableUiState.ShowError(R.string.feature_data_table_failed_to_fetch_data_table) ) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt similarity index 89% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableUiState.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt index 20769191cb8..01910946523 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableUiState.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.datatable +package com.mifos.feature.data_table.dataTable import com.mifos.core.objects.noncore.DataTable diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt similarity index 86% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableViewModel.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt index bf3f173a04f..eb0755d63fc 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTable/DataTableViewModel.kt @@ -1,18 +1,15 @@ -package com.mifos.mifosxdroid.online.datatable +package com.mifos.feature.data_table.dataTable -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope +import com.mifos.core.data.repository.DataTableRepository import com.mifos.core.objects.noncore.DataTable -import com.mifos.feature.note.NoteUiState -import com.mifos.mifosxdroid.R +import com.mifos.feature.data_table.R import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch -import okhttp3.internal.wait import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers @@ -48,7 +45,7 @@ class DataTableViewModel @Inject constructor(private val repository: DataTableRe override fun onError(e: Throwable) { _dataTableUiState.value = - DataTableUiState.ShowError(R.string.failed_to_fetch_datatable) + DataTableUiState.ShowError(R.string.feature_data_table_failed_to_fetch_data_table) } override fun onNext(dataTables: List) { diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListScreen.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt similarity index 75% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListScreen.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt index 06d95ccc307..7846e71c3cc 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListScreen.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListScreen.kt @@ -1,7 +1,6 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment +package com.mifos.feature.data_table.dataTableList import android.app.DatePickerDialog -import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row @@ -12,10 +11,8 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material.icons.Icons import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.SnackbarHostState import androidx.compose.material3.Switch @@ -45,16 +42,18 @@ import com.mifos.core.designsystem.component.MifosOutlinedTextField import com.mifos.core.designsystem.component.MifosScaffold import com.mifos.core.designsystem.component.MifosTextFieldDropdown import com.mifos.core.designsystem.icon.MifosIcons -import com.mifos.core.designsystem.icon.MifosIcons.ArrowDropDown import com.mifos.core.objects.client.Client import com.mifos.core.objects.noncore.DataTable -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.formwidgets.FormWidget +import com.mifos.feature.data_table.R import java.time.LocalDate import java.time.format.DateTimeFormatter @Composable fun DataTableListScreen( + dataTables : List, + requestType :Int, + payload : Any?, + formWidgetsList : MutableList>, viewModel: DataTableListViewModel = hiltViewModel(), onBackPressed: () -> Unit, clientCreated: (Client) -> Unit @@ -62,6 +61,10 @@ fun DataTableListScreen( val uiState by viewModel.dataTableListUiState.collectAsStateWithLifecycle() val dataTableList by viewModel.dataTableList.collectAsStateWithLifecycle() + LaunchedEffect(key1 = Unit) { + viewModel.initArgs(dataTables, requestType, formWidgetsList,payload) + } + DataTableListScreen( uiState = uiState, dataTableList = dataTableList ?: listOf(), @@ -83,7 +86,7 @@ fun DataTableListScreen( MifosScaffold( icon = MifosIcons.arrowBack, - title = stringResource(id = R.string.associated_datatables), + title = stringResource(id = R.string.feature_data_table_associated_datatables), onBackPressed = onBackPressed, snackbarHostState = snackBarHostState ) { paddingValues -> @@ -102,7 +105,7 @@ fun DataTableListScreen( val message = when { uiState.messageResId != null -> stringResource(id = uiState.messageResId) uiState.message != null -> uiState.message - else -> stringResource(id = R.string.something_went_wrong) + else -> stringResource(id = R.string.feature_data_table_something_went_wrong) } LaunchedEffect(key1 = message) { snackBarHostState.showSnackbar(message = message) @@ -116,7 +119,7 @@ fun DataTableListScreen( } ?: run { val message = when { uiState.messageResId != null -> stringResource(id = uiState.messageResId) - else -> stringResource(id = R.string.something_went_wrong) + else -> stringResource(id = R.string.feature_data_table_something_went_wrong) } LaunchedEffect(key1 = message) { snackBarHostState.showSnackbar(message = message) @@ -162,7 +165,7 @@ fun DataTableListContent( .padding(16.dp), colors = ButtonDefaults.buttonColors(containerColor = MaterialTheme.colorScheme.primary) ) { - Text(text = stringResource(id = R.string.save), color = Color.White) + Text(text = stringResource(id = R.string.feature_data_table_save), color = Color.White) } } } @@ -287,4 +290,77 @@ fun DataTableListScreenPreview() { clientCreated = { }, onSaveClicked = { } ) -} \ No newline at end of file +} + + +//private fun createFormWidgetList(): MutableList> { +// return dataTables?.map { createForm(it) }?.toMutableList() ?: mutableListOf() +//} +// +//private fun createForm(table: DataTable): List { +// return table.columnHeaderData +// .filterNot { it.columnPrimaryKey == true } +// .map { createFormWidget(it) } +//} +// +//private fun createFormWidget(columnHeader: ColumnHeader): FormWidget { +// return when (columnHeader.columnDisplayType) { +// FormWidget.SCHEMA_KEY_STRING, FormWidget.SCHEMA_KEY_TEXT -> FormEditText( +// activity, +// columnHeader.dataTableColumnName +// ) +// +// FormWidget.SCHEMA_KEY_INT -> FormNumericEditText( +// activity, +// columnHeader.dataTableColumnName +// ).apply { returnType = FormWidget.SCHEMA_KEY_INT } +// +// FormWidget.SCHEMA_KEY_DECIMAL -> FormNumericEditText( +// activity, +// columnHeader.dataTableColumnName +// ).apply { returnType = FormWidget.SCHEMA_KEY_DECIMAL } +// +// FormWidget.SCHEMA_KEY_CODELOOKUP, FormWidget.SCHEMA_KEY_CODEVALUE -> createFormSpinner( +// columnHeader +// ) +// +// FormWidget.SCHEMA_KEY_DATE -> FormEditText( +// activity, +// columnHeader.dataTableColumnName +// ).apply { setIsDateField(true, requireActivity().supportFragmentManager) } +// +// FormWidget.SCHEMA_KEY_BOOL -> FormToggleButton( +// activity, +// columnHeader.dataTableColumnName +// ) +// +// else -> FormEditText(activity, columnHeader.dataTableColumnName) +// } +//} +// +//private fun createFormSpinner(columnHeader: ColumnHeader): FormSpinner { +// val columnValueStrings = columnHeader.columnValues.mapNotNull { it.value } +// val columnValueIds = columnHeader.columnValues.mapNotNull { it.id } +// return FormSpinner( +// activity, +// columnHeader.dataTableColumnName, +// columnValueStrings, +// columnValueIds +// ).apply { +// returnType = FormWidget.SCHEMA_KEY_CODEVALUE +// } +//} +// +//private fun showClientCreatedSuccessfully(client: Client) { +// requireActivity().supportFragmentManager.popBackStack() +// requireActivity().supportFragmentManager.popBackStack() +// Toast.makeText( +// activity, getString(R.string.client) + +// MifosResponseHandler.response, Toast.LENGTH_SHORT +// ).show() +// if (PrefManager.userStatus == Constants.USER_ONLINE) { +// val clientActivityIntent = Intent(activity, ClientActivity::class.java) +// clientActivityIntent.putExtra(Constants.CLIENT_ID, client.clientId) +// startActivity(clientActivityIntent) +// } +//} diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListUiState.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt similarity index 59% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListUiState.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt index e7ab2aa5575..2429f998b97 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListUiState.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListUiState.kt @@ -1,4 +1,4 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment +package com.mifos.feature.data_table.dataTableList import com.mifos.core.objects.client.Client import com.mifos.core.objects.noncore.DataTable @@ -7,7 +7,12 @@ import com.mifos.core.objects.noncore.DataTable * Created by Aditya Gupta on 10/08/23. */ sealed class DataTableListUiState { - data object Loading: DataTableListUiState() - data class ShowMessage(val messageResId: Int? = null, val message: String? = null): DataTableListUiState() - data class Success(val messageResId: Int? = null, val client: Client? = null): DataTableListUiState() + + data object Loading : DataTableListUiState() + + data class ShowMessage(val messageResId: Int? = null, val message: String? = null) : + DataTableListUiState() + + data class Success(val messageResId: Int? = null, val client: Client? = null) : + DataTableListUiState() } \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListViewModel.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt similarity index 89% rename from mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListViewModel.kt rename to feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt index 244ea18fcfe..f388a1efba0 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListViewModel.kt +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/DataTableListViewModel.kt @@ -1,35 +1,22 @@ -package com.mifos.mifosxdroid.online.datatablelistfragment - -import android.graphics.Typeface -import android.util.TypedValue -import android.view.Gravity -import android.widget.TextView -import androidx.compose.runtime.MutableState -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData +package com.mifos.feature.data_table.dataTableList + import androidx.lifecycle.ViewModel import com.mifos.core.common.utils.Constants import com.mifos.core.data.GroupLoanPayload import com.mifos.core.data.LoansPayload +import com.mifos.core.data.repository.DataTableListRepository import com.mifos.core.objects.accounts.loan.Loans import com.mifos.core.objects.client.Client import com.mifos.core.objects.client.ClientPayload import com.mifos.core.objects.noncore.DataTable import com.mifos.core.objects.noncore.DataTablePayload -import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.formwidgets.FormEditText -import com.mifos.mifosxdroid.formwidgets.FormNumericEditText -import com.mifos.mifosxdroid.formwidgets.FormSpinner -import com.mifos.mifosxdroid.formwidgets.FormToggleButton -import com.mifos.mifosxdroid.formwidgets.FormWidget +import com.mifos.feature.data_table.R import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import rx.Subscriber import rx.android.schedulers.AndroidSchedulers import rx.schedulers.Schedulers -import java.util.ArrayList -import java.util.HashMap import javax.inject.Inject /** @@ -105,12 +92,12 @@ class DataTableListViewModel @Inject constructor(private val repository: DataTab override fun onError(e: Throwable) { _dataTableListUiState.value = - DataTableListUiState.ShowMessage(R.string.generic_failure_message) + DataTableListUiState.ShowMessage(R.string.feature_data_table_generic_failure_message) } override fun onNext(loans: Loans) { _dataTableListUiState.value = - DataTableListUiState.ShowMessage(R.string.loan_creation_success) + DataTableListUiState.ShowMessage(R.string.feature_data_table_loan_creation_success) } }) } @@ -126,12 +113,12 @@ class DataTableListViewModel @Inject constructor(private val repository: DataTab override fun onError(e: Throwable) { _dataTableListUiState.value = - DataTableListUiState.ShowMessage(R.string.generic_failure_message) + DataTableListUiState.ShowMessage(R.string.feature_data_table_generic_failure_message) } override fun onNext(loans: Loans?) { _dataTableListUiState.value = - DataTableListUiState.ShowMessage(R.string.loan_creation_success) + DataTableListUiState.ShowMessage(R.string.feature_data_table_loan_creation_success) } }) @@ -156,7 +143,7 @@ class DataTableListViewModel @Inject constructor(private val repository: DataTab _dataTableListUiState.value = DataTableListUiState.Success(client = client) } else { _dataTableListUiState.value = - DataTableListUiState.Success(messageResId = R.string.waiting_for_checker_approval) + DataTableListUiState.Success(messageResId = R.string.feature_data_table_waiting_for_checker_approval) } } }) diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt new file mode 100644 index 00000000000..7505986b22d --- /dev/null +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormSpinner.kt @@ -0,0 +1,47 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.data_table.dataTableList + +import android.R +import android.content.Context +import android.widget.ArrayAdapter +import android.widget.Spinner +import android.widget.TextView + +/** + * Created by ishankhanna on 01/08/14. + */ +class FormSpinner( + context: Context?, + name: String?, + columnValues: List, + columnValueIds: List +) : FormWidget(context, name) { + private val label: TextView + private val spinner: Spinner + private val spinnerValueIdMap: MutableMap + + init { + label = TextView(context) + label.text = displayText + spinner = Spinner(context) + spinner.adapter = + ArrayAdapter(context!!, R.layout.simple_spinner_item, columnValues) + layout.addView(label) + layout.addView(spinner) + spinnerValueIdMap = HashMap() + for (i in columnValues.indices) { + spinnerValueIdMap[columnValues[i]] = columnValueIds[i] + } + } + + override var value: String + get() = spinner.selectedItem.toString() + set(value) {} + + fun getIdOfSelectedItem(key: String): Int { + return spinnerValueIdMap[key]!! + } +} \ No newline at end of file diff --git a/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt new file mode 100644 index 00000000000..4ee8c561cf9 --- /dev/null +++ b/feature/data-table/src/main/java/com/mifos/feature/data_table/dataTableList/FormWidget.kt @@ -0,0 +1,162 @@ +/* + * This project is licensed under the open source MPL V2. + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.feature.data_table.dataTableList + +import android.content.Context +import android.view.View +import android.widget.LinearLayout +import org.json.JSONObject +import java.util.Locale + +/** + * Created by ishankhanna on 01/08/14. + */ +abstract class FormWidget(context: Context?, name: String?) { + + + /** + * returns the un-modified name of the property this widget represents + */ + var propertyName: String + protected set + + /** + * returns a title case version of this property + * + * @return + */ + var displayText: String + protected set + /** + * returns visual priority + * + * @return + */ + /** + * sets the visual priority of this widget + * essentially this means it's physical location in the form + */ + var priority = 0 + protected var layout: LinearLayout + var returnType: String + + init { + layout = LinearLayout(context) + layout.layoutParams = defaultLayoutParams + layout.orientation = LinearLayout.VERTICAL + layout.setPadding(4, 4, 4, 4) + propertyName = name!! + displayText = name.replace("", " ") + displayText = toTitleCase(displayText) + returnType = SCHEMA_KEY_TEXT + } + // ----------------------------------------------- + // + // view + // + // ----------------------------------------------- + /** + * return LinearLayout containing this widget's view elements + */ + val view : View + get() = layout + + /** + * toggles the visibility of this widget + * + * @param value + */ + fun setVisibility(value: Int) { + layout.visibility = value + } + // ----------------------------------------------- + // + // set / get value + // + // ----------------------------------------------- + /** + * returns value of this widget as String + */// -- override + /** + * sets value of this widget, method should be overridden in sub-class + * + * @param value + */ + open var value: String + get() = "" + set(value) { + // -- override + } + // ----------------------------------------------- + // + // modifiers + // + // ----------------------------------------------- + /** + * sets the hint for the widget, method should be overriden in sub-class + */ + open fun setHint(value: String?) { + // -- override + } + + /** + * sets an object that contains keys for special properties on an object + * + * @param modifiers + */ + fun setModifiers(modifiers: JSONObject?) { + // -- override + } + // ----------------------------------------------- + // + // set / get priority + // + // ----------------------------------------------- + // ----------------------------------------------- + // + // property name mods + // + // ----------------------------------------------- + /** + * takes a property name and modifies + * + * @param s + * @return + */ + fun toTitleCase(s: String): String { + val chars = s.trim { it <= ' ' }.lowercase(Locale.getDefault()).toCharArray() + var found = false + for (i in chars.indices) { + if (!found && Character.isLetter(chars[i])) { + chars[i] = chars[i].uppercaseChar() + found = true + } else if (Character.isWhitespace(chars[i])) { + found = false + } + } + return String(chars) + } + + companion object { + val defaultLayoutParams = LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, + LinearLayout.LayoutParams.WRAP_CONTENT + ) + const val SCHEMA_KEY_TYPE = "type" + const val SCHEMA_KEY_BOOL = "BOOLEAN" + const val SCHEMA_KEY_INT = "INTEGER" + const val SCHEMA_KEY_DECIMAL = "DECIMAL" + const val SCHEMA_KEY_STRING = "STRING" + const val SCHEMA_KEY_TEXT = "TEXT" + const val SCHEMA_KEY_CODELOOKUP = "CODELOOKUP" + const val SCHEMA_KEY_CODEVALUE = "CODEVALUE" + const val SCHEMA_KEY_DATE = "DATE" + const val SCHEMA_KEY_PRIORITY = "priority" + const val SCHEMA_KEY_DEFAULT = "default" + const val SCHEMA_KEY_OPTIONS = "options" + const val SCHEMA_KEY_META = "meta" + const val SCHEMA_KEY_HINT = "hint" + } +} \ No newline at end of file diff --git a/feature/data-table/src/main/res/values/strings.xml b/feature/data-table/src/main/res/values/strings.xml index b614f244384..77a9746522c 100644 --- a/feature/data-table/src/main/res/values/strings.xml +++ b/feature/data-table/src/main/res/values/strings.xml @@ -14,4 +14,15 @@ Added data table successfully Add Data Table Submit + + Failed to fetch data Table + Empty Data Table + No Internet Connection + + Failed to load + Loan Account Created Successfully + Waiting for Checker Approval + Associated Data Tables + Something went wrong + Save \ No newline at end of file diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt index b4b1e564e5f..c2a479efb4d 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/components/Navigation.kt @@ -127,7 +127,7 @@ fun Navigation( checkerInboxTaskGraph( navController = navController ) - + pathTrackingNavGraph( navController = navController ) 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 f6b09422e70..d7c29cf293f 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 @@ -15,7 +15,6 @@ import com.mifos.core.network.DataManager import com.mifos.core.network.datamanager.DataManagerAuth import com.mifos.core.network.datamanager.DataManagerCenter import com.mifos.core.network.datamanager.DataManagerClient -import com.mifos.core.network.datamanager.DataManagerDataTable import com.mifos.core.network.datamanager.DataManagerDocument import com.mifos.core.network.datamanager.DataManagerGroups import com.mifos.core.network.datamanager.DataManagerLoan @@ -57,10 +56,6 @@ import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepository import com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetRepositoryImp import com.mifos.core.data.repository.CreateNewClientRepository import com.mifos.core.data.repository_imp.CreateNewClientRepositoryImp -import com.mifos.mifosxdroid.online.datatable.DataTableRepository -import com.mifos.mifosxdroid.online.datatable.DataTableRepositoryImp -import com.mifos.mifosxdroid.online.datatablelistfragment.DataTableListRepository -import com.mifos.mifosxdroid.online.datatablelistfragment.DataTableListRepositoryImp import com.mifos.mifosxdroid.online.groupdetails.GroupDetailsRepository import com.mifos.mifosxdroid.online.groupdetails.GroupDetailsRepositoryImp import com.mifos.mifosxdroid.online.groupslist.GroupsListRepository @@ -112,11 +107,6 @@ class RepositoryModule { return SavingsAccountSummaryRepositoryImp(dataManagerSavings) } - @Provides - fun providesDataTableRepository(dataManagerDataTable: DataManagerDataTable): DataTableRepository { - return DataTableRepositoryImp(dataManagerDataTable) - } - @Provides fun providesNoteRepository(dataManagerNote: DataManagerNote): NoteRepository { @@ -142,16 +132,6 @@ class RepositoryModule { return CreateNewClientRepositoryImp(dataManagerClient, dataManagerOffices, dataManagerStaff) } - - @Provides - fun providesDataTableListRepository( - dataManagerLoan: DataManagerLoan, - dataManager: DataManager, - dataManagerClient: DataManagerClient - ): DataTableListRepository { - return DataTableListRepositoryImp(dataManagerLoan, dataManager, dataManagerClient) - } - @Provides fun providesSavingsAccountTransactionRepository(dataManagerSavings: DataManagerSavings): SavingsAccountTransactionRepository { return SavingsAccountTransactionRepositoryImp(dataManagerSavings) diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt index 24004003cd4..2f43719cfb7 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatable/DataTableFragment.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.navigation.fragment.findNavController import androidx.navigation.fragment.navArgs import com.mifos.core.objects.noncore.DataTable +import com.mifos.feature.data_table.dataTable.DataTableScreen import com.mifos.mifosxdroid.core.MifosBaseFragment import dagger.hilt.android.AndroidEntryPoint @@ -40,7 +41,8 @@ class DataTableFragment : MifosBaseFragment() { DataTableScreen( tableName = tableName, navigateBack = { - findNavController().popBackStack() }, + findNavController().popBackStack() + }, onClick = { navigateToDatatableData(dataTable = it) } diff --git a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt index e932b93969c..87bae50f00e 100644 --- a/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt +++ b/mifosng-android/src/main/java/com/mifos/mifosxdroid/online/datatablelistfragment/DataTableListFragment.kt @@ -5,40 +5,23 @@ package com.mifos.mifosxdroid.online.datatablelistfragment import android.content.Intent -import android.graphics.Typeface import android.os.Bundle -import android.util.Log -import android.util.TypedValue -import android.view.* -import android.widget.Button -import android.widget.TextView +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup import android.widget.Toast import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.ViewCompositionStrategy import androidx.fragment.app.Fragment -import androidx.fragment.app.viewModels -import androidx.lifecycle.ViewModelProvider -import androidx.navigation.fragment.findNavController import com.mifos.core.common.utils.Constants -import com.mifos.core.data.GroupLoanPayload -import com.mifos.core.data.LoansPayload import com.mifos.core.objects.client.Client -import com.mifos.core.objects.client.ClientPayload -import com.mifos.core.objects.noncore.ColumnHeader import com.mifos.core.objects.noncore.DataTable -import com.mifos.core.objects.noncore.DataTablePayload -import com.mifos.exceptions.RequiredFieldException +import com.mifos.feature.data_table.dataTableList.DataTableListScreen import com.mifos.mifosxdroid.R -import com.mifos.mifosxdroid.core.util.Toaster -import com.mifos.mifosxdroid.databinding.DialogFragmentAddEntryToDatatableBinding -import com.mifos.mifosxdroid.formwidgets.* import com.mifos.mifosxdroid.online.ClientActivity -import com.mifos.mifosxdroid.online.datatable.DataTableScreen import com.mifos.utils.MifosResponseHandler import com.mifos.utils.PrefManager -import com.mifos.utils.SafeUIBlockingUtility import dagger.hilt.android.AndroidEntryPoint -import java.util.* /** * A generic fragment to show the DataTables at the runtime. @@ -54,8 +37,6 @@ import java.util.* @AndroidEntryPoint class DataTableListFragment : Fragment() { - private val viewModel: DataTableListViewModel by viewModels() - private var dataTables: List? = null private var payload: Any? = null private var requestType = 0 @@ -65,17 +46,15 @@ class DataTableListFragment : Fragment() { container: ViewGroup?, savedInstanceState: Bundle? ): View { - viewModel.initArgs( - dataTables = dataTables ?: listOf(), - requestType = requestType, - payload = payload, - formWidgetsList = createFormWidgetList(), - ) return ComposeView(requireContext()).apply { setViewCompositionStrategy(ViewCompositionStrategy.DisposeOnViewTreeLifecycleDestroyed) setContent { DataTableListScreen( + dataTables = dataTables ?: listOf(), + requestType = requestType, + payload = payload, + formWidgetsList = mutableListOf(), // TODO remove FormWidget after api fix onBackPressed = { requireActivity().supportFragmentManager.popBackStack() }, clientCreated = { showClientCreatedSuccessfully(it) } ) @@ -83,36 +62,6 @@ class DataTableListFragment : Fragment() { } } - private fun createFormWidgetList(): MutableList> { - return dataTables?.map { createForm(it) }?.toMutableList() ?: mutableListOf() - } - - private fun createForm(table: DataTable): List { - return table.columnHeaderData - .filterNot { it.columnPrimaryKey == true } - .map { createFormWidget(it) } - } - - private fun createFormWidget(columnHeader: ColumnHeader): FormWidget { - return when (columnHeader.columnDisplayType) { - FormWidget.SCHEMA_KEY_STRING, FormWidget.SCHEMA_KEY_TEXT -> FormEditText(activity, columnHeader.dataTableColumnName) - FormWidget.SCHEMA_KEY_INT -> FormNumericEditText(activity, columnHeader.dataTableColumnName).apply { returnType = FormWidget.SCHEMA_KEY_INT } - FormWidget.SCHEMA_KEY_DECIMAL -> FormNumericEditText(activity, columnHeader.dataTableColumnName).apply { returnType = FormWidget.SCHEMA_KEY_DECIMAL } - FormWidget.SCHEMA_KEY_CODELOOKUP, FormWidget.SCHEMA_KEY_CODEVALUE -> createFormSpinner(columnHeader) - FormWidget.SCHEMA_KEY_DATE -> FormEditText(activity, columnHeader.dataTableColumnName).apply { setIsDateField(true, requireActivity().supportFragmentManager) } - FormWidget.SCHEMA_KEY_BOOL -> FormToggleButton(activity, columnHeader.dataTableColumnName) - else -> FormEditText(activity, columnHeader.dataTableColumnName) - } - } - - private fun createFormSpinner(columnHeader: ColumnHeader): FormSpinner { - val columnValueStrings = columnHeader.columnValues.mapNotNull { it.value } - val columnValueIds = columnHeader.columnValues.mapNotNull { it.id } - return FormSpinner(activity, columnHeader.dataTableColumnName, columnValueStrings, columnValueIds).apply { - returnType = FormWidget.SCHEMA_KEY_CODEVALUE - } - } - private fun showClientCreatedSuccessfully(client: Client) { requireActivity().supportFragmentManager.popBackStack() requireActivity().supportFragmentManager.popBackStack()