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

clear //TODO: refactor, state on value change listener is not required, compose will do the magic #50

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
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
Expand Up @@ -7,10 +7,7 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
Expand Down Expand Up @@ -46,7 +43,6 @@ import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.concurrent.TimeUnit
import javax.inject.Inject

//TODO: refactor, state on value change listener is not required, compose will do the magic
internal class CreditCardActivity : BaseActivity() {

@Inject
Expand Down Expand Up @@ -262,26 +258,6 @@ internal class CreditCardActivity : BaseActivity() {
cardIssuerBank = cardIssuerBank.value,
remainingTimeState = remainingTimeState,
onExpand = { isExpanding = it },
onCardNumberValueChange = {

state.cardNumber = it
val cardNumberWithoutSpace = SnapCreditCardUtil.getCardNumberFromTextField(it)
viewModel?.getPromosData(binNumber = cardNumberWithoutSpace)
if (cardNumberWithoutSpace.length >= SnapCreditCardUtil.SUPPORTED_MAX_BIN_NUMBER) {
val eightDigitNumber = cardNumberWithoutSpace.substring(
0,
SnapCreditCardUtil.SUPPORTED_MAX_BIN_NUMBER
)
if (eightDigitNumber != previousEightDigitNumber) {
previousEightDigitNumber = eightDigitNumber
viewModel?.getBinData(binNumber = eightDigitNumber)
onPromoReset.invoke()
}
} else {
viewModel?.resetCardNumberAttribute()
previousEightDigitNumber = cardNumberWithoutSpace
}
},
onClick = {
if (selectedFormData == null) {
viewModel?.chargeUsingCreditCard(
Expand Down Expand Up @@ -313,6 +289,24 @@ internal class CreditCardActivity : BaseActivity() {
promoState = promoState,
onSavedCardRadioSelected = { selectedFormData = it }
)
state.cardNumber.let {
var cardNumberWithoutSpace = SnapCreditCardUtil.getCardNumberFromTextField(it)
viewModel?.getPromosData(binNumber = cardNumberWithoutSpace)
if (cardNumberWithoutSpace.length >= SnapCreditCardUtil.SUPPORTED_MAX_BIN_NUMBER) {
var eightDigitNumber = cardNumberWithoutSpace.substring(
0,
SnapCreditCardUtil.SUPPORTED_MAX_BIN_NUMBER
)
if (eightDigitNumber != previousEightDigitNumber) {
previousEightDigitNumber = eightDigitNumber
viewModel?.getBinData(binNumber = eightDigitNumber)
onPromoReset.invoke()
}
} else {
viewModel?.resetCardNumberAttribute()
previousEightDigitNumber = cardNumberWithoutSpace
}
}
}
val errorState by errorTypeState
errorState?.let {
Expand Down Expand Up @@ -393,7 +387,6 @@ internal class CreditCardActivity : BaseActivity() {
cardIssuerBank: String?,
remainingTimeState: State<String>,
onExpand: (Boolean) -> Unit,
onCardNumberValueChange: (TextFieldValue) -> Unit,
onSavedCardRadioSelected: (item: FormData?) -> Unit,
onInstallmentTermSelected: (String) -> Unit,
onClick: () -> Unit
Expand Down Expand Up @@ -449,7 +442,6 @@ internal class CreditCardActivity : BaseActivity() {
state = state,
savedTokenListState = it,
bankCodeId = bankCodeState,
onCardNumberValueChange = onCardNumberValueChange,
onSavedCardRadioSelected = onSavedCardRadioSelected
)
}
Expand All @@ -458,8 +450,7 @@ internal class CreditCardActivity : BaseActivity() {
NormalCardFormLayout(
state = state,
creditCard = creditCard,
bankCodeState = bankCodeState,
onCardNumberValueChange = onCardNumberValueChange
bankCodeState = bankCodeState
)
}

Expand Down Expand Up @@ -529,23 +520,11 @@ internal class CreditCardActivity : BaseActivity() {
state: CardItemState,
bankCodeState: Int?,
creditCard: CreditCard?,
onCardNumberValueChange: (TextFieldValue) -> Unit
) {
NormalCardItem(
state = state,
bankIcon = bankCodeState,
creditCard = creditCard,
onCardNumberValueChange = {
onCardNumberValueChange(it)
},
onExpiryDateValueChange = { state.expiry = it },
onCvvValueChange = { state.cvv = it },
onCardTextFieldFocusedChange = { state.isCardTexFieldFocused = it },
onExpiryTextFieldFocusedChange = {
state.isExpiryTextFieldFocused = it
},
onCvvTextFieldFocusedChange = { state.isCvvTextFieldFocused = it },
onSavedCardCheckedChange = { state.isSavedCardChecked = it }
creditCard = creditCard
)
}

Expand Down Expand Up @@ -610,7 +589,6 @@ internal class CreditCardActivity : BaseActivity() {
state: CardItemState,
savedTokenListState: SnapshotStateList<FormData>,
bankCodeId: Int?,
onCardNumberValueChange: (TextFieldValue) -> Unit,
onSavedCardRadioSelected: (item: FormData?) -> Unit
) {
SnapSavedCardRadioGroup(
Expand All @@ -627,14 +605,7 @@ internal class CreditCardActivity : BaseActivity() {
)
savedTokenListState.remove(it)
},
onCardNumberOtherCardValueChange = onCardNumberValueChange,
onExpiryOtherCardValueChange = { state.expiry = it },
onSavedCardRadioSelected = onSavedCardRadioSelected,
onIsCvvSavedCardInvalidValueChange = { state.isCvvInvalid = it },
onCvvValueChange = {
state.cvv = it
},
onSavedCardCheckedChange = { state.isSavedCardChecked = it }
onSavedCardRadioSelected = onSavedCardRadioSelected
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ class SavedCardActivity: BaseActivity() {
DaggerUiKitComponent.builder().applicationContext(this.applicationContext).build().inject(this)
initTransactionResultScreenObserver()
setContent {
CreditCardPage(
/* CreditCardPage(
totalAmount = totalAmount,
orderId = transactionDetails?.orderId.toString(),
customerDetail = customerDetail
)
)*/
}
}

Expand Down Expand Up @@ -146,7 +146,7 @@ class SavedCardActivity: BaseActivity() {
return "**** **** **** $lastFourDigit"
}

@Composable
/* @Composable
private fun CreditCardPage(
totalAmount: String,
orderId: String,
Expand Down Expand Up @@ -341,7 +341,7 @@ class SavedCardActivity: BaseActivity() {
)
}
}
}
}*/
private fun checkIsPayButtonEnabled(
selectedFormData: FormData?,
isSelectedSavedCardCvvInvalid: Boolean,
Expand Down Expand Up @@ -376,14 +376,14 @@ class SavedCardActivity: BaseActivity() {
@Preview
@Composable
private fun Preview() {
CreditCardPage(
/* CreditCardPage(
totalAmount = "10000",
orderId = "Order ID #34345445554",
customerDetail = CustomerInfo(
"Ari Bhakti",
"087788778212",
listOf("Jl. ABC", "Rumah DEF")
)
)
)*/
}
}
Loading