Skip to content

Commit

Permalink
refactor: refactor NewIndividual Collection Sheet screen to jetpack c…
Browse files Browse the repository at this point in the history
…ompose with multi module
  • Loading branch information
Aditya-gupta99 committed May 19, 2024
1 parent d9cd3b1 commit 7b89da2
Show file tree
Hide file tree
Showing 28 changed files with 1,206 additions and 502 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.mifos.core.data.di

import com.mifos.core.data.repository.CheckerInboxTasksRepository
import com.mifos.core.data.repository.NewIndividualCollectionSheetRepository
import com.mifos.core.data.repository_imp.CheckerInboxTasksRepositoryImp
import com.mifos.core.data.repository_imp.NewIndividualCollectionSheetRepositoryImp
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
Expand All @@ -13,4 +15,7 @@ abstract class CheckerInboxTasksModule {

@Binds
abstract fun bindCheckerInboxTasksRepository(impl: CheckerInboxTasksRepositoryImp): CheckerInboxTasksRepository

@Binds
abstract fun bindNewIndividualCollectionSheetRepository(impl: NewIndividualCollectionSheetRepositoryImp): NewIndividualCollectionSheetRepository
}
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 @@ -73,5 +73,21 @@ fun MifosScaffold(
) { padding ->
content(padding)
}
}

@Composable
fun MifosScaffoldNoTopBar(
snackbarHostState: SnackbarHostState?,
bottomBar: @Composable () -> Unit,
content: @Composable (PaddingValues) -> Unit
) {

Scaffold(
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ interface OfficeService {
*
* @param listOfOfficesCallback
*/
@get:GET(APIEndPoint.OFFICES)
val allOffices: Observable<List<Office>>
@GET(APIEndPoint.OFFICES)
suspend fun allOffices(): List<Office>
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import rx.Observable
*/
interface StaffService {
@GET(APIEndPoint.STAFF + "?status=all")
fun getStaffForOffice(@Query("officeId") officeId: Int): Observable<List<Staff>>
suspend fun getStaffForOffice(@Query("officeId") officeId: Int): List<Staff>

@get:GET(APIEndPoint.STAFF)
val allStaff: Observable<List<Staff>>
Expand Down
Loading

0 comments on commit 7b89da2

Please sign in to comment.