From c418ca18904f4017446de4638dc41859d16030d8 Mon Sep 17 00:00:00 2001 From: Jake McGinty Date: Wed, 9 Sep 2015 08:55:06 -1000 Subject: [PATCH] fix thumbnail click fixes #4051 Closes #4053 // FREEBIE --- .../securesms/components/ThumbnailView.java | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/src/org/thoughtcrime/securesms/components/ThumbnailView.java b/src/org/thoughtcrime/securesms/components/ThumbnailView.java index 07b0cc4cd1..3fb3b74ee4 100644 --- a/src/org/thoughtcrime/securesms/components/ThumbnailView.java +++ b/src/org/thoughtcrime/securesms/components/ThumbnailView.java @@ -5,7 +5,6 @@ import android.app.Activity; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; -import android.os.Build; import android.os.Build.VERSION; import android.os.Build.VERSION_CODES; import android.support.annotation.NonNull; @@ -79,6 +78,9 @@ public class ThumbnailView extends FrameLayout { progress = (ProgressWheel) findViewById(R.id.progress_wheel); downloadButton = (ImageButton) findViewById(R.id.download_button); + setOnClickListener(new ThumbnailClickDispatcher()); + downloadButton.setOnClickListener(new DownloadClickDispatcher()); + if (attrs != null) { TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0); backgroundColorHint = typedArray.getColor(0, Color.BLACK); @@ -184,12 +186,6 @@ public class ThumbnailView extends FrameLayout { this.slide = slide; buildGlideRequest(slide, masterSecret).into(image); - if (this.slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_DONE) { - setOnClickListener(new ThumbnailClickDispatcher(thumbnailClickListener, slide)); - } else { - setOnClickListener(null); - } - downloadButton.setOnClickListener(new ThumbnailClickDispatcher(downloadClickListener, slide)); } public void setThumbnailClickListener(ThumbnailClickListener listener) { @@ -332,20 +328,23 @@ public class ThumbnailView extends FrameLayout { void onClick(View v, Slide slide); } - private static class ThumbnailClickDispatcher implements View.OnClickListener { - private ThumbnailClickListener listener; - private Slide slide; - - public ThumbnailClickDispatcher(ThumbnailClickListener listener, Slide slide) { - this.listener = listener; - this.slide = slide; - } - + private class ThumbnailClickDispatcher implements View.OnClickListener { @Override public void onClick(View view) { - if (listener != null) + if (thumbnailClickListener != null && + slide != null && + slide.getTransferProgress() == PartDatabase.TRANSFER_PROGRESS_DONE) { - listener.onClick(view, slide); + thumbnailClickListener.onClick(view, slide); + } + } + } + + private class DownloadClickDispatcher implements View.OnClickListener { + @Override + public void onClick(View view) { + if (downloadClickListener != null && slide != null) { + downloadClickListener.onClick(view, slide); } } }