From 72f164bb8d279ae09245ca7b01f225fc5f3ccadf Mon Sep 17 00:00:00 2001 From: Abandoned Cart Date: Fri, 17 Nov 2023 07:04:41 -0500 Subject: [PATCH] Add a null check for a selection-based Uri --- .../main/java/com/hiddenramblings/tagmo/BrowserActivity.kt | 2 +- .../com/hiddenramblings/tagmo/fragment/BrowserFragment.kt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt b/app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt index b446437d7..0c69cffe6 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/BrowserActivity.kt @@ -1830,7 +1830,7 @@ class BrowserActivity : AppCompatActivity(), BrowserSettingsListener, } } - fun decompressArchive(uri: Uri?) { + fun decompressArchive(uri: Uri) { val zipFile = File(externalCacheDir, "archive.zip") zipFile.outputStream().use { fileOut -> contentResolver.openInputStream(uri)?.use { diff --git a/app/src/main/java/com/hiddenramblings/tagmo/fragment/BrowserFragment.kt b/app/src/main/java/com/hiddenramblings/tagmo/fragment/BrowserFragment.kt index 444f36529..71ea162e9 100644 --- a/app/src/main/java/com/hiddenramblings/tagmo/fragment/BrowserFragment.kt +++ b/app/src/main/java/com/hiddenramblings/tagmo/fragment/BrowserFragment.kt @@ -114,6 +114,10 @@ class BrowserFragment : Fragment(), OnFoomiiboClickListener { ActivityResultContracts.OpenDocument() ) { uri -> bottomSheet?.state = BottomSheetBehavior.STATE_COLLAPSED + if (null == uri) { + Toasty(requireContext()).Short(R.string.error_uri_unknown) + return@registerForActivityResult + } (requireActivity() as BrowserActivity).decompressArchive(uri) }