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>
This commit is contained in:
Álvaro Brey Vilas 2022-01-10 18:31:05 +01:00
parent 93d7c7f9f7
commit 61f8115d79
No known key found for this signature in database
GPG key ID: 2585783189A62105
2 changed files with 11 additions and 3 deletions

View file

@ -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());

View file

@ -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>