Преглед на файлове

SendFilesDialog: Show error if no app can send multiple files

Otherwise an empty bottom fragment shows up, which is not good UX

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
Álvaro Brey Vilas преди 3 години
родител
ревизия
61f8115d79
променени са 2 файла, в които са добавени 11 реда и са изтрити 3 реда
  1. 10 3
      src/main/java/com/owncloud/android/ui/dialog/SendFilesDialog.java
  2. 1 0
      src/main/res/values/strings.xml

+ 10 - 3
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<ResolveInfo> 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<SendButtonData> sendButtonDataList = setupSendButtonData(sendIntent);
+        List<SendButtonData> sendButtonDataList = setupSendButtonData(matches);
 
         SendButtonAdapter.ClickListener clickListener = setupSendButtonClickListener(sendIntent);
 
@@ -108,11 +115,11 @@ public class SendFilesDialog extends BottomSheetDialogFragment {
     }
 
     @NonNull
-    private List<SendButtonData> setupSendButtonData(Intent sendIntent) {
+    private List<SendButtonData> setupSendButtonData(List<ResolveInfo> matches) {
         Drawable icon;
         SendButtonData sendButtonData;
         CharSequence label;
-        List<ResolveInfo> matches = requireActivity().getPackageManager().queryIntentActivities(sendIntent, 0);
+
         List<SendButtonData> sendButtonDataList = new ArrayList<>(matches.size());
         for (ResolveInfo match : matches) {
             icon = match.loadIcon(requireActivity().getPackageManager());

+ 1 - 0
src/main/res/values/strings.xml

@@ -1006,4 +1006,5 @@
     <string name="file_list_empty_unified_search_no_results">No results found for your query</string>
     <string name="file_list_empty_gallery">Found no images or videos</string>
     <string name="error_creating_file_from_template">Error creating file from template</string>
+    <string name="no_send_app">No app available for sending the selected files</string>
 </resources>