Skip to content

Commit

Permalink
refactor: refactor client details screen to compose
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya-gupta99 committed Mar 18, 2024
1 parent 1b56478 commit 9af5b0f
Show file tree
Hide file tree
Showing 24 changed files with 1,372 additions and 787 deletions.
24 changes: 24 additions & 0 deletions core/common/src/main/java/com/mifos/core/common/utils/Utils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.mifos.core.common.utils

import java.text.DateFormat
import java.util.Calendar
import java.util.TimeZone

object Utils {

fun getStringOfDate(dateObj: List<Int?>): String {
val calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"))
dateObj.getOrNull(0)?.let { year ->
calendar.set(Calendar.YEAR, year)
}
dateObj.getOrNull(1)?.let { month ->
calendar.set(Calendar.MONTH, month - 1)
}
dateObj.getOrNull(2)?.let { day ->
calendar.set(Calendar.DAY_OF_MONTH, day)
}
val dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM)
return dateFormat.format(calendar.time)
}

}
7 changes: 7 additions & 0 deletions core/designsystem/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -46,6 +47,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation(project(":core:datastore"))
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand All @@ -61,4 +63,9 @@ dependencies {

// coil
implementation("io.coil-kt:coil-compose:2.5.0")

//DBFlow dependencies
kapt("com.github.raizlabs.dbflow.dbflow:dbflow-processor:3.1.1")
implementation("com.github.raizlabs.dbflow.dbflow:dbflow:3.1.1")
kapt("com.github.raizlabs.dbflow:dbflow-processor:4.2.4")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.animation.core.LinearOutSlowInEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -47,9 +48,12 @@ import com.mifos.core.designsystem.theme.Black
import com.mifos.core.designsystem.theme.BlueSecondary
import com.mifos.core.designsystem.theme.DarkGray
import com.mifos.core.designsystem.theme.White
import com.mifos.core.objects.accounts.loan.LoanAccount
import com.mifos.core.objects.accounts.savings.DepositType
import com.mifos.core.objects.accounts.savings.SavingsAccount

@Composable
fun MifosAccountExpendableCard(accountType: String) {
fun MifosLoanAccountExpendableCard(accountType: String, loanAccounts: List<LoanAccount>,loanAccountSelected : (Int)->Unit) {

var expendableState by remember { mutableStateOf(false) }
val rotateState by animateFloatAsState(
Expand Down Expand Up @@ -106,17 +110,15 @@ fun MifosAccountExpendableCard(accountType: String) {
if (expendableState) {

Spacer(modifier = Modifier.height(10.dp))
MifosAccountsLazyColumn()
MifosLoanAccountsLazyColumn(loanAccounts,loanAccountSelected)
}
}
}
}


@Composable
fun MifosAccountsLazyColumn() {

val array = listOf("first", "second", "third", "fourth")
fun MifosLoanAccountsLazyColumn(loanAccounts: List<LoanAccount>,loanAccountSelected : (Int)->Unit) {

Card(
modifier = Modifier
Expand All @@ -127,26 +129,78 @@ fun MifosAccountsLazyColumn() {
) {
LazyColumn(
modifier = Modifier
.height((array.size * 48).dp)
.height((loanAccounts.size * 52).dp)
.padding(6.dp)
) {
items(array) {
items(loanAccounts) { loanAccount ->
Row(
modifier = Modifier.padding(5.dp),
modifier = Modifier.padding(5.dp).clickable(onClick = { loanAccount.id?.let {
loanAccountSelected(
it
)
} }),
verticalAlignment = Alignment.CenterVertically
) {
Canvas(modifier = Modifier
.size(20.dp)
.padding(4.dp), onDraw = {
drawCircle(color = Color.Yellow)
drawCircle(
color = when {
loanAccount.status?.active == true -> {
Color.Green
}

loanAccount.status?.waitingForDisbursal == true -> {
Color.Blue
}

loanAccount.status?.pendingApproval == true -> {
Color.Yellow
}

loanAccount.status?.active == true && loanAccount.inArrears == true -> {
Color.Red
}

else -> {
Color.DarkGray
}
}
)
})
Column(
modifier = Modifier
.weight(1f)
.padding(start = 4.dp)
) {
loanAccount.productName?.let {
Text(
text = it,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_regular))
),
color = Black,
textAlign = TextAlign.Start
)
}
Text(
text = "Office",
text = loanAccount.accountNo.toString(),
style = TextStyle(
fontSize = 14.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_light))
),
color = DarkGray,
textAlign = TextAlign.Start
)
}
loanAccount.productId?.let {
Text(
text = it.toString(),
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Normal,
Expand All @@ -156,8 +210,148 @@ fun MifosAccountsLazyColumn() {
color = Black,
textAlign = TextAlign.Start
)
}
}
}
}
}
}


@Composable
fun MifosSavingsAccountExpendableCard(accountType: String, savingsAccount: List<SavingsAccount>,savingsAccountSelected : (Int,DepositType)->Unit) {

var expendableState by remember { mutableStateOf(false) }
val rotateState by animateFloatAsState(
targetValue = if (expendableState) 180f else 0f,
label = ""
)

Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.animateContentSize(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
),
shape = RoundedCornerShape(22.dp),
colors = CardDefaults.cardColors(BlueSecondary)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(10.dp),
) {
Row(
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier
.weight(1f)
.padding(start = 8.dp),
text = accountType,
style = TextStyle(
fontSize = 18.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_regular))
),
color = Black,
textAlign = TextAlign.Start
)
IconButton(
modifier = Modifier
.size(24.dp),
onClick = { expendableState = !expendableState }) {
Icon(
modifier = Modifier.rotate(rotateState),
imageVector = Icons.Default.KeyboardArrowDown, contentDescription = null
)
}
}

