Skip to content
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

migrated account fragment to jetpack compose #1561

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package org.mifos.mobilewallet.mifospay.bank.composeScreen

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Text
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mifos.mobilewallet.model.domain.BankAccountDetails
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.bank.viewmodel.BankAccountsViewModel
import org.mifos.mobilewallet.mifospay.designsystem.theme.MifosTheme

@Composable
fun AccountScreen(
viewModel: BankAccountsViewModel = hiltViewModel(),
onAddAccountClicked: () -> Unit,
onAccountClicked: (BankAccountDetails) -> Unit
) {
val bankAccountDetails = viewModel.bankAccountDetailsList
AccountScreenContent(bankAccountDetails, onAddAccountClicked, onAccountClicked)
}

@Composable
fun AccountScreenContent(
bankAccountDetails: List<BankAccountDetails>,
onAddAccountClicked: () -> Unit,
onAccountClicked: (BankAccountDetails) -> Unit
) {
Column(
modifier = Modifier
.fillMaxSize()
) {
Text(
text = stringResource(id = R.string.linked_bank_account),
fontSize = 16.sp,
color = colorResource(id = R.color.colorTextPrimary),
modifier = Modifier.padding(
top = 48.dp,
start = 24.dp
)
)
if (bankAccountDetails.isEmpty()) {
Column(
modifier = Modifier
.weight(1f)
.fillMaxWidth()
.padding(top = 48.dp, bottom = 70.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally

) {
EmptyStatePlaceHolder(
title = stringResource(id = R.string.empty_no_accounts_title),
subtitle = stringResource(id = R.string.empty_no_accounts_subtitle),
drawableResId = R.drawable.ic_empty_state
)
}
} else {
LazyColumn(
modifier = Modifier
.weight(1f)
.padding(top = 48.dp)
.fillMaxSize(),
state = rememberLazyListState()
) {
items(bankAccountDetails.size) { index ->
val bankAccount = bankAccountDetails[index]
ListItemWithImage(
bankAccount = bankAccount,
onAccountClicked
)
}
}
}
Spacer(modifier = Modifier.height(16.dp))
AddAccountChip(
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(bottom = 128.dp),
onAddAccountClicked = onAddAccountClicked
)
}
}

@Preview
@Composable
fun AccountScreenPreview() {
var bankAccountDetails = listOf(
BankAccountDetails(
"SBI", "Ankur Sharma", "New Delhi",
"1234567890", "Savings"
),
BankAccountDetails(
"HDFC", "Mandeep Singh ", "Uttar Pradesh",
"1234567890", "Savings"
),
BankAccountDetails(
"ANDHRA", "Rakesh anna ", "Telegana",
"1234567890", "Savings"
),
BankAccountDetails(
"PNB", "luv Pro ", "Gujrat",
"1234567890", "Savings"
),
BankAccountDetails(
"HDF", "Harry potter ", "Hogwarts",
"1234567890", "Savings"
),
BankAccountDetails(
"GCI", "JIGME ", "JAMMU",
"1234567890", "Savings"
),
BankAccountDetails(
"FCI", "NISHU BOII ", "ASSAM",
"1234567890", "Savings"
),
BankAccountDetails(
"SBI", "Ankur Sharma", "New Delhi",
"1234567890", "Savings"
),
BankAccountDetails(
"HDFC", "Mandeep Singh ", "Uttar Pradesh",
"1234567890", "Savings"
),
BankAccountDetails(
"ANDHRA", "Rakesh anna ", "Telegana",
"1234567890", "Savings"
),
BankAccountDetails(
"PNB", "luv Pro ", "Gujrat",
"1234567890", "Savings"
)
)
MifosTheme {
AccountScreenContent(bankAccountDetails, {}, {})
}
}

@Preview
@Composable
fun EmptyAccountScreenPreview() {
MifosTheme {
AccountScreenContent(bankAccountDetails = emptyList(), {}, {})
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.mifos.mobilewallet.mifospay.bank.composeScreen

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Chip
import androidx.compose.material.ChipDefaults
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

@OptIn(ExperimentalMaterialApi::class)
@Composable
fun AddAccountChip(modifier: Modifier = Modifier, onAddAccountClicked: () -> Unit) {
Chip(
modifier = modifier,
onClick = { onAddAccountClicked() },
colors = ChipDefaults.chipColors(
backgroundColor = Color.Black,
contentColor = colorResource(id = R.color.colorPrimary)
),
border = BorderStroke(width = 1.dp, color = Color.Gray),
) {
Icon(
imageVector = Icons.Default.Add,
contentDescription = null,
tint = colorResource(id = R.color.colorPrimary),
modifier = Modifier.padding(end = 4.dp)
)
Text(
text = stringResource(id = R.string.add_account),
modifier = Modifier.padding(horizontal = 8.dp, vertical = 4.dp),
color = colorResource(id = R.color.colorPrimary),
textAlign = TextAlign.Center
)
}
}

@Preview
@Composable
fun AddAccountChipPreview() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap around the MifosTheme every preview function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

MifosTheme {
AddAccountChip(onAddAccountClicked = { })
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.mifos.mobilewallet.mifospay.bank.composeScreen

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.text.BasicText
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

@Composable
fun EmptyStatePlaceHolder(
title: String,
subtitle: String,
drawableResId: Int
) {
Column(
modifier = Modifier
.padding(16.dp),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Image(
painter = painterResource(id = drawableResId),
contentDescription = "Content Description Placeholder",
modifier = Modifier.size(120.dp)
)

Spacer(modifier = Modifier.height(16.dp))

BasicText(
text = title,
style = MaterialTheme.typography.body1
)

Spacer(modifier = Modifier.height(8.dp))

BasicText(
text = subtitle,
style = MaterialTheme.typography.body2
)
}
}

@Preview
@Composable
fun PlaceholderStateLayoutPreview() {
MifosTheme {
EmptyStatePlaceHolder(
title = "No Bank Accounts Linked",
subtitle = "You have not linked any bank accounts yet",
drawableResId = R.drawable.ic_empty_state
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package org.mifos.mobilewallet.mifospay.bank.composeScreen

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material.Divider
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.mifos.mobilewallet.model.domain.BankAccountDetails
import org.mifos.mobilewallet.mifospay.R
import org.mifos.mobilewallet.mifospay.theme.MifosTheme

@Composable
fun ListItemWithImage(
bankAccount: BankAccountDetails,
onAccountClicked: (BankAccountDetails) -> Unit
) {
var margin = dimensionResource(id = R.dimen.marginItemsInSectionSmall)
var title = bankAccount.bankName ?: ""
var subtitle = bankAccount.accountholderName ?: ""
var optionalCaption = bankAccount.branch ?: ""
Column(
modifier = Modifier.clickable {
onAccountClicked(bankAccount)
}
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(
top = margin
),
) {
Icon(
painter = painterResource(id = R.drawable.ic_bank),
contentDescription = "bank`s icon",
modifier = Modifier
.align(Alignment.CenterVertically)
.padding(
start = margin,
end = margin
)
.height(dimensionResource(id = R.dimen.listImageSize))
.width(dimensionResource(id = R.dimen.listImageSize))
)

Column {
Text(
text = subtitle,
color = colorResource(id = R.color.colorTextSecondary),
)
Text(
text = title,
color = colorResource(id = R.color.colorTextPrimary),
modifier = Modifier.padding(top = 4.dp),
fontSize = 16.sp
)
}
Column(
horizontalAlignment = Alignment.End,
modifier = Modifier.fillMaxWidth()
) {
Text(
text = optionalCaption,
modifier = Modifier.padding(
top = margin,
bottom = margin,
end = margin,
start = margin
),
fontSize = 12.sp,
color = colorResource(id = R.color.colorTextSecondary)
)
}
}
Divider(modifier = Modifier.padding(start = 8.dp, end = 8.dp, top = 8.dp, bottom = 8.dp))
}
}

@Preview
@Composable
fun ListItemPreview() {
MifosTheme {
ListItemWithImage(
bankAccount = BankAccountDetails(
"SBI", "Ankur Sharma", "New Delhi",
"1234567890", "Savings"
),
{}
)
}
}
Loading
Loading