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

Improve PaymentAuthWebViewActivity #2555

Merged
merged 1 commit into from
Jun 8, 2020
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
1 change: 1 addition & 0 deletions stripe/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

<activity
android:name=".view.PaymentAuthWebViewActivity"
android:windowSoftInputMode="adjustResize"
android:theme="@style/StripeDefaultTheme" />

<activity
Expand Down
47 changes: 29 additions & 18 deletions stripe/res/layout/payment_auth_web_view_activity.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="@dimen/stripe_toolbar_elevation"
android:theme="@style/StripeToolBarStyle"
app:title="@string/secure_checkout" />
android:layout_height="match_parent"
android:windowSoftInputMode="adjustResize"
android:fitsSystemWindows="true">

<FrameLayout
android:id="@+id/auth_web_view_container"
android:layout_below="@id/toolbar"
android:id="@+id/web_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<com.stripe.android.view.PaymentAuthWebView
android:id="@+id/auth_web_view"
android:id="@+id/web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:windowSoftInputMode="adjustResize"
android:focusable="true"
android:focusableInTouchMode="true" />
</FrameLayout>

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/stripe_toolbar_elevation"
tools:targetApi="lollipop">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="@style/StripeToolBarStyle"
app:title="@string/secure_checkout" />
</com.google.android.material.appbar.AppBarLayout>

<ProgressBar
android:id="@+id/auth_web_view_progress_bar"
android:id="@+id/progress_bar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:indeterminate="true" />
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,14 @@ internal class PaymentAuthWebView @JvmOverloads constructor(
clientSecret: String,
returnUrl: String? = null
) {
val webViewClient = PaymentAuthWebViewClient(activity, activity.packageManager, logger,
progressBar, clientSecret, returnUrl)
val webViewClient = PaymentAuthWebViewClient(
activity,
activity.packageManager,
logger,
progressBar,
clientSecret,
returnUrl
)
setWebViewClient(webViewClient)
this.webViewClient = webViewClient

Expand Down Expand Up @@ -128,7 +134,7 @@ internal class PaymentAuthWebView @JvmOverloads constructor(
returnUrl: String?
) : WebViewClient() {
// user-specified return URL
private val userReturnUri: Uri? = if (returnUrl != null) Uri.parse(returnUrl) else null
private val userReturnUri: Uri? = returnUrl?.let { Uri.parse(it) }

var completionUrlParam: String? = null
private set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ class PaymentAuthWebViewActivity : AppCompatActivity() {
}

logger.debug("PaymentAuthWebViewActivity#onCreate() - PaymentAuthWebView init and loadUrl")
viewBinding.authWebView.init(
viewBinding.webView.init(
this,
logger,
viewBinding.authWebViewProgressBar,
viewBinding.progressBar,
clientSecret,
args.returnUrl
)
viewBinding.authWebView.loadUrl(args.url)
viewBinding.webView.loadUrl(args.url)
}

override fun onDestroy() {
viewBinding.authWebViewContainer.removeAllViews()
viewBinding.authWebView.destroy()
viewBinding.webViewContainer.removeAllViews()
viewBinding.webView.destroy()
super.onDestroy()
}

Expand All @@ -100,8 +100,8 @@ class PaymentAuthWebViewActivity : AppCompatActivity() {
}

override fun onBackPressed() {
if (viewBinding.authWebView.canGoBack()) {
viewBinding.authWebView.goBack()
if (viewBinding.webView.canGoBack()) {
viewBinding.webView.goBack()
} else {
cancelIntentSource()
}
Expand Down