Fixes a crash when a thumbnail for an image attachment fails to load.

main
Vavassor 7 years ago
parent 2674a11c50
commit e24dcbbd7c
  1. 10
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java

@ -1365,6 +1365,10 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
MediaMetadataRetriever retriever = new MediaMetadataRetriever(); MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(this, uri); retriever.setDataSource(this, uri);
Bitmap source = retriever.getFrameAtTime(); Bitmap source = retriever.getFrameAtTime();
if (source == null) {
displayTransientError(R.string.error_media_upload_opening);
return;
}
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize); addMediaToQueue(QueuedMedia.Type.VIDEO, bitmap, uri, mediaSize);
@ -1378,8 +1382,12 @@ public class ComposeActivity extends BaseActivity implements ComposeOptionsFragm
displayTransientError(R.string.error_media_upload_opening); displayTransientError(R.string.error_media_upload_opening);
return; return;
} }
Bitmap source = BitmapFactory.decodeStream(stream); Bitmap source = BitmapFactory.decodeStream(stream);
if (source == null) {
IOUtils.closeQuietly(stream);
displayTransientError(R.string.error_media_upload_opening);
return;
}
Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE); Bitmap bitmap = ThumbnailUtils.extractThumbnail(source, THUMBNAIL_SIZE, THUMBNAIL_SIZE);
source.recycle(); source.recycle();
try { try {

Loading…
Cancel
Save