From 302f8397c2275e1606405899c98a72c07b35c06a Mon Sep 17 00:00:00 2001 From: Jay Ohms Date: Mon, 21 Dec 2020 11:17:10 -0500 Subject: [PATCH] Simplify using the TurboWebFragmentCallback interface --- .../TurboWebBottomSheetDialogFragment.kt | 22 ------------------ .../turbo/fragments/TurboWebFragment.kt | 23 ------------------- .../fragments/TurboWebFragmentCallback.kt | 20 ++++++++-------- 3 files changed, 11 insertions(+), 54 deletions(-) diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebBottomSheetDialogFragment.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebBottomSheetDialogFragment.kt index aa31eb37..8b106ccf 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebBottomSheetDialogFragment.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebBottomSheetDialogFragment.kt @@ -6,11 +6,9 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.webkit.HttpAuthHandler import dev.hotwire.turbo.R import dev.hotwire.turbo.delegates.TurboWebFragmentDelegate import dev.hotwire.turbo.views.TurboView -import dev.hotwire.turbo.views.TurboWebView /** * The base class from which all bottom sheet web fragments in a @@ -73,27 +71,7 @@ abstract class TurboWebBottomSheetDialogFragment : TurboBottomSheetDialogFragmen return layoutInflater.inflate(R.layout.turbo_error, null) } - override fun onWebViewAttached(webView: TurboWebView) {} - - override fun onWebViewDetached(webView: TurboWebView) {} - - override fun onColdBootPageStarted(location: String) {} - - override fun onColdBootPageCompleted(location: String) {} - - override fun onVisitStarted(location: String) {} - - override fun onVisitCompleted(location: String, completedOffline: Boolean) {} - override fun onVisitErrorReceived(location: String, errorCode: Int) { webDelegate.showErrorView(errorCode) } - - override fun onVisitErrorReceivedWithCachedSnapshotAvailable(location: String, errorCode: Int) { - // Allow app to display an indicator for (potentially) stale content - } - - override fun onReceivedHttpAuthRequest(handler: HttpAuthHandler, host: String, realm: String) { - handler.cancel() - } } diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragment.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragment.kt index 76c4df64..ca051ac2 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragment.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragment.kt @@ -5,13 +5,10 @@ import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.webkit.HttpAuthHandler -import com.google.android.material.textview.MaterialTextView import dev.hotwire.turbo.R import dev.hotwire.turbo.delegates.TurboWebFragmentDelegate import dev.hotwire.turbo.session.TurboSessionModalResult import dev.hotwire.turbo.views.TurboView -import dev.hotwire.turbo.views.TurboWebView /** * The base class from which all web "standard" fragments (non-dialogs) in a @@ -86,27 +83,7 @@ abstract class TurboWebFragment : TurboFragment(), TurboWebFragmentCallback { return layoutInflater.inflate(R.layout.turbo_error, null) } - override fun onWebViewAttached(webView: TurboWebView) {} - - override fun onWebViewDetached(webView: TurboWebView) {} - - override fun onColdBootPageStarted(location: String) {} - - override fun onColdBootPageCompleted(location: String) {} - - override fun onVisitStarted(location: String) {} - - override fun onVisitCompleted(location: String, completedOffline: Boolean) {} - override fun onVisitErrorReceived(location: String, errorCode: Int) { webDelegate.showErrorView(errorCode) } - - override fun onVisitErrorReceivedWithCachedSnapshotAvailable(location: String, errorCode: Int) { - // Allow app to display an indicator for (potentially) stale content - } - - override fun onReceivedHttpAuthRequest(handler: HttpAuthHandler, host: String, realm: String) { - handler.cancel() - } } diff --git a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt index 89723d1d..3962ac7c 100644 --- a/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt +++ b/turbo/src/main/kotlin/dev/hotwire/turbo/fragments/TurboWebFragmentCallback.kt @@ -28,46 +28,48 @@ interface TurboWebFragmentCallback { /** * Called when the WebView has been attached to the current destination. */ - fun onWebViewAttached(webView: TurboWebView) + fun onWebViewAttached(webView: TurboWebView) {} /** * Called when the WebView has been detached from the current destination. */ - fun onWebViewDetached(webView: TurboWebView) + fun onWebViewDetached(webView: TurboWebView) {} /** * Called when Turbo begins a WebView cold boot (fresh resources). */ - fun onColdBootPageStarted(location: String) + fun onColdBootPageStarted(location: String) {} /** * Called when Turbo completes a WebView cold boot (fresh resources). */ - fun onColdBootPageCompleted(location: String) + fun onColdBootPageCompleted(location: String) {} /** * Called when a Turbo visit has started. */ - fun onVisitStarted(location: String) + fun onVisitStarted(location: String) {} /** * Called when a Turbo visit has completed. */ - fun onVisitCompleted(location: String, completedOffline: Boolean) + fun onVisitCompleted(location: String, completedOffline: Boolean) {} /** * Called when a Turbo visit resulted in an error. */ - fun onVisitErrorReceived(location: String, errorCode: Int) + fun onVisitErrorReceived(location: String, errorCode: Int) {} /** * Called when the Turbo visit resulted in an error, but a cached * snapshot is being displayed, which may be stale. */ - fun onVisitErrorReceivedWithCachedSnapshotAvailable(location: String, errorCode: Int) + fun onVisitErrorReceivedWithCachedSnapshotAvailable(location: String, errorCode: Int) {} /** * Called when the WebView has received an HTTP authentication request. */ - fun onReceivedHttpAuthRequest(handler: HttpAuthHandler, host: String, realm: String) + fun onReceivedHttpAuthRequest(handler: HttpAuthHandler, host: String, realm: String) { + handler.cancel() + } }