Skip to content

Instantly share code, notes, and snippets.

@CyxouD
Created July 19, 2018 14:59
Show Gist options
  • Save CyxouD/00e87fb7372a978697206ddb326a3f2d to your computer and use it in GitHub Desktop.
Save CyxouD/00e87fb7372a978697206ddb326a3f2d to your computer and use it in GitHub Desktop.
Fragment which is MVP View which can show credit card logo, show that there is no credit card logo, show credit card number was validated successfully etc (everything defined in AddEditCardContract.kt)
//MVP View
class AddEditCardFragment : BaseFragment<AddEditCardContract.Presenter>(), AddEditCardContract.View {
// ...Android lifecycle methods
override fun setPresenter(presenter: AddEditCardContract.Presenter) {
mPresenter = presenter
}
override fun showCreditCardLogo(creditCardEnum: CreditCardEnum) {
val logoDrawable = ContextCompat.getDrawable(context, creditCardEnum.cardDrawable!!)
val gradientDrawable = ContextCompat.getDrawable(context, creditCardEnum.gradientDrawable!!)
flipBetweenActiveFrontAndInactiveAppearance(logoDrawable,
gradientDrawable,
toActive = true)
}
override fun showNoCreditCardLogo() {
flipBetweenActiveFrontAndInactiveAppearance(null,
null,
toActive = false)
}
override fun showCreditCardNumberValidatedSuccessfully() {
stateMachine.nextState()
}
override fun showCreditCardNumberFailedToValidate() {
context.toast(R.string.credit_card_number_is_not_valid).show()
}
override fun showCreditCardHolderValidatedSuccessfully() {
stateMachine.nextState()
}
override fun showCreditCardHolderFailedToValidate() {
context.toast(R.string.credit_card_holder_is_not_valid).show()
}
override fun showCreditCardExpiryDateValidatedSuccessfully() {
stateMachine.nextState()
}
override fun showCreditCardExpiryDateFailedToValidate() {
context.toast(R.string.credit_card_expiry_date_is_not_valid).show()
}
override fun showCreditCardCvvValidatedSuccessfully() {
stateMachine.nextState()
}
override fun showCreditCardCvvFailedToValidate() {
context.toast(R.string.credit_card_cvv_is_not_valid).show()
}
override fun showCreditCardSavedSuccessfully() {
stateMachine.nextState()
(activity as AppCompatActivity).supportActionBar!!.setDisplayHomeAsUpEnabled(false)
}
override fun showCreditCardFailedToSave() {
save_card_container.showNext()
context.toast(R.string.credit_card_failed_to_save).show()
}
override fun showCreditCardPriorityAndTypeValidatedSuccessfully() {
save()
}
override fun showCreditCardPriorityIsEmpty() {
context.toast(R.string.credit_card_priority_is_empty).show()
}
override fun showCreditCardTypeIsEmpty() {
context.toast(R.string.credit_card_type_is_empty).show()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment