Skip to content

Commit

Permalink
refactor: move data table screens to data table module
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Aug 19, 2024
1 parent cdc9bd1 commit c0b376e
Show file tree
Hide file tree
Showing 17 changed files with 366 additions and 140 deletions.
10 changes: 10 additions & 0 deletions core/data/src/main/java/com/mifos/core/data/di/DataModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -8,15 +8,13 @@ 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
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
Expand All @@ -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
Expand Down Expand Up @@ -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
) {
Expand All @@ -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 -> {
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -218,7 +215,7 @@ class DataTablePreviewProvider : PreviewParameterProvider<DataTableUiState> {
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)
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.datatable
package com.mifos.feature.data_table.dataTable

import com.mifos.core.objects.noncore.DataTable

Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<DataTable>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -45,23 +42,29 @@ 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<DataTable>,
requestType :Int,
payload : Any?,
formWidgetsList : MutableList<List<FormWidget>>,
viewModel: DataTableListViewModel = hiltViewModel(),
onBackPressed: () -> Unit,
clientCreated: (Client) -> Unit
) {
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(),
Expand All @@ -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 ->
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -287,4 +290,77 @@ fun DataTableListScreenPreview() {
clientCreated = { },
onSaveClicked = { }
)
}
}


//private fun createFormWidgetList(): MutableList<List<FormWidget>> {
// return dataTables?.map { createForm(it) }?.toMutableList() ?: mutableListOf()
//}
//
//private fun createForm(table: DataTable): List<FormWidget> {
// 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)
// }
//}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
}
Loading

0 comments on commit c0b376e

Please sign in to comment.