[android] Display Image Attachements: Address first round of review comments

This commit is contained in:
Torsten Grote
2018-11-19 20:32:43 -02:00
parent de8e95692a
commit 10e9fb308d
6 changed files with 28 additions and 23 deletions

View File

@@ -119,9 +119,14 @@ class AttachmentController {
is.reset();
size = getSizeFromBitmap(is);
}
is.close();
} catch (IOException e) {
logException(LOG, WARNING, e);
} finally {
try {
is.close();
} catch (IOException e) {
logException(LOG, WARNING, e);
}
}
// calculate thumbnail size
@@ -161,7 +166,7 @@ class AttachmentController {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(is, null, options);
if (options.outWidth == -1 || options.outHeight == -1)
if (options.outWidth < 1 || options.outHeight < 1)
return new Size();
return new Size(options.outWidth, options.outHeight);
}
@@ -178,9 +183,10 @@ class AttachmentController {
}
private static class Size {
private int width;
private int height;
private boolean error;
private final int width;
private final int height;
private final boolean error;
private Size(int width, int height) {
this.width = width;

View File

@@ -444,8 +444,12 @@ public class ConversationActivity extends BriarActivity
List<AttachmentHeader> headers) {
runOnDbThread(() -> {
try {
displayMessageAttachments(messageId,
attachmentController.getMessageAttachments(headers));
List<Pair<AttachmentHeader, Attachment>> attachments =
attachmentController.getMessageAttachments(headers);
// TODO move getting the items off to the IoExecutor
List<AttachmentItem> items =
attachmentController.getAttachmentItems(attachments);
displayMessageAttachments(messageId, items);
} catch (DbException e) {
logException(LOG, WARNING, e);
}
@@ -453,10 +457,8 @@ public class ConversationActivity extends BriarActivity
}
private void displayMessageAttachments(MessageId m,
List<Pair<AttachmentHeader, Attachment>> attachments) {
List<AttachmentItem> items) {
runOnUiThreadUnlessDestroyed(() -> {
List<AttachmentItem> items =
attachmentController.getAttachmentItems(attachments);
attachmentController.put(m, items);
Pair<Integer, ConversationMessageItem> pair =
adapter.getMessageItem(m);
@@ -829,12 +831,14 @@ public class ConversationActivity extends BriarActivity
return text;
}
@Nullable
@Override
public List<AttachmentItem> getAttachmentItems(MessageId m,
List<AttachmentHeader> headers) {
List<AttachmentItem> attachments = attachmentController.get(m);
if (attachments == null) loadMessageAttachments(m, headers);
if (attachments == null) {
loadMessageAttachments(m, headers);
return emptyList();
}
return attachments;
}
}

View File

@@ -1,7 +1,6 @@
package org.briarproject.briar.android.conversation;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.briar.api.messaging.PrivateMessageHeader;
@@ -14,16 +13,14 @@ import javax.annotation.concurrent.NotThreadSafe;
@NotNullByDefault
class ConversationMessageItem extends ConversationItem {
@Nullable
private List<AttachmentItem> attachments;
ConversationMessageItem(@LayoutRes int layoutRes, PrivateMessageHeader h,
@Nullable List<AttachmentItem> attachments) {
List<AttachmentItem> attachments) {
super(layoutRes, h);
this.attachments = attachments;
}
@Nullable
List<AttachmentItem> getAttachments() {
return attachments;
}

View File

@@ -21,7 +21,6 @@ import static android.os.Build.VERSION.SDK_INT;
import static android.support.v4.view.ViewCompat.LAYOUT_DIRECTION_RTL;
import static com.bumptech.glide.load.engine.DiskCacheStrategy.NONE;
import static com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions.withCrossFade;
import static java.util.Objects.requireNonNull;
@UiThread
@NotNullByDefault
@@ -83,7 +82,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
super.bind(conversationItem, listener);
ConversationMessageItem item =
(ConversationMessageItem) conversationItem;
if (item.getAttachments() == null || item.getAttachments().isEmpty()) {
if (item.getAttachments().isEmpty()) {
bindTextItem();
} else {
bindImageItem(item);
@@ -101,8 +100,7 @@ class ConversationMessageViewHolder extends ConversationItemViewHolder {
private void bindImageItem(ConversationMessageItem item) {
// TODO show more than just the first image
AttachmentItem attachment =
requireNonNull(item.getAttachments()).get(0);
AttachmentItem attachment = item.getAttachments().get(0);
ConstraintSet constraintSet;
if (item.getText() == null) {

View File

@@ -294,7 +294,6 @@ class ConversationVisitor implements
}
interface AttachmentCache {
@Nullable
List<AttachmentItem> getAttachmentItems(MessageId m,
List<AttachmentHeader> headers);
}

View File

@@ -25,8 +25,9 @@ public final class BriarGlideModule extends AppGlideModule {
@Override
public void registerComponents(Context context, Glide glide,
Registry registry) {
BriarModelLoaderFactory factory =
new BriarModelLoaderFactory((BriarApplication) context);
BriarApplication app =
(BriarApplication) context.getApplicationContext();
BriarModelLoaderFactory factory = new BriarModelLoaderFactory(app);
registry.prepend(AttachmentItem.class, InputStream.class, factory);
}