Move attachment constraints check to a background thread.
Fixes #13296 Closes #13306
This commit is contained in:
parent
62ece66f36
commit
6d150aa5cb
1 changed files with 11 additions and 5 deletions
|
@ -35,6 +35,7 @@ import android.widget.Toast;
|
||||||
import androidx.annotation.ColorInt;
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.WorkerThread;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
@ -266,6 +267,8 @@ public class AttachmentManager {
|
||||||
final SettableFuture<Boolean> result = new SettableFuture<>();
|
final SettableFuture<Boolean> result = new SettableFuture<>();
|
||||||
|
|
||||||
new AsyncTask<Void, Void, Slide>() {
|
new AsyncTask<Void, Void, Slide>() {
|
||||||
|
private boolean areConstraintsSatisfied = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
thumbnail.clear(glideRequests);
|
thumbnail.clear(glideRequests);
|
||||||
|
@ -275,19 +278,21 @@ public class AttachmentManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected @Nullable Slide doInBackground(Void... params) {
|
protected @Nullable Slide doInBackground(Void... params) {
|
||||||
|
Slide slide;
|
||||||
try {
|
try {
|
||||||
if (PartAuthority.isLocalUri(uri)) {
|
if (PartAuthority.isLocalUri(uri)) {
|
||||||
return getManuallyCalculatedSlideInfo(uri, width, height);
|
slide = getManuallyCalculatedSlideInfo(uri, width, height);
|
||||||
} else {
|
} else {
|
||||||
Slide result = getContentResolverSlideInfo(uri, width, height);
|
Slide result = getContentResolverSlideInfo(uri, width, height);
|
||||||
|
slide = (result == null) ? getManuallyCalculatedSlideInfo(uri, width, height) : result;
|
||||||
if (result == null) return getManuallyCalculatedSlideInfo(uri, width, height);
|
|
||||||
else return result;
|
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.areConstraintsSatisfied = areConstraintsSatisfied(context, slide, constraints);
|
||||||
|
return slide;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -298,7 +303,7 @@ public class AttachmentManager {
|
||||||
R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
R.string.ConversationActivity_sorry_there_was_an_error_setting_your_attachment,
|
||||||
Toast.LENGTH_SHORT).show();
|
Toast.LENGTH_SHORT).show();
|
||||||
result.set(false);
|
result.set(false);
|
||||||
} else if (!areConstraintsSatisfied(context, slide, constraints)) {
|
} else if (!areConstraintsSatisfied) {
|
||||||
attachmentViewStub.get().setVisibility(View.GONE);
|
attachmentViewStub.get().setVisibility(View.GONE);
|
||||||
Toast.makeText(context,
|
Toast.makeText(context,
|
||||||
R.string.ConversationActivity_attachment_exceeds_size_limits,
|
R.string.ConversationActivity_attachment_exceeds_size_limits,
|
||||||
|
@ -524,6 +529,7 @@ public class AttachmentManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@WorkerThread
|
||||||
private boolean areConstraintsSatisfied(final @NonNull Context context,
|
private boolean areConstraintsSatisfied(final @NonNull Context context,
|
||||||
final @Nullable Slide slide,
|
final @Nullable Slide slide,
|
||||||
final @NonNull MediaConstraints constraints)
|
final @NonNull MediaConstraints constraints)
|
||||||
|
|
Loading…
Add table
Reference in a new issue