diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt index e3c8c1b..f7d95ff 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/fragments/HotwireWebFragmentDelegate.kt @@ -45,8 +45,8 @@ internal class HotwireWebFragmentDelegate( private val screenshotHolder = HotwireViewScreenshotHolder() private val navigator get() = navDestination.navigator private val session get() = navigator.session - private val turboView get() = callback.hotwireView - private val viewTreeLifecycleOwner get() = turboView?.findViewTreeLifecycleOwner() + private val hotwireView get() = callback.hotwireView + private val viewTreeLifecycleOwner get() = hotwireView?.findViewTreeLifecycleOwner() /** * Get the session's WebView instance @@ -137,7 +137,7 @@ internal class HotwireWebFragmentDelegate( fun refresh(displayProgress: Boolean) { if (webView.url == null) return - turboView?.webViewRefresh?.apply { + hotwireView?.webViewRefresh?.apply { if (displayProgress && !isRefreshing) { isRefreshing = true } @@ -151,7 +151,7 @@ internal class HotwireWebFragmentDelegate( * Displays the error view that's implemented via [HotwireWebFragmentCallback.createErrorView]. */ fun showErrorView(error: VisitError) { - turboView?.addErrorView(callback.createErrorView(error)) + hotwireView?.addErrorView(callback.createErrorView(error)) } // ----------------------------------------------------------------------- @@ -275,7 +275,7 @@ internal class HotwireWebFragmentDelegate( private fun initView() { screenshotHolder.currentlyZoomed = false - turboView?.let { + hotwireView?.let { initializePullToRefresh(it) initializeErrorPullToRefresh(it) @@ -289,7 +289,7 @@ internal class HotwireWebFragmentDelegate( } private fun attachWebView(onReady: (Boolean) -> Unit = {}) { - val view = turboView + val view = hotwireView if (view == null) { onReady(false) @@ -316,7 +316,7 @@ internal class HotwireWebFragmentDelegate( val webView = webView screenshotView() - turboView?.detachWebView(webView) { + hotwireView?.detachWebView(webView) { callback.onWebViewDetached(webView) onReady() } @@ -345,7 +345,7 @@ internal class HotwireWebFragmentDelegate( private fun webViewIsAttached(): Boolean { val webView = webView - return turboView?.webViewIsAttached(webView) ?: false + return hotwireView?.webViewIsAttached(webView) ?: false } private fun title(): String { @@ -406,14 +406,14 @@ internal class HotwireWebFragmentDelegate( } private suspend fun screenshotView() { - turboView?.let { + hotwireView?.let { screenshotHolder.captureScreenshot(it) screenshotHolder.showScreenshotIfAvailable(it) } } private fun showProgressView(location: String) { - turboView?.addProgressView(callback.createProgressView(location)) + hotwireView?.addProgressView(callback.createProgressView(location)) } private fun initializePullToRefresh(hotwireView: HotwireView) { @@ -434,15 +434,15 @@ internal class HotwireWebFragmentDelegate( } private fun pullToRefreshEnabled(enabled: Boolean) { - turboView?.webViewRefresh?.isEnabled = enabled + hotwireView?.webViewRefresh?.isEnabled = enabled } private fun removeTransitionalViews() { - turboView?.webViewRefresh?.isRefreshing = false - turboView?.errorRefresh?.isRefreshing = false - turboView?.removeProgressView() - turboView?.removeScreenshot() - turboView?.removeErrorView() + hotwireView?.webViewRefresh?.isRefreshing = false + hotwireView?.errorRefresh?.isRefreshing = false + hotwireView?.removeProgressView() + hotwireView?.removeScreenshot() + hotwireView?.removeErrorView() } private fun generateIdentifier(): Int { diff --git a/navigation-fragments/src/main/java/dev/hotwire/navigation/util/HotwireViewScreenshotHolder.kt b/navigation-fragments/src/main/java/dev/hotwire/navigation/util/HotwireViewScreenshotHolder.kt index 73245fd..72c41f0 100644 --- a/navigation-fragments/src/main/java/dev/hotwire/navigation/util/HotwireViewScreenshotHolder.kt +++ b/navigation-fragments/src/main/java/dev/hotwire/navigation/util/HotwireViewScreenshotHolder.kt @@ -13,7 +13,6 @@ import dev.hotwire.navigation.logging.logEvent import dev.hotwire.navigation.views.HotwireView import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine -import java.security.AccessController.getContext internal class HotwireViewScreenshotHolder { private var bitmap: Bitmap? = null @@ -47,7 +46,9 @@ internal class HotwireViewScreenshotHolder { val start = System.currentTimeMillis() val window = hotwireView.getActivity()?.window - if (window == null || !hotwireView.isLaidOut || !hasEnoughMemoryForScreenshot() || (hotwireView.width <= 0 || hotwireView.height <= 0)) { + if (window == null || !hotwireView.isLaidOut || !hasEnoughMemoryForScreenshot() || + hotwireView.width <= 0 || hotwireView.height <= 0 + ) { if (continuation.isActive) { continuation.resume(null, null) } @@ -61,9 +62,7 @@ internal class HotwireViewScreenshotHolder { try { PixelCopy.request( - window, - rect, - bitmap, + window, rect, bitmap, { result -> if (result == PixelCopy.SUCCESS) { logEvent(