Skip to content

Commit f4dc70e

Browse files
committed
make SEPACardInputActivity a BaseFragmentActivity child, Fix SEPACardInputActivity launched from CheckoutActivity not going back to CheckoutActivity
1 parent 26f982f commit f4dc70e

File tree

8 files changed

+36
-25
lines changed

8 files changed

+36
-25
lines changed

kotlin-sample/src/main/res/navigation/mobile_navigation.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383

8484
<fragment
8585
android:id="@+id/navigation_payment_status"
86-
android:name="io.snabble.sdk.ui.payment.PaymentStatusFragment"
86+
android:name="io.snabble.sdk.ui.checkout.PaymentStatusFragment"
8787
android:label="Payment Status" />
8888

8989
<action

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class CheckoutActivity : FragmentActivity() {
2222
@JvmStatic
2323
fun startCheckoutFlow(context: Context, args: Bundle?) {
2424
val intent = Intent(context, CheckoutActivity::class.java)
25-
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
2625
args?.let {
2726
intent.putExtras(args)
2827
}

ui/src/main/java/io/snabble/sdk/ui/checkout/CheckoutGatekeeperView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public void onStateChanged(Checkout.State state) {
161161
String id = checkout.getId();
162162
if (id != null) {
163163
checkoutIdCode.setText("snabble:checkoutProcess:" + id);
164+
Logger.d("QR_CODE = snabble:checkoutProcess:" + id);
164165
}
165166
break;
166167
case PAYMENT_PROCESSING:

ui/src/main/java/io/snabble/sdk/ui/payment/PaymentStatusFragment.kt renamed to ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusFragment.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package io.snabble.sdk.ui.payment
1+
package io.snabble.sdk.ui.checkout
22

33
import android.os.Bundle
44
import android.view.LayoutInflater

ui/src/main/java/io/snabble/sdk/ui/checkout/PaymentStatusView.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ class PaymentStatusView @JvmOverloads constructor(
5252
private var paymentOriginCandidate: PaymentOriginCandidate? = null
5353
private var paymentOriginCandidateHelper: PaymentOriginCandidateHelper
5454
private var ignoreStateChanges = false
55+
private var hasShownSEPAInput = false
5556

5657
init {
5758
inflate(getContext(), R.layout.snabble_view_payment_status, this)
@@ -111,6 +112,8 @@ class PaymentStatusView @JvmOverloads constructor(
111112
intent.putExtra(SEPACardInputActivity.ARG_PAYMENT_ORIGIN_CANDIDATE, paymentOriginCandidate)
112113
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
113114
getContext()?.startActivity(intent)
115+
binding.addIbanLayout.isVisible = false
116+
hasShownSEPAInput = true
114117
}
115118

116119
val activity = getFragmentActivity()
@@ -229,7 +232,7 @@ class PaymentStatusView @JvmOverloads constructor(
229232
binding.payment.setText(resources.getString(R.string.Snabble_PaymentStatus_Payment_error))
230233
binding.payment.setAction(resources.getString(R.string.Snabble_PaymentStatus_Payment_tryAgain)) {
231234
project.shoppingCart.generateNewUUID()
232-
executeUiAction(SnabbleUI.Event.GO_BACK, null)
235+
requireFragmentActivity().finish()
233236
}
234237
binding.title.text = resources.getString(R.string.Snabble_PaymentStatus_Title_error)
235238
binding.image.isVisible = true
@@ -241,6 +244,10 @@ class PaymentStatusView @JvmOverloads constructor(
241244
}
242245

243246
private fun startPollingForPaymentOriginCandidate() {
247+
if (hasShownSEPAInput) {
248+
return
249+
}
250+
244251
paymentOriginCandidateHelper.addPaymentOriginCandidateAvailableListener(this)
245252
if (checkout.state == Checkout.State.PAYMENT_APPROVED) {
246253
paymentOriginCandidateHelper.startPollingIfLinkIsAvailable(checkout.checkoutProcess)

ui/src/main/java/io/snabble/sdk/ui/payment/SEPACardInputActivity.kt

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,18 @@ package io.snabble.sdk.ui.payment
22

33
import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
5+
import androidx.fragment.app.Fragment
56
import io.snabble.sdk.PaymentOriginCandidateHelper
7+
import io.snabble.sdk.ui.BaseFragmentActivity
68

7-
class SEPACardInputActivity : AppCompatActivity() {
9+
class SEPACardInputActivity : BaseFragmentActivity() {
810
companion object {
9-
const val ARG_PAYMENT_ORIGIN_CANDIDATE = "paymentOriginCandidate"
11+
const val ARG_PAYMENT_ORIGIN_CANDIDATE = SEPACardInputFragment.ARG_PAYMENT_ORIGIN_CANDIDATE
1012
}
1113

12-
override fun onCreate(savedInstanceState: Bundle?) {
13-
super.onCreate(savedInstanceState)
14-
15-
val view = SEPACardInputView(this)
16-
view.setOnCloseListener {
17-
finish()
18-
}
19-
20-
val args = intent.extras
21-
val paymentOriginCandidate = args?.getSerializable(ARG_PAYMENT_ORIGIN_CANDIDATE)
22-
as? PaymentOriginCandidateHelper.PaymentOriginCandidate
23-
24-
paymentOriginCandidate?.let {
25-
view.setPrefilledPaymentOriginCandidate(paymentOriginCandidate)
26-
}
27-
28-
setContentView(view)
14+
override fun onCreateFragment(): Fragment {
15+
val fragment = SEPACardInputFragment()
16+
fragment.arguments = intent.extras
17+
return fragment
2918
}
3019
}

ui/src/main/java/io/snabble/sdk/ui/payment/SEPACardInputFragment.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,34 @@ import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
77
import androidx.fragment.app.Fragment
8+
import io.snabble.sdk.PaymentMethod
9+
import io.snabble.sdk.PaymentOriginCandidateHelper
810
import io.snabble.sdk.ui.R
911

1012
open class SEPACardInputFragment : Fragment() {
13+
companion object {
14+
const val ARG_PAYMENT_ORIGIN_CANDIDATE = "paymentOriginCandidate"
15+
}
16+
17+
var paymentOriginCandidate: PaymentOriginCandidateHelper.PaymentOriginCandidate? = null
18+
1119
override fun onCreate(savedInstanceState: Bundle?) {
1220
super.onCreate(savedInstanceState)
1321
setHasOptionsMenu(true)
22+
23+
paymentOriginCandidate = arguments?.getSerializable(SEPACardInputActivity.ARG_PAYMENT_ORIGIN_CANDIDATE)
24+
as? PaymentOriginCandidateHelper.PaymentOriginCandidate
1425
}
1526

1627
override fun onCreateView(
1728
inflater: LayoutInflater,
1829
container: ViewGroup?,
1930
savedInstanceState: Bundle?
2031
): View? {
21-
return inflater.inflate(R.layout.snabble_fragment_cardinput_sepa, container, false)
32+
val v = inflater.inflate(R.layout.snabble_fragment_cardinput_sepa, container, false) as SEPACardInputView
33+
paymentOriginCandidate?.let {
34+
v.setPrefilledPaymentOriginCandidate(paymentOriginCandidate)
35+
}
36+
return v
2237
}
2338
}

ui/src/main/res/navigation/snabble_nav_checkout.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
<fragment
4040
android:id="@+id/snabble_nav_payment_status"
41-
android:name="io.snabble.sdk.ui.payment.PaymentStatusFragment"
41+
android:name="io.snabble.sdk.ui.checkout.PaymentStatusFragment"
4242
android:label="@string/Snabble.Checkout.title">
4343

4444
</fragment>

0 commit comments

Comments
 (0)