mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
Filter attachment URIs in controller.
This commit is contained in:
@@ -6,7 +6,6 @@ import android.arch.lifecycle.ViewModelProvider;
|
|||||||
import android.arch.lifecycle.ViewModelProviders;
|
import android.arch.lifecycle.ViewModelProviders;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@@ -653,15 +652,11 @@ public class ConversationActivity extends BriarActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Uri> filterAttachmentUris(List<Uri> uris) {
|
public void onTooManyAttachments() {
|
||||||
if (uris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
String format = getResources().getString(
|
||||||
String format = getResources().getString(
|
R.string.messaging_too_many_attachments_toast);
|
||||||
R.string.messaging_too_many_attachments_toast);
|
String warning = String.format(format, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
String warning = String.format(format, MAX_ATTACHMENTS_PER_MESSAGE);
|
Toast.makeText(this, warning, LENGTH_SHORT).show();
|
||||||
Toast.makeText(this, warning, LENGTH_SHORT).show();
|
|
||||||
uris = uris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
|
||||||
}
|
|
||||||
return new ArrayList<>(uris);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ import static android.view.View.GONE;
|
|||||||
import static android.widget.Toast.LENGTH_LONG;
|
import static android.widget.Toast.LENGTH_LONG;
|
||||||
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
import static org.briarproject.briar.android.util.UiUtils.resolveColorAttribute;
|
||||||
import static org.briarproject.briar.api.messaging.MessagingConstants.IMAGE_MIME_TYPES;
|
import static org.briarproject.briar.api.messaging.MessagingConstants.IMAGE_MIME_TYPES;
|
||||||
|
import static org.briarproject.briar.api.messaging.MessagingConstants.MAX_ATTACHMENTS_PER_MESSAGE;
|
||||||
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED;
|
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_DISMISSED;
|
||||||
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED;
|
import static uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.STATE_FINISHED;
|
||||||
|
|
||||||
@@ -153,25 +154,28 @@ public class TextAttachmentController extends TextSendController
|
|||||||
public void onImageReceived(@Nullable Intent resultData) {
|
public void onImageReceived(@Nullable Intent resultData) {
|
||||||
if (resultData == null) return;
|
if (resultData == null) return;
|
||||||
if (loadingUris || !imageUris.isEmpty()) throw new AssertionError();
|
if (loadingUris || !imageUris.isEmpty()) throw new AssertionError();
|
||||||
|
List<Uri> newUris = new ArrayList<>();
|
||||||
if (resultData.getData() != null) {
|
if (resultData.getData() != null) {
|
||||||
imageUris.add(resultData.getData());
|
newUris.add(resultData.getData());
|
||||||
onNewUris(false);
|
onNewUris(false, newUris);
|
||||||
} else if (SDK_INT >= 18 && resultData.getClipData() != null) {
|
} else if (SDK_INT >= 18 && resultData.getClipData() != null) {
|
||||||
ClipData clipData = resultData.getClipData();
|
ClipData clipData = resultData.getClipData();
|
||||||
for (int i = 0; i < clipData.getItemCount(); i++) {
|
for (int i = 0; i < clipData.getItemCount(); i++) {
|
||||||
imageUris.add(clipData.getItemAt(i).getUri());
|
newUris.add(clipData.getItemAt(i).getUri());
|
||||||
}
|
}
|
||||||
onNewUris(false);
|
onNewUris(false, newUris);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onNewUris(boolean restart) {
|
private void onNewUris(boolean restart, List<Uri> newUris) {
|
||||||
if (imageUris.isEmpty()) return;
|
if (newUris.isEmpty()) return;
|
||||||
if (loadingUris) throw new AssertionError();
|
if (loadingUris) throw new AssertionError();
|
||||||
loadingUris = true;
|
loadingUris = true;
|
||||||
List<Uri> filtered = attachmentListener.filterAttachmentUris(imageUris);
|
if (newUris.size() > MAX_ATTACHMENTS_PER_MESSAGE) {
|
||||||
imageUris.clear();
|
newUris = newUris.subList(0, MAX_ATTACHMENTS_PER_MESSAGE);
|
||||||
imageUris.addAll(filtered);
|
attachmentListener.onTooManyAttachments();
|
||||||
|
}
|
||||||
|
imageUris.addAll(newUris);
|
||||||
updateViewState();
|
updateViewState();
|
||||||
textInput.setHint(R.string.image_caption_hint);
|
textInput.setHint(R.string.image_caption_hint);
|
||||||
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
List<ImagePreviewItem> items = ImagePreviewItem.fromUris(imageUris);
|
||||||
@@ -244,8 +248,7 @@ public class TextAttachmentController extends TextSendController
|
|||||||
public Parcelable onRestoreInstanceState(Parcelable inState) {
|
public Parcelable onRestoreInstanceState(Parcelable inState) {
|
||||||
SavedState state = (SavedState) inState;
|
SavedState state = (SavedState) inState;
|
||||||
if (!imageUris.isEmpty()) throw new AssertionError();
|
if (!imageUris.isEmpty()) throw new AssertionError();
|
||||||
if (state.imageUris != null) imageUris.addAll(state.imageUris);
|
if (state.imageUris != null) onNewUris(true, state.imageUris);
|
||||||
onNewUris(true);
|
|
||||||
return state.getSuperState();
|
return state.getSuperState();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +328,6 @@ public class TextAttachmentController extends TextSendController
|
|||||||
|
|
||||||
void onAttachImage(Intent intent);
|
void onAttachImage(Intent intent);
|
||||||
|
|
||||||
List<Uri> filterAttachmentUris(List<Uri> uris);
|
void onTooManyAttachments();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user