Skip to content

refactor: refactor NewIndividual Collection Sheet screen to jetpack compose with multi module #2100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 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 @@ -2,8 +2,10 @@ package com.mifos.core.data.di

import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.GroupsListRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.GroupsListRepositoryImpl
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -16,6 +18,9 @@ abstract class DataModule {
@Binds
abstract fun bindCheckerInboxTasksRepository(impl: CheckerInboxTasksRepositoryImp): CheckerInboxTasksRepository

@Binds
abstract fun bindNewIndividualCollectionSheetRepository(impl: NewIndividualCollectionSheetRepositoryImp): NewIndividualCollectionSheetRepository

@Binds
internal abstract fun provideGroupListRepository(
groupsListRepositoryImpl: GroupsListRepositoryImpl
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mifos.mifosxdroid.online.collectionsheetindividual
package com.mifos.core.data.repository

import com.mifos.core.network.model.RequestCollectionSheetPayload
import com.mifos.core.objects.collectionsheet.IndividualCollectionSheet
Expand All @@ -11,12 +11,12 @@ import rx.Observable
*/
interface NewIndividualCollectionSheetRepository {

fun getIndividualCollectionSheet(
suspend fun getIndividualCollectionSheet(
payload: RequestCollectionSheetPayload?
): Observable<IndividualCollectionSheet>
): IndividualCollectionSheet

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

fun getStaffInOffice(officeId: Int): Observable<List<Staff>>
suspend fun getStaffInOffice(officeId: Int): List<Staff>

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

import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.network.DataManager
import com.mifos.core.network.datamanager.DataManagerCollectionSheet
import com.mifos.core.network.model.RequestCollectionSheetPayload
Expand All @@ -12,20 +13,20 @@ import javax.inject.Inject
/**
* Created by Aditya Gupta on 10/08/23.
*/
class NewIndividualCollectionSheetRepositoryImp @Inject internal constructor(
class NewIndividualCollectionSheetRepositoryImp @Inject constructor(
private val dataManager: DataManager,
private val dataManagerCollection: DataManagerCollectionSheet
) : NewIndividualCollectionSheetRepository {

override fun getIndividualCollectionSheet(payload: RequestCollectionSheetPayload?): Observable<IndividualCollectionSheet> {
override suspend fun getIndividualCollectionSheet(payload: RequestCollectionSheetPayload?): IndividualCollectionSheet {
return dataManagerCollection.getIndividualCollectionSheet(payload)
}

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

override fun getStaffInOffice(officeId: Int): Observable<List<Staff>> {
override suspend fun getStaffInOffice(officeId: Int): List<Staff> {
return dataManager.getStaffInOffice(officeId)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,17 @@
package com.mifos.core.objects.collectionsheet

import android.os.Parcel
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.mifos.core.objects.accounts.loan.PaymentTypeOptions
import kotlinx.parcelize.Parcelize

/**
* Created by Tarun on 06-07-2017.
*/
class IndividualCollectionSheet() : Parcelable {
var dueDate: IntArray? = null
@Parcelize
data class IndividualCollectionSheet(
var dueDate: IntArray? = null,

@SerializedName("clients")
var clients: ArrayList<ClientCollectionSheet>? = null
var clients: ArrayList<ClientCollectionSheet>? = null,

var paymentTypeOptions: ArrayList<PaymentTypeOptions>? = null

constructor(parcel: Parcel) : this() {
dueDate = parcel.createIntArray()
clients = ArrayList<ClientCollectionSheet>().apply {
parcel.readList(this, ClientCollectionSheet::class.java.classLoader)
}
paymentTypeOptions = ArrayList<PaymentTypeOptions>().apply {
parcel.readList(this, PaymentTypeOptions::class.java.classLoader)
}
}

override fun writeToParcel(dest: Parcel, flags: Int) {
dest.writeIntArray(dueDate)
dest.writeList(clients)
dest.writeList(paymentTypeOptions)
}

override fun describeContents(): Int {
return 0
}

companion object CREATOR : Parcelable.Creator<IndividualCollectionSheet> {
override fun createFromParcel(parcel: Parcel): IndividualCollectionSheet {
return IndividualCollectionSheet(parcel)
}

override fun newArray(size: Int): Array<IndividualCollectionSheet?> {
return arrayOfNulls(size)
}
}
}
) : Parcelable
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.CalendarToday
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
Expand Down Expand Up @@ -80,4 +83,35 @@ fun MifosOutlinedTextField(
}
}
)
}


@Composable
fun MifosDatePickerTextField(
value: String,
label: Int,
openDatePicker: () -> Unit
) {
OutlinedTextField(
value = value,
onValueChange = { },
label = { Text(text = stringResource(id = label)) },
readOnly = true,
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp),
maxLines = 1,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp)
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon = {
IconButton(onClick = { openDatePicker() }) {
Icon(imageVector = Icons.Default.CalendarToday, null)
}
}
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,26 @@ 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.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(
icon: ImageVector?,
title: String?,
onBackPressed: () -> Unit,
actions: @Composable () -> Unit,
topBar: @Composable () -> Unit,
snackbarHostState: SnackbarHostState?,
bottomBar: @Composable () -> Unit,
content: @Composable (PaddingValues) -> Unit
) {

Scaffold(
topBar = {
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() }
)
},
topBar = topBar,
snackbarHost = { snackbarHostState?.let { SnackbarHost(it) } },
containerColor = White,
bottomBar = bottomBar
) { padding ->
content(padding)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@file:OptIn(ExperimentalMaterial3Api::class)

package com.mifos.core.designsystem.component

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowDropDown
import androidx.compose.material.icons.filled.ArrowDropUp
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ExposedDropdownMenuBox
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mifos.core.designsystem.theme.BluePrimary
import com.mifos.core.designsystem.theme.BluePrimaryDark

@Composable
fun MifosTextFieldDropdown(
value: String,
onValueChanged: (String) -> Unit,
onOptionSelected: (Int, String) -> Unit,
label: Int,
options: List<String>
) {
var isExpended by remember { mutableStateOf(false) }

ExposedDropdownMenuBox(
expanded = isExpended,
onExpandedChange = { isExpended = it }
) {
OutlinedTextField(
value = value,
onValueChange = { onValueChanged(it) },
label = { Text(text = stringResource(id = label)) },
modifier = Modifier
.fillMaxWidth()
.padding(start = 16.dp, end = 16.dp)
.menuAnchor(),
maxLines = 1,
colors = OutlinedTextFieldDefaults.colors(
focusedBorderColor = if (isSystemInDarkTheme()) BluePrimaryDark else BluePrimary,
),
textStyle = LocalDensity.current.run {
TextStyle(fontSize = 18.sp)
},
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Next),
trailingIcon = {
val image =
if (isExpended) Icons.Default.ArrowDropUp else Icons.Default.ArrowDropDown
IconButton(onClick = { isExpended = !isExpended }) {
Icon(imageVector = image, null)
}
}
)

ExposedDropdownMenu(
expanded = isExpended,
onDismissRequest = { isExpended = false }
) {
options.forEachIndexed { index, value ->
DropdownMenuItem(
text = { Text(text = value) },
onClick = {
isExpended = false
onOptionSelected(index, value)
}
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ class DataManager {
/**
* Offices API
*/
val offices: Observable<List<Office>>
get() = mBaseApiManager.officeApi.allOffices
suspend fun offices(): List<Office> = mBaseApiManager.officeApi.allOffices()

/**
* Staff API
*/
fun getStaffInOffice(officeId: Int): Observable<List<Staff>> {
suspend fun getStaffInOffice(officeId: Int): List<Staff> {
return mBaseApiManager.staffApi.getStaffForOffice(officeId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class DataManagerCollectionSheet @Inject constructor(
/**
* Individual CollectionSheet API
*/
fun getIndividualCollectionSheet(
suspend fun getIndividualCollectionSheet(
payload: RequestCollectionSheetPayload?
): Observable<IndividualCollectionSheet> {
): IndividualCollectionSheet {
return mBaseApiManager.collectionSheetApi.getIndividualCollectionSheet(payload)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import rx.Observable
*/
interface CollectionSheetService {
@POST(APIEndPoint.COLLECTION_SHEET + "?command=generateCollectionSheet")
fun getIndividualCollectionSheet(
suspend fun getIndividualCollectionSheet(
@Body payload: RequestCollectionSheetPayload?
): Observable<IndividualCollectionSheet>
): IndividualCollectionSheet

@POST(APIEndPoint.COLLECTION_SHEET + "?command=saveCollectionSheet")
fun saveindividualCollectionSheet(
Expand Down
Loading
Loading