diff --git a/CHANGELOG.md b/CHANGELOG.md index b5cbc27..b5e37d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +### 2.01.01 +- Cleared form data on back pressed +- Cleared form data on successful payment + ### 2.01.00 - Dropped android sdk support below 21 - Migrated to maven from jcenter for deployment diff --git a/app/build.gradle b/app/build.gradle index fee87fb..6018a46 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -13,7 +13,7 @@ android { release { minifyEnabled true shrinkResources true - debuggable false + debuggable true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } @@ -35,6 +35,6 @@ dependencies { /*ButterKnife*/ implementation "com.jakewharton:butterknife:${butterKnifeVersion}" annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}" - implementation "com.khalti:khalti-android:2.01.00" + implementation "com.khalti:khalti-android:2.01.01" // implementation project(':khalti-android') } diff --git a/khalti-android/src/main/java/com/khalti/checkout/CheckOutActivity.kt b/khalti-android/src/main/java/com/khalti/checkout/CheckOutActivity.kt index 39c7f81..240c506 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/CheckOutActivity.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/CheckOutActivity.kt @@ -34,6 +34,7 @@ class CheckOutActivity : AppCompatActivity(), CheckOutContract.View, BaseComm { private val searchViewMap = HashMap() private val searchViewMapInitSignal = Signal() + private val backPressSignal:Signal = Signal() companion object { var isActive: Boolean = false @@ -174,9 +175,7 @@ class CheckOutActivity : AppCompatActivity(), CheckOutContract.View, BaseComm { window.decorView.systemUiVisibility = flags window.statusBarColor = ResourceUtil.getColor(this, R.color.bg) } else { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < 23) { - window.statusBarColor = ResourceUtil.getColor(this, R.color.khaltiPrimaryDark) - } + window.statusBarColor = ResourceUtil.getColor(this, R.color.khaltiPrimaryDark) } } @@ -237,8 +236,13 @@ class CheckOutActivity : AppCompatActivity(), CheckOutContract.View, BaseComm { } } + override fun getBackPressedSignal(): Signal { + return backPressSignal; + } + override fun onBackPressed() { presenter.onBackPressed() + backPressSignal.emit(true); super.onBackPressed() } } \ No newline at end of file diff --git a/khalti-android/src/main/java/com/khalti/checkout/CheckOutPresenter.kt b/khalti-android/src/main/java/com/khalti/checkout/CheckOutPresenter.kt index 47ad9b5..7f2ffb3 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/CheckOutPresenter.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/CheckOutPresenter.kt @@ -4,6 +4,7 @@ import com.khalti.checkout.helper.CheckoutEventListener import com.khalti.checkout.helper.Config import com.khalti.checkout.helper.PaymentPreference import com.khalti.signal.CompositeSignal +import com.khalti.signal.Signal import com.khalti.utils.EmptyUtil import com.khalti.utils.GuavaUtil import com.khalti.utils.HandlerUtil @@ -84,7 +85,6 @@ class CheckOutPresenter(view: CheckOutContract.View) : CheckOutContract.Presente override fun onTabSelected(preferences: List, it: Map) { currentPage = it.getValue("position") as Int -// view.toggleTab(currentPage, it.getValue("selected") as Boolean, it.getValue("id") as String) view.toggleSearch(preferences[currentPage].value, searchList.contains(preferences[currentPage].value)) } diff --git a/khalti-android/src/main/java/com/khalti/checkout/form/Form.kt b/khalti-android/src/main/java/com/khalti/checkout/form/Form.kt index 369c381..069571f 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/form/Form.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/form/Form.kt @@ -80,7 +80,11 @@ class Form : Fragment(), FormContract.View { } if (show) { - val pair = UserInterfaceUtil.runProgressDialog(fragmentActivity, message, ResourceUtil.getString(fragmentActivity, R.string.please_wait)) + val pair = UserInterfaceUtil.runProgressDialog( + fragmentActivity, + message, + ResourceUtil.getString(fragmentActivity, R.string.please_wait) + ) progressDialog = pair.first signal = pair.second } else { @@ -90,7 +94,10 @@ class Form : Fragment(), FormContract.View { } override fun toggleConfirmationLayout(show: Boolean) { - val buttonText = if (show) ResourceUtil.getString(fragmentActivity, R.string.confirm_payment) else "Pay Rs ${NumberUtil.convertToRupees(Store.getConfig().amount)}" + val buttonText = if (show) ResourceUtil.getString( + fragmentActivity, + R.string.confirm_payment + ) else "Pay Rs ${NumberUtil.convertToRupees(Store.getConfig().amount)}" binding.btnPay.text = buttonText binding.etCode.setText("") binding.elConfirmation.toggleExpansion() @@ -209,12 +216,26 @@ class Form : Fragment(), FormContract.View { } override fun showNetworkError() { - UserInterfaceUtil.showSnackBar(fragmentActivity, baseComm.getCoordinator(), ResourceUtil.getString(fragmentActivity, R.string.network_error_body), null, Snackbar.LENGTH_LONG) + UserInterfaceUtil.showSnackBar( + fragmentActivity, + baseComm.getCoordinator(), + ResourceUtil.getString(fragmentActivity, R.string.network_error_body), + null, + Snackbar.LENGTH_LONG + ) } override fun showMessageDialog(title: String, message: String, actionListener: Boolean): Signal { val cancelText = if (actionListener) ResourceUtil.getString(fragmentActivity, R.string.cancel) else null - return UserInterfaceUtil.showInfoDialog(fragmentActivity, title, message, autoDismiss = true, cancelable = true, positiveText = ResourceUtil.getString(fragmentActivity, R.string.ok), negativeText = cancelText) + return UserInterfaceUtil.showInfoDialog( + fragmentActivity, + title, + message, + autoDismiss = true, + cancelable = true, + positiveText = ResourceUtil.getString(fragmentActivity, R.string.ok), + negativeText = cancelText + ) } override fun showSlogan() { @@ -316,6 +337,16 @@ class Form : Fragment(), FormContract.View { } } + override fun clearForm() { + binding.etMobile.setText("") + binding.etCode.setText("") + binding.etPIN.setText("") + } + + override fun getBackPressedSignal(): Signal { + return baseComm.getBackPressedSignal() + } + override fun setPresenter(presenter: FormContract.Presenter) { this.presenter = presenter } diff --git a/khalti-android/src/main/java/com/khalti/checkout/form/FormContract.kt b/khalti-android/src/main/java/com/khalti/checkout/form/FormContract.kt index 770540f..dda15e9 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/form/FormContract.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/form/FormContract.kt @@ -2,10 +2,9 @@ package com.khalti.checkout.form import com.khalti.base.LifeCycle - +import com.khalti.checkout.api.Result import com.khalti.checkout.form.helper.WalletConfirmPojo import com.khalti.checkout.form.helper.WalletInitPojo -import com.khalti.checkout.api.Result import com.khalti.checkout.helper.Config import com.khalti.signal.Signal @@ -72,6 +71,10 @@ interface FormContract { fun doesPackageExist(): Boolean + fun clearForm() + + fun getBackPressedSignal(): Signal + fun setPresenter(presenter: Presenter) } diff --git a/khalti-android/src/main/java/com/khalti/checkout/form/FormPresenter.kt b/khalti-android/src/main/java/com/khalti/checkout/form/FormPresenter.kt index 9422812..23174e4 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/form/FormPresenter.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/form/FormPresenter.kt @@ -2,8 +2,8 @@ package com.khalti.checkout.form import com.khalti.checkout.api.ErrorAction import com.khalti.checkout.api.Result -import com.khalti.checkout.helper.Config import com.khalti.checkout.form.helper.WalletInitPojo +import com.khalti.checkout.helper.Config import com.khalti.checkout.helper.PaymentPreference import com.khalti.signal.CompositeSignal import com.khalti.utils.* @@ -108,44 +108,48 @@ class FormPresenter(view: FormContract.View) : FormContract.Presenter { if (EmptyUtil.isNotNull(clickMap["pin"])) { compositeSignal.add(clickMap.getValue("pin") - .connect { - if (view.doesPackageExist()) { - view.openKhaltiSettings() - } else { - view.openLinkInBrowser(Constant.url + transactionPINUrl) - } - }) + .connect { + if (view.doesPackageExist()) { + view.openKhaltiSettings() + } else { + view.openLinkInBrowser(Constant.url + transactionPINUrl) + } + }) } val watcherMap = view.setEditTextListener() if (EmptyUtil.isNotNull(watcherMap["mobile"])) { compositeSignal.add(watcherMap.getValue("mobile") - .connect { - view.setEditTextError("mobile", null) - if (view.payButtonText.lowercase(Locale.getDefault()).contains("confirm")) { - view.toggleConfirmationLayout(false) - } - }) + .connect { + view.setEditTextError("mobile", null) + if (view.payButtonText.lowercase(Locale.getDefault()).contains("confirm")) { + view.toggleConfirmationLayout(false) + } + }) } if (EmptyUtil.isNotNull(watcherMap["pin"])) { compositeSignal.add(watcherMap.getValue("pin") - .connect { - view.setEditTextError("pin", null) - if (view.payButtonText.lowercase(Locale.getDefault()).contains("confirm")) { - view.toggleConfirmationLayout(false) - } - }) + .connect { + view.setEditTextError("pin", null) + if (view.payButtonText.lowercase(Locale.getDefault()).contains("confirm")) { + view.toggleConfirmationLayout(false) + } + }) } if (EmptyUtil.isNotNull(watcherMap["code"])) { compositeSignal.add(watcherMap.getValue("code") - .connect { - view.setEditTextError("code", null) - view.setConfirmationLayoutHeight() - }) + .connect { + view.setEditTextError("code", null) + view.setConfirmationLayoutHeight() + }) } } + + compositeSignal.add(view.getBackPressedSignal().connect { + view.clearForm() + }) } override fun onDestroy() { @@ -218,15 +222,15 @@ class FormPresenter(view: FormContract.View) : FormContract.Presenter { if (errorMap.containsKey("error_key") && errorMap.getValue("error_key") == "third_party_transaction_locked") { compositeSignal.add(view.showMessageDialog("Error", view.getMessage("pin_error"), true) - .connect { - if (it) { - if (view.doesPackageExist()) { - view.openKhaltiSettings() - } else { - view.openLinkInBrowser(Constant.url + transactionPINUrl) - } + .connect { + if (it) { + if (view.doesPackageExist()) { + view.openKhaltiSettings() + } else { + view.openLinkInBrowser(Constant.url + transactionPINUrl) } - }) + } + }) } else if (errorMap.containsKey("detail")) { view.showMessageDialog("Error", errorMap.getValue("detail")) } else if (errorMap.containsKey("error_key") && errorMap.getValue("error_key") == "validation_error") { @@ -279,11 +283,15 @@ class FormPresenter(view: FormContract.View) : FormContract.Presenter { if (EmptyUtil.isNotNull(walletConfirmPojo.mobile)) { data["mobile"] = walletConfirmPojo.mobile!! } + if (EmptyUtil.isNotNull(walletConfirmPojo.idx)) { + data["idx"] = walletConfirmPojo.idx!! + } if (EmptyUtil.isNotNull(config.additionalData) && EmptyUtil.isNotEmpty(config.additionalData)) { data.putAll(config.additionalData!!) } config.onCheckOutListener.onSuccess(data) + view.clearForm() view.closeWidget() } diff --git a/khalti-android/src/main/java/com/khalti/checkout/form/helper/WalletConfirmPojo.kt b/khalti-android/src/main/java/com/khalti/checkout/form/helper/WalletConfirmPojo.kt index 3b1e0e5..2dac23d 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/form/helper/WalletConfirmPojo.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/form/helper/WalletConfirmPojo.kt @@ -5,6 +5,9 @@ import com.google.gson.annotations.Expose import com.google.gson.annotations.SerializedName class WalletConfirmPojo { + @SerializedName("idx") + @Expose + val idx: String? = null @SerializedName("product_identity") @Expose val productIdentity: String? = null diff --git a/khalti-android/src/main/java/com/khalti/checkout/helper/BaseComm.kt b/khalti-android/src/main/java/com/khalti/checkout/helper/BaseComm.kt index 05eeaae..20b7355 100644 --- a/khalti-android/src/main/java/com/khalti/checkout/helper/BaseComm.kt +++ b/khalti-android/src/main/java/com/khalti/checkout/helper/BaseComm.kt @@ -2,6 +2,7 @@ package com.khalti.checkout.helper import androidx.appcompat.widget.SearchView import androidx.coordinatorlayout.widget.CoordinatorLayout +import com.khalti.signal.Signal interface BaseComm { @@ -10,4 +11,6 @@ interface BaseComm { fun addSearchView(paymentType: String, searchView: SearchView) fun toggleSearchView(paymentType: String, show: Boolean) + + fun getBackPressedSignal(): Signal } \ No newline at end of file diff --git a/metadata.gradle b/metadata.gradle index 163567c..d9ea99c 100644 --- a/metadata.gradle +++ b/metadata.gradle @@ -2,8 +2,8 @@ ext { appVersionCode = 10000 appVersionName = "1.0.0" - khaltiVersionCode = 2001000 - khaltiVersionName = "2.01.00" + khaltiVersionCode = 2001001 + khaltiVersionName = "2.01.01" compileSdk = 29 buildToolVersion = '29.0.0'