Skip to content

Commit 70b40c9

Browse files
authored
Avoid usage of requireActivity in download callback (#6558)
Task/Issue URL: https://app.asana.com/1/137249556945/project/488551667048375/task/1211022417452920?focus=true ### Description After downloading a file we have a callback which shows a snackbar; there is button on it to open the file. From a stack trace it seems possible the activity is gone and the use of `requireActivity()` results in a crash. Switching to avoiding the crash and doing nothing if the `activity` is null when we try. Fixes #6557 ### Steps to test this PR - [ ] QA optional - [ ] If you want, download a file (e.g., https://file-examples.com/index.php/sample-images-download/sample-jpg-download/) and tap on the snackbar to view it once done Co-authored-by: Craig Russell <[email protected]>
1 parent ea7f906 commit 70b40c9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserTabFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,9 +1579,11 @@ class BrowserTabFragment :
15791579
)
15801580
?.apply {
15811581
this.setAction(R.string.downloadsDownloadFinishedActionName) {
1582-
val result = downloadsFileActions.openFile(requireActivity(), File(command.filePath))
1583-
if (!result) {
1584-
view.makeSnackbarWithNoBottomInset(getString(R.string.downloadsCannotOpenFileErrorMessage), Snackbar.LENGTH_LONG).show()
1582+
activity?.let {
1583+
val result = downloadsFileActions.openFile(it, File(command.filePath))
1584+
if (!result) {
1585+
view.makeSnackbarWithNoBottomInset(getString(R.string.downloadsCannotOpenFileErrorMessage), Snackbar.LENGTH_LONG).show()
1586+
}
15851587
}
15861588
}
15871589
}

0 commit comments

Comments
 (0)