Browse Source

Prevent crash when storage access framework not installed

main
M66B 6 years ago
parent
commit
d3fc9aadcc
1 changed files with 20 additions and 8 deletions
  1. +20
    -8
      app/src/main/java/eu/faircode/email/FragmentCompose.java

+ 20
- 8
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -422,6 +422,10 @@ public class FragmentCompose extends FragmentEx {
menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0); menu.findItem(R.id.menu_attachment).setVisible(!free && working >= 0);
menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled()); menu.findItem(R.id.menu_attachment).setEnabled(etBody.isEnabled());
menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0); menu.findItem(R.id.menu_addresses).setVisible(!free && working >= 0);
PackageManager pm = getContext().getPackageManager();
menu.findItem(R.id.menu_image).setEnabled(getImageIntent().resolveActivity(pm) != null);
menu.findItem(R.id.menu_attachment).setEnabled(getAttachmentIntent().resolveActivity(pm) != null);
} }
@Override @Override
@ -488,17 +492,11 @@ public class FragmentCompose extends FragmentEx {
} }
private void onMenuImage() { private void onMenuImage() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
startActivityForResult(intent, ActivityCompose.REQUEST_IMAGE);
startActivityForResult(getImageIntent(), ActivityCompose.REQUEST_IMAGE);
} }
private void onMenuAttachment() { private void onMenuAttachment() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, ActivityCompose.REQUEST_ATTACHMENT);
startActivityForResult(getAttachmentIntent(), ActivityCompose.REQUEST_ATTACHMENT);
} }
private void onMenuAddresses() { private void onMenuAddresses() {
@ -522,6 +520,20 @@ public class FragmentCompose extends FragmentEx {
} }
} }
private Intent getImageIntent() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("image/*");
return intent;
}
private Intent getAttachmentIntent() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
return intent;
}
private void handleExit() { private void handleExit() {
if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED)) if (getLifecycle().getCurrentState().isAtLeast(Lifecycle.State.RESUMED))
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())


Loading…
Cancel
Save