do not request storage permission for attaching location

This commit is contained in:
Daniel Gultsch 2020-05-16 17:51:14 +02:00
parent 4dd3b0c2aa
commit 1da490f77a

View file

@ -56,6 +56,7 @@ import com.google.common.base.Optional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -863,13 +864,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
private void commitAttachments() { private void commitAttachments() {
if (!hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) { final List<Attachment> attachments = mediaPreviewAdapter.getAttachments();
if (anyNeedsExternalStoragePermission(attachments) && !hasPermissions(REQUEST_COMMIT_ATTACHMENTS, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
return; return;
} }
if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) { if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) {
return; return;
} }
final List<Attachment> attachments = mediaPreviewAdapter.getAttachments();
final PresenceSelector.OnPresenceSelected callback = () -> { final PresenceSelector.OnPresenceSelected callback = () -> {
for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) { for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) {
final Attachment attachment = i.next(); final Attachment attachment = i.next();
@ -896,6 +897,16 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
} }
} }
private static boolean anyNeedsExternalStoragePermission(final Collection<Attachment> attachments) {
for(final Attachment attachment : attachments) {
if (attachment.getType() != Attachment.Type.LOCATION) {
return true;
}
}
return false;
}
public void toggleInputMethod() { public void toggleInputMethod() {
boolean hasAttachments = mediaPreviewAdapter.hasAttachments(); boolean hasAttachments = mediaPreviewAdapter.hasAttachments();
binding.textinput.setVisibility(hasAttachments ? View.GONE : View.VISIBLE); binding.textinput.setVisibility(hasAttachments ? View.GONE : View.VISIBLE);