-
Notifications
You must be signed in to change notification settings - Fork 469
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/composeScreen/AccountScreen.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), {}, {}) | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
mifospay/src/main/java/org/mifos/mobilewallet/mifospay/bank/composeScreen/AddAccountChip.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
MifosTheme { | ||
AddAccountChip(onAddAccountClicked = { }) | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...src/main/java/org/mifos/mobilewallet/mifospay/bank/composeScreen/EmptyStatePlaceHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
...pay/src/main/java/org/mifos/mobilewallet/mifospay/bank/composeScreen/ListItemWithImage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
), | ||
{} | ||
) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done