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
1 changed files with 13 additions and 2 deletions

View File

@ -56,6 +56,7 @@ import com.google.common.base.Optional;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
@ -863,13 +864,13 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
}
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;
}
if (conversation.getNextEncryption() == Message.ENCRYPTION_AXOLOTL && trustKeysIfNeeded(REQUEST_TRUST_KEYS_ATTACHMENTS)) {
return;
}
final List<Attachment> attachments = mediaPreviewAdapter.getAttachments();
final PresenceSelector.OnPresenceSelected callback = () -> {
for (Iterator<Attachment> i = attachments.iterator(); i.hasNext(); i.remove()) {
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() {
boolean hasAttachments = mediaPreviewAdapter.hasAttachments();
binding.textinput.setVisibility(hasAttachments ? View.GONE : View.VISIBLE);