-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Merchants to feature module (#1669)
Co-authored-by: Rajan Maurya <therajanmaurya@users.noreply.github.com>
- Loading branch information
1 parent
5133f20
commit b07241d
Showing
12 changed files
with
800 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,19 @@ | ||
plugins { | ||
alias(libs.plugins.mifospay.android.feature) | ||
alias(libs.plugins.mifospay.android.library.compose) | ||
} | ||
|
||
android { | ||
namespace = "org.mifospay.feature.merchants" | ||
} | ||
|
||
dependencies { | ||
implementation(projects.core.data) | ||
implementation(libs.compose.material) | ||
|
||
//Todo: Remove these after migration of MerchantTransferActivity | ||
implementation("com.jakewharton:butterknife-annotations:10.2.3") | ||
implementation("com.jakewharton:butterknife:10.2.3@aar") | ||
implementation("com.mifos.mobile:mifos-passcode:0.3.0@aar") | ||
implementation(project(":mifospay")) | ||
} |
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
.../merchants/src/androidTest/java/org/mifospay/feature/merchants/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.merchants | ||
|
||
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.merchants.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> |
284 changes: 284 additions & 0 deletions
284
feature/merchants/src/main/kotlin/org/mifospay/feature/merchants/MerchantScreen.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,284 @@ | ||
package org.mifospay.feature.merchants | ||
|
||
import android.content.Intent | ||
import android.widget.Toast | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Close | ||
import androidx.compose.material.icons.filled.Search | ||
import androidx.compose.material.icons.rounded.Info | ||
import androidx.compose.material.pullrefresh.PullRefreshIndicator | ||
import androidx.compose.material.pullrefresh.pullRefresh | ||
import androidx.compose.material.pullrefresh.rememberPullRefreshState | ||
import androidx.compose.material3.ExperimentalMaterial3Api | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.IconButton | ||
import androidx.compose.material3.SearchBar | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalClipboardManager | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.AnnotatedString | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations | ||
import org.mifospay.R | ||
import org.mifospay.common.Constants | ||
import org.mifospay.core.designsystem.component.MfLoadingWheel | ||
import org.mifospay.core.ui.EmptyContentScreen | ||
import org.mifospay.theme.MifosTheme | ||
|
||
@Composable | ||
fun MerchantScreen( | ||
viewModel: MerchantViewModel = hiltViewModel() | ||
) { | ||
val merchantUiState by viewModel.merchantUiState.collectAsStateWithLifecycle() | ||
val merchantsListUiState by viewModel.merchantsListUiState.collectAsStateWithLifecycle() | ||
val isRefreshing by viewModel.isRefreshing.collectAsStateWithLifecycle() | ||
|
||
MerchantScreen( | ||
merchantUiState = merchantUiState, | ||
merchantListUiState = merchantsListUiState, | ||
updateQuery = { viewModel.updateSearchQuery(it) }, | ||
isRefreshing = isRefreshing, | ||
onRefresh = { viewModel.refresh() }, | ||
) | ||
} | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun MerchantScreen( | ||
merchantUiState: MerchantUiState, | ||
merchantListUiState: MerchantUiState, | ||
updateQuery: (String) -> Unit, | ||
isRefreshing: Boolean, | ||
onRefresh: () -> Unit, | ||
) { | ||
val pullRefreshState = rememberPullRefreshState(isRefreshing, onRefresh) | ||
Box(Modifier.pullRefresh(pullRefreshState)) { | ||
Column(modifier = Modifier.fillMaxSize()) { | ||
when (merchantUiState) { | ||
MerchantUiState.Empty -> { | ||
EmptyContentScreen( | ||
modifier = Modifier, | ||
title = stringResource(id = R.string.empty_no_merchants_title), | ||
subTitle = stringResource(id = R.string.empty_no_merchants_subtitle), | ||
iconTint = Color.Black, | ||
iconImageVector = Icons.Rounded.Info | ||
) | ||
} | ||
|
||
is MerchantUiState.Error -> { | ||
EmptyContentScreen( | ||
modifier = Modifier, | ||
title = stringResource(id = R.string.error_oops), | ||
subTitle = stringResource(id = R.string.unexpected_error_subtitle), | ||
iconTint = Color.Black, | ||
iconImageVector = Icons.Rounded.Info | ||
) | ||
} | ||
|
||
MerchantUiState.Loading -> { | ||
MfLoadingWheel( | ||
contentDesc = stringResource(R.string.loading), | ||
backgroundColor = Color.White | ||
) | ||
} | ||
|
||
is MerchantUiState.ShowMerchants -> { | ||
MerchantScreenContent( | ||
merchantList = (merchantListUiState as MerchantUiState.ShowMerchants).merchants, | ||
updateQuery = updateQuery | ||
) | ||
} | ||
} | ||
} | ||
PullRefreshIndicator( | ||
refreshing = isRefreshing, | ||
state = pullRefreshState, | ||
modifier = Modifier.align(Alignment.TopCenter) | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
fun MerchantScreenContent( | ||
merchantList: List<SavingsWithAssociations>, | ||
updateQuery: (String) -> Unit | ||
) { | ||
val query by rememberSaveable { mutableStateOf("") } | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
Column { | ||
SearchBarScreen( | ||
query = query, | ||
onQueryChange = { q -> | ||
updateQuery(q) | ||
}, | ||
onSearch = {}, | ||
onClearQuery = { updateQuery("") } | ||
) | ||
MerchantList(merchantList = merchantList) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun MerchantList( | ||
merchantList: List<SavingsWithAssociations> | ||
) { | ||
val context = LocalContext.current | ||
val clipboardManager = LocalClipboardManager.current | ||
LazyColumn( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(horizontal = 16.dp) | ||
) { | ||
items(merchantList.size) { index -> | ||
MerchantsItem(savingsWithAssociations = merchantList[index], | ||
onMerchantClicked = { | ||
val intent = Intent(context, MerchantTransferActivity::class.java) | ||
intent.putExtra(Constants.MERCHANT_NAME, merchantList[index].clientName) | ||
intent.putExtra(Constants.MERCHANT_VPA, merchantList[index].externalId) | ||
intent.putExtra(Constants.MERCHANT_ACCOUNT_NO, merchantList[index].accountNo) | ||
context.startActivity(intent) | ||
}, | ||
onMerchantLongPressed = { | ||
clipboardManager.setText(AnnotatedString(it ?: "")) | ||
Toast.makeText(context, R.string.vpa_copy_success, Toast.LENGTH_LONG).show() | ||
} | ||
) | ||
} | ||
} | ||
} | ||
|
||
|
||
@OptIn(ExperimentalMaterial3Api::class) | ||
@Composable | ||
fun SearchBarScreen( | ||
query: String, | ||
onQueryChange: (String) -> Unit, | ||
onSearch: (String) -> Unit, | ||
onClearQuery: () -> Unit | ||
) { | ||
SearchBar( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 16.dp, horizontal = 16.dp), | ||
query = query, | ||
onQueryChange = onQueryChange, | ||
onSearch = onSearch, | ||
active = false, | ||
onActiveChange = { }, | ||
placeholder = { | ||
Text(text = stringResource(R.string.search)) | ||
}, | ||
leadingIcon = { | ||
Icon( | ||
imageVector = Icons.Filled.Search, | ||
contentDescription = stringResource(R.string.search) | ||
) | ||
}, | ||
trailingIcon = { | ||
IconButton( | ||
onClick = onClearQuery | ||
) { | ||
Icon( | ||
imageVector = Icons.Filled.Close, | ||
contentDescription = stringResource(R.string.close) | ||
) | ||
} | ||
} | ||
) {} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun MerchantLoadingPreview() { | ||
MifosTheme { | ||
MerchantScreen(merchantUiState = MerchantUiState.Loading, | ||
merchantListUiState = MerchantUiState.ShowMerchants(sampleMerchantList), | ||
updateQuery = {}, | ||
false, {} | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun MerchantListPreview() { | ||
MifosTheme { | ||
MerchantScreen( | ||
merchantUiState = MerchantUiState.ShowMerchants(sampleMerchantList), | ||
merchantListUiState = MerchantUiState.ShowMerchants(sampleMerchantList), | ||
updateQuery = {}, false, {} | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun MerchantErrorPreview() { | ||
MifosTheme { | ||
MerchantScreen( | ||
merchantUiState = MerchantUiState.Error("Error Screen"), | ||
merchantListUiState = MerchantUiState.ShowMerchants(sampleMerchantList), | ||
updateQuery = {}, true, {} | ||
) | ||
} | ||
} | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
private fun MerchantEmptyPreview() { | ||
MifosTheme { | ||
MerchantScreen( | ||
merchantUiState = MerchantUiState.Empty, | ||
merchantListUiState = MerchantUiState.ShowMerchants(sampleMerchantList), | ||
updateQuery = {}, false, {} | ||
) | ||
} | ||
} | ||
|
||
|
||
val sampleMerchantList = List(10) { | ||
SavingsWithAssociations( | ||
id = 1L, | ||
accountNo = "123456789", | ||
depositType = null, | ||
externalId = "EXT987654", | ||
clientId = 101, | ||
clientName = "Alice Bob", | ||
savingsProductId = 2001, | ||
savingsProductName = "Premium Savings Account", | ||
fieldOfficerId = 501, | ||
status = null, | ||
timeline = null, | ||
currency = null, | ||
nominalAnnualInterestRate = 3.5, | ||
minRequiredOpeningBalance = 500.0, | ||
lockinPeriodFrequency = 12.0, | ||
withdrawalFeeForTransfers = true, | ||
allowOverdraft = false, | ||
enforceMinRequiredBalance = false, | ||
withHoldTax = true, | ||
lastActiveTransactionDate = listOf(2024, 3, 24), | ||
dormancyTrackingActive = true, | ||
summary = null, | ||
transactions = listOf() | ||
) | ||
} |
Oops, something went wrong.