TP-52122 | Addressed PR comment to include vararg & function renaming (#9068)

This commit is contained in:
Ujjwal Kumar
2023-12-22 14:35:55 +05:30
committed by GitHub
parent b68071865d
commit 7f0c8ab7f6
8 changed files with 46 additions and 47 deletions

View File

@@ -14,13 +14,13 @@ import javax.inject.Inject
interface ResourceProvider {
fun getStringFromResId(@StringRes resId: Int, vararg formatArg: Any): String
fun getString(@StringRes resId: Int, vararg formatArg: Any): String
}
class ResourceProviderImpl @Inject constructor(@ApplicationContext val context: Context) :
ResourceProvider {
override fun getStringFromResId(@StringRes resId: Int, vararg formatArg: Any): String {
return context.getString(resId)
override fun getString(@StringRes resId: Int, vararg formatArg: Any): String {
return context.getString(resId, formatArg)
}
}

View File

@@ -45,7 +45,6 @@ import com.navi.pay.common.theme.color.NaviPayColor
import com.navi.pay.common.usecase.LinkedAccountsUseCase
import com.navi.pay.common.usecase.LiteAccountSyncUseCase
import com.navi.pay.common.usecase.NaviPayConfigUseCase
import com.navi.pay.common.usecase.SyncFrequentTransactionsUseCase
import com.navi.pay.common.utils.DeviceInfoProvider
import com.navi.pay.common.utils.NaviPayCommonUtils
import com.navi.pay.common.viewmodel.NaviPayBaseVM
@@ -239,7 +238,7 @@ class SendMoneyViewModel @Inject constructor(
private val _mainCtaState =
MutableStateFlow<SendMoneyMainCtaState>(
SendMoneyMainCtaState.Disabled(
ctaText = resourceProvider.getStringFromResId(resId = R.string.np_pay)
ctaText = resourceProvider.getString(resId = R.string.np_pay)
)
)
val mainCtaState = _mainCtaState.asStateFlow()
@@ -502,7 +501,7 @@ class SendMoneyViewModel @Inject constructor(
val isLiteSyncNeeded =
(upiLiteBoundResponse.status == UpiLiteBoundStatus.BOUND.name && upiLiteBoundResponse.syncRequired.toBoolean()) || upiLiteBoundResponse.status == UpiLiteBoundStatus.NO_BIND.name
val balanceDescription = resourceProvider.getStringFromResId(resId = R.string.balance)
val balanceDescription = resourceProvider.getString(resId = R.string.balance)
.appendStrings(
SPACE,
RUPEE_SYMBOL,
@@ -512,7 +511,7 @@ class SendMoneyViewModel @Inject constructor(
return if (isLiteSyncNeeded || liteAccountBalance.isEmpty()) {
LinkedAccountEntityState(
isAccountEligible = false,
description = resourceProvider.getStringFromResId(resId = R.string.upi_lite_sync_needed)
description = resourceProvider.getString(resId = R.string.upi_lite_sync_needed)
)
} else if (liteAccountBalance.getFormattedAmountWithDecimal().toIntOrNull() == 0) {
LinkedAccountEntityState(
@@ -924,35 +923,35 @@ class SendMoneyViewModel @Inject constructor(
.toDouble()) {
SendMoneyMainCtaState.Pay(
ctaText = if (paymentAmount.isBlank() || paymentAmount == ZERO_STRING) {
resourceProvider.getStringFromResId(resId = R.string.np_pay)
resourceProvider.getString(resId = R.string.np_pay)
} else {
String.format(
resourceProvider.getStringFromResId(resId = R.string.pay_rupees_x),
resourceProvider.getString(resId = R.string.pay_rupees_x),
_paymentAmount.value.getDisplayableAmount()
)
}
)
} else {
SendMoneyMainCtaState.Disabled(
ctaText = resourceProvider.getStringFromResId(resId = R.string.np_pay)
ctaText = resourceProvider.getString(resId = R.string.np_pay)
)
}
} else if (selectedBankAccount.value?.isMPinSet == true) {
SendMoneyMainCtaState.Pay(
ctaText = if (paymentAmount.isBlank() || paymentAmount == ZERO_STRING) {
resourceProvider.getStringFromResId(resId = R.string.np_pay)
resourceProvider.getString(resId = R.string.np_pay)
} else {
String.format(
resourceProvider.getStringFromResId(resId = R.string.pay_rupees_x),
resourceProvider.getString(resId = R.string.pay_rupees_x),
_paymentAmount.value.getDisplayableAmount()
)
}
)
} else {
SendMoneyMainCtaState.SetPin(ctaText = resourceProvider.getStringFromResId(resId = R.string.set_upi_pin))
SendMoneyMainCtaState.SetPin(ctaText = resourceProvider.getString(resId = R.string.set_upi_pin))
}
} else {
SendMoneyMainCtaState.Disabled(ctaText = resourceProvider.getStringFromResId(resId = R.string.np_pay))
SendMoneyMainCtaState.Disabled(ctaText = resourceProvider.getString(resId = R.string.np_pay))
}
_mainCtaState.update { mainCtaState }
@@ -1012,7 +1011,7 @@ class SendMoneyViewModel @Inject constructor(
description = qrError.description,
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.retry),
text = resourceProvider.getString(resId = R.string.retry),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Retry("")
)
@@ -1303,7 +1302,7 @@ class SendMoneyViewModel @Inject constructor(
}
val eligibilityDescription =
resourceProvider.getStringFromResId(resId = R.string.balance).appendStrings(
resourceProvider.getString(resId = R.string.balance).appendStrings(
SPACE,
RUPEE_SYMBOL,
liteAccountBalanceValue.toString().getFormattedAmountWithDecimal()
@@ -1314,7 +1313,7 @@ class SendMoneyViewModel @Inject constructor(
description = eligibilityDescription,
inEligibilityReasonResId = inEligibilityReasonResId,
inEligibilityReason = if (isMaxPayableAmountExceeded) {
resourceProvider.getStringFromResId(resId = R.string.max_payable_amount)
resourceProvider.getString(resId = R.string.max_payable_amount)
.format(maxPayableAmountValue.toString().getFormattedAmountWithDecimal())
} else {
""

View File

@@ -203,24 +203,24 @@ class UPILiteViewModel @Inject constructor(
updateFooterUiForOnBoardedUser
) { selectedBankAccount, enteredAmount, updateFooterUiForOnBoardedUser ->
if (updateFooterUiForOnBoardedUser) {
UPILiteMainCtaState.Done(ctaText = resourceProvider.getStringFromResId(resId = R.string.done))
UPILiteMainCtaState.Done(ctaText = resourceProvider.getString(resId = R.string.done))
} else if (selectedBankAccount?.isMPinSet == false) {
UPILiteMainCtaState.SetPin(ctaText = resourceProvider.getStringFromResId(resId = R.string.set_upi_pin))
UPILiteMainCtaState.SetPin(ctaText = resourceProvider.getString(resId = R.string.set_upi_pin))
} else UPILiteMainCtaState.AddBalance(
ctaText = if (enteredAmount.isAmountValid())
resourceProvider.getStringFromResId(resId = R.string.add).appendStrings(
resourceProvider.getString(resId = R.string.add).appendStrings(
SPACE,
RUPEE_SYMBOL,
enteredAmount.getFormattedAmountWithDecimal()
)
else resourceProvider.getStringFromResId(resId = R.string.add_balance)
else resourceProvider.getString(resId = R.string.add_balance)
)
}.flowOn(coroutineDispatcherProvider.default)
.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(),
initialValue = UPILiteMainCtaState.Default(
ctaText = resourceProvider.getStringFromResId(resId = R.string.add)
ctaText = resourceProvider.getString(resId = R.string.add)
.appendStrings(
SPACE,
RUPEE_SYMBOL,
@@ -1786,11 +1786,11 @@ class UPILiteViewModel @Inject constructor(
notifyError(
errorConfig = getGenericErrorConfig().copy(
iconResId = R.drawable.ic_np_white_exclamation_yellow_bg,
title = resourceProvider.getStringFromResId(resId = R.string.np_lite_topup_pending_title),
description = resourceProvider.getStringFromResId(resId = R.string.np_please_try_again_sometime),
title = resourceProvider.getString(resId = R.string.np_lite_topup_pending_title),
description = resourceProvider.getString(resId = R.string.np_please_try_again_sometime),
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.np_okay_got_it),
text = resourceProvider.getString(resId = R.string.np_okay_got_it),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Dismiss
)
@@ -1816,11 +1816,11 @@ class UPILiteViewModel @Inject constructor(
notifyError(
errorConfig = getGenericErrorConfig().copy(
iconResId = R.drawable.ic_np_white_exclamation_yellow_bg,
title = resourceProvider.getStringFromResId(resId = R.string.np_lite_topup_pending_title),
description = resourceProvider.getStringFromResId(resId = R.string.np_please_try_again_sometime),
title = resourceProvider.getString(resId = R.string.np_lite_topup_pending_title),
description = resourceProvider.getString(resId = R.string.np_please_try_again_sometime),
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.np_okay_got_it),
text = resourceProvider.getString(resId = R.string.np_okay_got_it),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Dismiss
)
@@ -1860,11 +1860,11 @@ class UPILiteViewModel @Inject constructor(
if (response.errors?.firstOrNull()?.code == UNKNOWN_ERROR_CODE) {
notifyError(
errorConfig = getGenericErrorConfig().copy(
title = resourceProvider.getStringFromResId(resId = R.string.np_lite_topup_failed_title),
description = resourceProvider.getStringFromResId(resId = R.string.np_please_try_again_sometime),
title = resourceProvider.getString(resId = R.string.np_lite_topup_failed_title),
description = resourceProvider.getString(resId = R.string.np_please_try_again_sometime),
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.np_okay_got_it),
text = resourceProvider.getString(resId = R.string.np_okay_got_it),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Dismiss
)
@@ -1902,8 +1902,8 @@ class UPILiteViewModel @Inject constructor(
notifyError(
errorConfig = getGenericErrorConfig()
.copy(
title = resourceProvider.getStringFromResId(resId = R.string.np_lite_registration_failed_title),
description = resourceProvider.getStringFromResId(resId = R.string.np_facing_technical_issues),
title = resourceProvider.getString(resId = R.string.np_lite_registration_failed_title),
description = resourceProvider.getString(resId = R.string.np_facing_technical_issues),
)
)
}
@@ -1963,7 +1963,7 @@ class UPILiteViewModel @Inject constructor(
_openBottomSheet.emit(false)
notifyError(
errorConfig = getGenericErrorConfig().copy(
description = resourceProvider.getStringFromResId(
description = resourceProvider.getString(
resId = R.string.np_no_active_lite_account
)
)

View File

@@ -308,7 +308,7 @@ class BankDetailInputViewModel @Inject constructor(
if (!validateVpaAPIResponse.isSuccessWithData()) {
if (validateVpaAPIResponse.errors?.getOrNull(0)?.code == INVALID_VPA) {
val error = getError(validateVpaAPIResponse).copy(
title = resourceProvider.getStringFromResId(resId = R.string.invalid_bank_details)
title = resourceProvider.getString(resId = R.string.invalid_bank_details)
)
updateInvalidInfoState(

View File

@@ -107,7 +107,7 @@ class QrScannerViewModel @Inject constructor(
cancelable = false,
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.retry),
text = resourceProvider.getString(resId = R.string.retry),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Retry(action = "genericError")
)
@@ -244,11 +244,11 @@ class QrScannerViewModel @Inject constructor(
description = qrError.description,
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.cancel),
text = resourceProvider.getString(resId = R.string.cancel),
type = NaviPayButtonTheme.Secondary,
action = NaviPayButtonAction.Dismiss
), NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.retry),
text = resourceProvider.getString(resId = R.string.retry),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Retry("")
)

View File

@@ -308,7 +308,7 @@ class TransactionHistoryViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.Default) {
naviPayAnalytics.onCategoriesTabApplyClicked(activeCategories = categoryTagsHolder.value.filter { it.isActive }
.map {
if (it.displayTextId != -1) resourceProvider.getStringFromResId(resId = it.displayTextId)
if (it.displayTextId != -1) resourceProvider.getString(resId = it.displayTextId)
else it.displayText
})
}
@@ -346,12 +346,12 @@ class TransactionHistoryViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.Default) {
naviPayAnalytics.onFiltersTabApplyClicked(paymentModes = paymentModeTagsHolder.value.filter { it.isActive }
.map {
if (it.displayTextId != -1) resourceProvider.getStringFromResId(resId = it.displayTextId)
if (it.displayTextId != -1) resourceProvider.getString(resId = it.displayTextId)
else it.displayText
},
transactionStatus = transactionStatusTagsHolder.value.filter { it.isActive }
.map {
if (it.displayTextId != -1) resourceProvider.getStringFromResId(resId = it.displayTextId)
if (it.displayTextId != -1) resourceProvider.getString(resId = it.displayTextId)
else it.displayText
})
}
@@ -369,7 +369,7 @@ class TransactionHistoryViewModel @Inject constructor(
viewModelScope.launch(Dispatchers.Default) {
naviPayAnalytics.onMonthsTabApplyClicked(activeMonths = monthTagsHolder.value.filter { it.isActive }
.map {
if (it.displayTextId != -1) resourceProvider.getStringFromResId(resId = it.displayTextId)
if (it.displayTextId != -1) resourceProvider.getString(resId = it.displayTextId)
else it.displayText
})
}

View File

@@ -211,8 +211,8 @@ class LinkedAccountDetailViewModel @Inject constructor(
updateBottomSheetUIState(showBottomSheet = false)
notifyError(
errorConfig = getGenericErrorConfig().copy(
title = resourceProvider.getStringFromResId(resId = R.string.unable_to_remove_account),
description = resourceProvider.getStringFromResId(resId = R.string.unable_to_remove_account_description)
title = resourceProvider.getString(resId = R.string.unable_to_remove_account),
description = resourceProvider.getString(resId = R.string.unable_to_remove_account_description)
)
)
return@launch

View File

@@ -408,12 +408,12 @@ class NaviPayOnboardingViewModel @Inject constructor(
description = naviPayOnboardingConfig.config.smsVerificationLocallyExpiredDescription,
buttonConfigs = listOf(
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.retry),
text = resourceProvider.getString(resId = R.string.retry),
type = NaviPayButtonTheme.Primary,
action = NaviPayButtonAction.Retry(action = "RETRY")
),
NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.cancel),
text = resourceProvider.getString(resId = R.string.cancel),
type = NaviPayButtonTheme.Secondary,
action = NaviPayButtonAction.Dismiss
)
@@ -694,7 +694,7 @@ class NaviPayOnboardingViewModel @Inject constructor(
val error = getError(response = response, cancelable = false)
if (error.buttonConfigs.size == 1 && error.buttonConfigs[0].action is NaviPayButtonAction.Retry) {
val cancelButtonConfig = NaviPayErrorButtonConfig(
text = resourceProvider.getStringFromResId(resId = R.string.cancel),
text = resourceProvider.getString(resId = R.string.cancel),
type = NaviPayButtonTheme.Secondary,
action = NaviPayButtonAction.Dismiss
)