Skip to content

Commit

Permalink
Intercept only the URLs which are initiated to load
Browse files Browse the repository at this point in the history
  • Loading branch information
kidinov committed Jan 29, 2025
1 parent dea69ad commit 792252a
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class ReceiptPreviewFragment : BaseFragment(R.layout.fragment_receipt_preview),
private var _binding: FragmentReceiptPreviewBinding? = null
private val binding get() = _binding!!

private var urlToLoad: String? = null

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

Expand All @@ -59,10 +61,12 @@ class ReceiptPreviewFragment : BaseFragment(R.layout.fragment_receipt_preview),
viewModel.onPrintClicked()
true
}

R.id.menu_send -> {
viewModel.onShareClicked()
true
}

else -> false
}
}
Expand Down Expand Up @@ -102,9 +106,12 @@ class ReceiptPreviewFragment : BaseFragment(R.layout.fragment_receipt_preview),
override fun shouldInterceptRequest(
view: WebView,
request: WebResourceRequest
): WebResourceResponse? {
return interceptAndModifyReceiptResponse(request)
}
): WebResourceResponse? =
if (request.url.toString() == urlToLoad) {
interceptAndModifyReceiptResponse(request)
} else {
null
}

override fun onPageFinished(view: WebView, url: String) {
viewModel.onReceiptLoaded()
Expand Down Expand Up @@ -142,7 +149,10 @@ class ReceiptPreviewFragment : BaseFragment(R.layout.fragment_receipt_preview),
}
viewModel.event.observe(viewLifecycleOwner) {
when (it) {
is LoadUrl -> binding.receiptPreviewPreviewWebview.loadUrl(it.url)
is LoadUrl -> {
urlToLoad = it.url
binding.receiptPreviewPreviewWebview.loadUrl(it.url)
}
is PrintReceipt -> printHtmlHelper.printReceipt(requireActivity(), it.receiptUrl, it.documentName)
is ShowSnackbar -> uiMessageResolver.showSnack(it.message)
else -> it.isHandled = false
Expand Down

0 comments on commit 792252a

Please sign in to comment.