diff --git a/app/src/main/java/com/amaze/filemanager/asynchronous/handlers/FileHandler.kt b/app/src/main/java/com/amaze/filemanager/asynchronous/handlers/FileHandler.kt index 8ba17a597f..513bc0e5d6 100644 --- a/app/src/main/java/com/amaze/filemanager/asynchronous/handlers/FileHandler.kt +++ b/app/src/main/java/com/amaze/filemanager/asynchronous/handlers/FileHandler.kt @@ -93,9 +93,11 @@ class FileHandler( !mainFragmentViewModel.isList ) } else { - val itemList = main.elementsList ?: listOf() - // we already have some elements in list view, invalidate the adapter - (listView.adapter as RecyclerAdapter).setItems(listView, itemList) + listView.adapter?.let { + val itemList = main.elementsList ?: listOf() + // we already have some elements in list view, invalidate the adapter + (listView.adapter as RecyclerAdapter).setItems(listView, itemList) + } } } else { // there was no list view, means the directory was empty diff --git a/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java b/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java index c8a11f114b..ea86addfb2 100644 --- a/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java +++ b/app/src/main/java/com/amaze/filemanager/ui/fragments/MainFragment.java @@ -536,25 +536,29 @@ public void returnIntentResults(HybridFileParcelable baseFile) { requireMainActivity().mReturnIntent = false; - Uri mediaStoreUri = Utils.getUriForBaseFile(requireActivity(), baseFile); - LOG.debug( - mediaStoreUri.toString() - + "\t" - + MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); - Intent intent = new Intent(); - intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - intent.setAction(Intent.ACTION_SEND); - - if (requireMainActivity().mRingtonePickerIntent) { - intent.setDataAndType( - mediaStoreUri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); - intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri); + @Nullable Uri mediaStoreUri = Utils.getUriForBaseFile(requireActivity(), baseFile); + if(mediaStoreUri != null) { + LOG.debug( + mediaStoreUri.toString() + + "\t" + + MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); + Intent intent = new Intent(); + intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + intent.setAction(Intent.ACTION_SEND); + + if (requireMainActivity().mRingtonePickerIntent) { + intent.setDataAndType( + mediaStoreUri, MimeTypes.getMimeType(baseFile.getPath(), baseFile.isDirectory())); + intent.putExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI, mediaStoreUri); + } else { + LOG.debug("pickup file"); + intent.setDataAndType(mediaStoreUri, MimeTypes.getExtension(baseFile.getPath())); + } + requireActivity().setResult(FragmentActivity.RESULT_OK, intent); } else { - LOG.debug("pickup file"); - intent.setDataAndType(mediaStoreUri, MimeTypes.getExtension(baseFile.getPath())); + LOG.warn("Unable to get URI from baseFile [{}]", baseFile.getPath()); } - getActivity().setResult(FragmentActivity.RESULT_OK, intent); - getActivity().finish(); + requireActivity().finish(); } LoadFilesListTask loadFilesListTask;