-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved Accounts to feature module (#1670)
Co-authored-by: Rajan Maurya <[email protected]>
- Loading branch information
1 parent
23649dd
commit 5133f20
Showing
17 changed files
with
1,287 additions
and
0 deletions.
There are no files selected for viewing
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 @@ | ||
/build |
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,18 @@ | ||
plugins { | ||
alias(libs.plugins.mifospay.android.feature) | ||
alias(libs.plugins.mifospay.android.library.compose) | ||
} | ||
|
||
android { | ||
namespace = "org.mifospay.feature.bank.accounts" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.data) | ||
implementation(libs.compose.material) | ||
implementation(libs.androidx.appcompat) | ||
|
||
//Remove the following implementations after completing migration | ||
implementation(projects.mifospay) | ||
implementation("com.mifos.mobile:mifos-passcode:0.3.0@aar") | ||
} |
Empty file.
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,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
24 changes: 24 additions & 0 deletions
24
...counts/src/androidTest/java/org/mifospay/feature/bank/accounts/ExampleInstrumentedTest.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,24 @@ | ||
package org.mifospay.feature.bank.accounts | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("org.mifospay.feature.bank.accounts.test", appContext.packageName) | ||
} | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
</manifest> |
114 changes: 114 additions & 0 deletions
114
feature/accounts/src/main/kotlin/org/mifospay/feature/bank/accounts/AccountViewModel.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,114 @@ | ||
package org.mifospay.feature.bank.accounts | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.viewModelScope | ||
import com.mifospay.core.model.domain.BankAccountDetails | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import kotlinx.coroutines.launch | ||
import java.util.Random | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class AccountViewModel @Inject constructor() : ViewModel() { | ||
|
||
private val _bankAccountDetailsList = MutableStateFlow<List<BankAccountDetails>>(emptyList()) | ||
val bankAccountDetailsList: StateFlow<List<BankAccountDetails>> = _bankAccountDetailsList | ||
|
||
private val _accountsUiState = MutableStateFlow<AccountsUiState>(AccountsUiState.Loading) | ||
val accountsUiState: StateFlow<AccountsUiState> = _accountsUiState | ||
|
||
init { | ||
fetchLinkedAccount() | ||
} | ||
|
||
private val _isRefreshing = MutableStateFlow(false) | ||
val isRefreshing: StateFlow<Boolean> get() = _isRefreshing.asStateFlow() | ||
|
||
fun refresh() { | ||
viewModelScope.launch { | ||
_isRefreshing.emit(true) | ||
fetchLinkedAccount() | ||
_isRefreshing.emit(false) | ||
} | ||
} | ||
|
||
private val mRandom = Random() | ||
|
||
private fun fetchLinkedAccount() { | ||
viewModelScope.launch { | ||
_accountsUiState.value = AccountsUiState.Loading | ||
delay(2000) | ||
val linkedAccounts = fetchSampleLinkedAccounts() | ||
_bankAccountDetailsList.value = linkedAccounts | ||
_accountsUiState.value = if (linkedAccounts.isEmpty()) { | ||
AccountsUiState.Empty | ||
} else { | ||
AccountsUiState.LinkedAccounts(linkedAccounts) | ||
} | ||
} | ||
} | ||
|
||
private fun fetchSampleLinkedAccounts(): List<BankAccountDetails> { | ||
return listOf( | ||
BankAccountDetails( | ||
"SBI", "Ankur Sharma", "New Delhi", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"HDFC", "Mandeep Singh", "Uttar Pradesh", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"ANDHRA", "Rakesh anna", "Telegana", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"PNB", "luv Pro", "Gujrat", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"HDF", "Harry potter", "Hogwarts", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"GCI", "JIGME", "JAMMU", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
), | ||
BankAccountDetails( | ||
"FCI", "NISHU BOII", "ASSAM", | ||
mRandom.nextInt().toString() + " ", "Savings" | ||
) | ||
) | ||
} | ||
|
||
fun addBankAccount(bankAccountDetails: BankAccountDetails) { | ||
viewModelScope.launch { | ||
val updatedList = _bankAccountDetailsList.value.toMutableList().apply { | ||
add(bankAccountDetails) | ||
} | ||
_bankAccountDetailsList.value = updatedList | ||
_accountsUiState.value = AccountsUiState.LinkedAccounts(updatedList) | ||
} | ||
} | ||
|
||
fun updateBankAccount(index: Int, bankAccountDetails: BankAccountDetails) { | ||
viewModelScope.launch { | ||
val updatedList = _bankAccountDetailsList.value.toMutableList().apply { | ||
this[index] = bankAccountDetails | ||
} | ||
_bankAccountDetailsList.value = updatedList | ||
_accountsUiState.value = AccountsUiState.LinkedAccounts(updatedList) | ||
} | ||
} | ||
} | ||
|
||
sealed class AccountsUiState { | ||
data object Loading : AccountsUiState() | ||
data object Empty : AccountsUiState() | ||
data object Error : AccountsUiState() | ||
data class LinkedAccounts(val linkedAccounts: List<BankAccountDetails>) : AccountsUiState() | ||
} |
83 changes: 83 additions & 0 deletions
83
feature/accounts/src/main/kotlin/org/mifospay/feature/bank/accounts/AccountsItem.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,83 @@ | ||
package org.mifospay.feature.bank.accounts | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material3.CardDefaults | ||
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.graphics.Color | ||
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.mifospay.core.model.domain.BankAccountDetails | ||
import org.mifospay.R | ||
import org.mifospay.core.designsystem.component.MifosCard | ||
import org.mifospay.core.designsystem.theme.mifosText | ||
import org.mifospay.core.designsystem.theme.styleMedium16sp | ||
|
||
@Composable | ||
fun AccountsItem( | ||
bankAccountDetails: BankAccountDetails, | ||
onAccountClicked: () -> Unit | ||
) { | ||
MifosCard( | ||
onClick = { onAccountClicked.invoke() }, | ||
colors = CardDefaults.cardColors(Color.White) | ||
) { | ||
Column { | ||
Row( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(top = 16.dp) | ||
) { | ||
Icon( | ||
painter = painterResource(id = R.drawable.ic_bank), | ||
contentDescription = null, | ||
modifier = Modifier | ||
.align(Alignment.CenterVertically) | ||
.padding(start = 16.dp, end = 16.dp) | ||
.size(39.dp) | ||
) | ||
|
||
Column { | ||
Text( | ||
text = bankAccountDetails.accountholderName.toString(), | ||
color = mifosText, | ||
) | ||
Text( | ||
text = bankAccountDetails.bankName.toString(), | ||
modifier = Modifier.padding(top = 4.dp), | ||
style = styleMedium16sp.copy(mifosText) | ||
) | ||
} | ||
Column( | ||
horizontalAlignment = Alignment.End, | ||
modifier = Modifier.fillMaxWidth() | ||
) { | ||
Text( | ||
text = bankAccountDetails.branch.toString(), | ||
modifier = Modifier.padding(16.dp), | ||
fontSize = 12.sp, | ||
color = mifosText | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun AccountsItemPreview() { | ||
AccountsItem( | ||
bankAccountDetails = BankAccountDetails("A", "B", "C"), | ||
onAccountClicked = {} | ||
) | ||
} |
Oops, something went wrong.