Skip to content

Commit

Permalink
Merge pull request #13425 from woocommerce/merge/release-21.5-into-trunk
Browse files Browse the repository at this point in the history
Merge release/21.5 into trunk
  • Loading branch information
ThomazFB authored Jan 30, 2025
2 parents 32dd18c + 3fc239d commit 5558af5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import com.woocommerce.android.ui.base.BaseFragment
import com.woocommerce.android.ui.base.UIMessageResolver
import com.woocommerce.android.util.PrintHtmlHelper
import com.woocommerce.android.util.UiHelpers
import com.woocommerce.android.util.WooLog
import com.woocommerce.android.viewmodel.MultiLiveEvent.Event.ShowSnackbar
import dagger.hilt.android.AndroidEntryPoint
import java.io.IOException
Expand All @@ -38,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 @@ -58,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 @@ -101,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 All @@ -129,7 +137,8 @@ class ReceiptPreviewFragment : BaseFragment(R.layout.fragment_receipt_preview),
} catch (e: MalformedURLException) {
throw IllegalArgumentException("Invalid receipt URL: ${request.url}", e)
} catch (e: IOException) {
throw IOException("Failed to read content from receipt URL: ${request.url}", e)
WooLog.e(WooLog.T.ORDERS, "Failed to read content from receipt URL: ${request.url}", e)
null
}
}

Expand All @@ -140,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
4 changes: 2 additions & 2 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
versionName=21.5-rc-1
versionCode=638
versionName=21.5-rc-2
versionCode=639

0 comments on commit 5558af5

Please sign in to comment.