Skip to content

Commit

Permalink
Simplify using the TurboWebFragmentCallback interface
Browse files Browse the repository at this point in the history
  • Loading branch information
jayohms committed Dec 21, 2020
1 parent 634058c commit 302f839
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

0 comments on commit 302f839

Please sign in to comment.