From 61f8115d79549680161ccc9c7352413e08c95532 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Brey=20Vilas?= Date: Mon, 10 Jan 2022 18:31:05 +0100 Subject: [PATCH] SendFilesDialog: Show error if no app can send multiple files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise an empty bottom fragment shows up, which is not good UX Signed-off-by: Álvaro Brey Vilas --- .../owncloud/android/ui/dialog/SendFilesDialog.java | 13 ++++++++++--- src/main/res/values/strings.xml | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/owncloud/android/ui/dialog/SendFilesDialog.java b/src/main/java/com/owncloud/android/ui/dialog/SendFilesDialog.java index 8ab51fa98e..b38bde87d6 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/SendFilesDialog.java +++ b/src/main/java/com/owncloud/android/ui/dialog/SendFilesDialog.java @@ -9,6 +9,7 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.Toast; import com.google.android.material.bottomsheet.BottomSheetDialogFragment; import com.nextcloud.client.utils.IntentUtil; @@ -82,8 +83,14 @@ public class SendFilesDialog extends BottomSheetDialogFragment { // populate send apps Intent sendIntent = IntentUtil.createSendIntent(requireContext(), files); + List matches = requireActivity().getPackageManager().queryIntentActivities(sendIntent, 0); + if (matches.isEmpty()) { + Toast.makeText(getContext(), R.string.no_send_app, Toast.LENGTH_SHORT).show(); + dismiss(); + return null; + } - List sendButtonDataList = setupSendButtonData(sendIntent); + List sendButtonDataList = setupSendButtonData(matches); SendButtonAdapter.ClickListener clickListener = setupSendButtonClickListener(sendIntent); @@ -108,11 +115,11 @@ public class SendFilesDialog extends BottomSheetDialogFragment { } @NonNull - private List setupSendButtonData(Intent sendIntent) { + private List setupSendButtonData(List matches) { Drawable icon; SendButtonData sendButtonData; CharSequence label; - List matches = requireActivity().getPackageManager().queryIntentActivities(sendIntent, 0); + List sendButtonDataList = new ArrayList<>(matches.size()); for (ResolveInfo match : matches) { icon = match.loadIcon(requireActivity().getPackageManager()); diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 81ecd3c3a9..fd820068e3 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -1006,4 +1006,5 @@ No results found for your query Found no images or videos Error creating file from template + No app available for sending the selected files