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

Fix deep links to fragments in example app not working #1344

Merged
merged 1 commit into from
Oct 2, 2023
Merged
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
17 changes: 17 additions & 0 deletions example-app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
android:value=".ui.main.MainActivity" />
</activity>

<!-- We have to handle deep links to fragments with this activity. -->
<activity
android:name=".ui.main.MainActivity"
android:exported="true"
Expand All @@ -32,6 +33,22 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- Use a different intent filter then the one used to handle the Drop-In result
(if you have both Drop-In and standalone components in your app). If you don't do this
the user will have to choose which Activity is used to handle the result, which is a
confusing user experience. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data
android:host="${applicationId}"
android:path="/instant"
android:scheme="adyencheckout" />
</intent-filter>

</activity>

<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

package com.adyen.checkout.example.ui.instant

import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -46,7 +47,7 @@ class InstantFragment : BottomSheetDialogFragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
// Insert return url in extras, so we can access it in the ViewModel through SavedStateHandle
val returnUrl = RedirectComponent.getReturnUrl(requireActivity().applicationContext)
val returnUrl = RedirectComponent.getReturnUrl(requireActivity().applicationContext) + RETURN_URL_PATH
arguments = (arguments ?: bundleOf()).apply {
putString(RETURN_URL_EXTRA, returnUrl)
}
Expand All @@ -66,6 +67,10 @@ class InstantFragment : BottomSheetDialogFragment() {
}
}

fun onNewIntent(intent: Intent) {
instantPaymentComponent?.handleIntent(intent)
}

private fun setupInstantComponent(componentData: InstantComponentData) {
val instantPaymentComponent = InstantPaymentComponent.PROVIDER.get(
this,
Expand Down Expand Up @@ -127,9 +132,10 @@ class InstantFragment : BottomSheetDialogFragment() {

companion object {

private const val TAG = "InstantFragment"
internal const val TAG = "InstantFragment"
internal const val PAYMENT_METHOD_TYPE_EXTRA = "PAYMENT_METHOD_TYPE_EXTRA"
internal const val RETURN_URL_EXTRA = "RETURN_URL_EXTRA"
internal const val RETURN_URL_PATH = "/instant"

fun show(fragmentManager: FragmentManager, paymentMethodType: String) {
InstantFragment().apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ class MainActivity : AppCompatActivity() {
viewModel.onResume()
}

override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)

when (intent.data?.path) {
InstantFragment.RETURN_URL_PATH -> {
(supportFragmentManager.findFragmentByTag(InstantFragment.TAG) as? InstantFragment)
?.onNewIntent(intent)
}
}
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.main_menu, menu)
return super.onCreateOptionsMenu(menu)
Expand Down Expand Up @@ -135,6 +146,7 @@ class MainActivity : AppCompatActivity() {
ExampleAdvancedDropInService::class.java,
)
}

is MainNavigation.DropInWithSession -> {
DropIn.startPayment(
this,
Expand All @@ -143,6 +155,7 @@ class MainActivity : AppCompatActivity() {
navigation.dropInConfiguration,
)
}

is MainNavigation.DropInWithCustomSession -> {
DropIn.startPayment(
this,
Expand All @@ -152,31 +165,38 @@ class MainActivity : AppCompatActivity() {
ExampleSessionsDropInService::class.java
)
}

is MainNavigation.Bacs -> BacsFragment.show(supportFragmentManager)
is MainNavigation.Blik -> {
val intent = Intent(this, BlikActivity::class.java)
startActivity(intent)
}

MainNavigation.Card -> {
val intent = Intent(this, CardActivity::class.java)
startActivity(intent)
}

MainNavigation.CardWithSession -> {
val intent = Intent(this, SessionsCardActivity::class.java)
startActivity(intent)
}

MainNavigation.GiftCard -> {
val intent = Intent(this, GiftCardActivity::class.java)
startActivity(intent)
}

MainNavigation.GiftCardWithSession -> {
val intent = Intent(this, SessionsGiftCardActivity::class.java)
startActivity(intent)
}

MainNavigation.CardWithSessionTakenOver -> {
val intent = Intent(this, SessionsCardTakenOverActivity::class.java)
startActivity(intent)
}

is MainNavigation.Instant -> {
InstantFragment.show(supportFragmentManager, navigation.paymentMethodType)
}
Expand Down