if (expendableState) {

Spacer(modifier = Modifier.height(10.dp))
MifosSavingsAccountsLazyColumn(savingsAccount,savingsAccountSelected)
}
}
}
}


@Composable
fun MifosSavingsAccountsLazyColumn(savingsAccounts: List<SavingsAccount>,savingsAccountSelected : (Int,DepositType)->Unit) {

Card(
modifier = Modifier
.fillMaxWidth()
.padding(8.dp),
shape = RoundedCornerShape(22.dp),
colors = CardDefaults.cardColors(White)
) {
LazyColumn(
modifier = Modifier
.height((savingsAccounts.size * 50).dp)
.padding(6.dp)
) {
items(savingsAccounts) { savingsAccount ->
Row(
modifier = Modifier.padding(5.dp).clickable(onClick = { savingsAccount.id?.let {
savingsAccount.depositType?.let { it1 ->
savingsAccountSelected(
it, it1
)
}
} }),
verticalAlignment = Alignment.CenterVertically
) {
Canvas(modifier = Modifier
.size(20.dp)
.padding(4.dp), onDraw = {
drawCircle(
color = when {
savingsAccount.status?.active == true -> {
Color.Green
}

savingsAccount.status?.approved == true -> {
Color.Blue
}

savingsAccount.status?.submittedAndPendingApproval == true -> {
Color.Yellow
}

else -> {
Color.DarkGray
}
}
)
})
Column(
modifier = Modifier
.weight(1f)
.padding(start = 4.dp)
) {
savingsAccount.productName?.let {
Text(
text = it,
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_regular))
),
color = Black,
textAlign = TextAlign.Start
)
}
Text(
text = "Office Number",
text = savingsAccount.accountNo.toString(),
style = TextStyle(
fontSize = 14.sp,
fontWeight = FontWeight.Normal,
Expand All @@ -168,17 +362,19 @@ fun MifosAccountsLazyColumn() {
textAlign = TextAlign.Start
)
}
Text(
text = "0.0",
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_regular))
),
color = Black,
textAlign = TextAlign.Start
)
savingsAccount.productId?.let {
Text(
text = it.toString(),
style = TextStyle(
fontSize = 16.sp,
fontWeight = FontWeight.Normal,
fontStyle = FontStyle.Normal,
fontFamily = FontFamily(Font(R.font.outfit_regular))
),
color = Black,
textAlign = TextAlign.Start
)
}
}
}
}
Expand Down
Loading

0 comments on commit 9af5b0f

Please sign in to comment.