diff --git a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java index 3f8f03fa51..def84b57f0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java @@ -64,10 +64,12 @@ import org.session.libsignal.utilities.Log; import org.thoughtcrime.securesms.components.MediaView; import org.thoughtcrime.securesms.database.MediaDatabase.MediaRecord; import org.thoughtcrime.securesms.database.loaders.PagingMediaLoader; +import org.thoughtcrime.securesms.database.model.MmsMessageRecord; import org.thoughtcrime.securesms.mediapreview.MediaPreviewViewModel; import org.thoughtcrime.securesms.mediapreview.MediaRailAdapter; import org.thoughtcrime.securesms.mms.GlideApp; import org.thoughtcrime.securesms.mms.GlideRequests; +import org.thoughtcrime.securesms.mms.Slide; import org.thoughtcrime.securesms.permissions.Permissions; import org.thoughtcrime.securesms.util.AttachmentUtil; import org.thoughtcrime.securesms.util.DateUtils; @@ -116,6 +118,22 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im private int restartItem = -1; + public static Intent getPreviewIntent(Context context, Slide slide, MmsMessageRecord mms) { + Intent previewIntent = null; + if (MediaPreviewActivity.isContentTypeSupported(slide.getContentType()) && slide.getUri() != null) { + previewIntent = new Intent(context, MediaPreviewActivity.class); + previewIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + .setDataAndType(slide.getUri(), slide.getContentType()) + .putExtra(ADDRESS_EXTRA, mms.getRecipient().getAddress()) + .putExtra(OUTGOING_EXTRA, mms.isOutgoing()) + .putExtra(DATE_EXTRA, mms.getTimestamp()) + .putExtra(SIZE_EXTRA, slide.asAttachment().getSize()) + .putExtra(CAPTION_EXTRA, slide.getCaption().orNull()) + .putExtra(LEFT_IS_RECENT_EXTRA, false); + } + return previewIntent; + } + @SuppressWarnings("ConstantConditions") @Override diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/AlbumThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/AlbumThumbnailView.kt index 56da118f3b..d895e50743 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/AlbumThumbnailView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/AlbumThumbnailView.kt @@ -38,6 +38,7 @@ class AlbumThumbnailView : FrameLayout { private val cornerMask by lazy { CornerMask(this) } private var slides: List = listOf() + private var slideSize: Int = 0 private fun initialize() { LayoutInflater.from(context).inflate(R.layout.album_thumbnail_view, this) @@ -69,22 +70,9 @@ class AlbumThumbnailView : FrameLayout { child.getGlobalVisibleRect(testRect) if (Rect.intersects(rawRect, testRect)) { // hit intersects with this particular child - slides.getOrNull(index)?.let { slide -> - // dispatch to view image - if (MediaPreviewActivity.isContentTypeSupported(slide.contentType) && slide.uri != null) { - ActivityDispatcher.get(context)?.dispatchIntent { context -> - Intent(context, MediaPreviewActivity::class.java).apply { - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - setDataAndType(slide.uri, slide.contentType) - putExtra(MediaPreviewActivity.ADDRESS_EXTRA, mms.recipient.address) - putExtra(MediaPreviewActivity.OUTGOING_EXTRA, mms.isOutgoing) - putExtra(MediaPreviewActivity.DATE_EXTRA, mms.timestamp) - putExtra(MediaPreviewActivity.SIZE_EXTRA, slide.asAttachment().size) - putExtra(MediaPreviewActivity.CAPTION_EXTRA, slide.caption.orNull()) - putExtra(MediaPreviewActivity.LEFT_IS_RECENT_EXTRA, false) - } - } - } + val slide = slides.getOrNull(index) ?: return + ActivityDispatcher.get(context)?.dispatchIntent { context -> + MediaPreviewActivity.getPreviewIntent(context, slide, mms) } } } @@ -92,16 +80,20 @@ class AlbumThumbnailView : FrameLayout { fun bind(glideRequests: GlideRequests, message: MmsMessageRecord, isStart: Boolean, isEnd: Boolean) { - // TODO: optimize for same size slides = message.slideDeck.thumbnailSlides if (slides.isEmpty()) { // this should never be encountered because it's checked by parent return } calculateRadius(isStart, isEnd, message.isOutgoing) - albumCellContainer.removeAllViews() - LayoutInflater.from(context).inflate(layoutRes(slides.size), albumCellContainer) - // iterate + + // recreate cell views if different size to what we have already (for recycling) + if (slides.size != this.slideSize) { + albumCellContainer.removeAllViews() + LayoutInflater.from(context).inflate(layoutRes(slides.size), albumCellContainer) + this.slideSize = slides.size + } + // iterate binding slides.take(5).forEachIndexed { position, slide -> val thumbnailView = getThumbnailView(position) thumbnailView.setImageResource(glideRequests, slide, showControls = false, isPreview = false) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt index 52038d7316..336645dfbb 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/ConversationActivityV2.kt @@ -151,8 +151,8 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe return super.getSystemService(name) } - override fun dispatchIntent(body: (Context) -> Intent) { - val intent = body(this) + override fun dispatchIntent(body: (Context) -> Intent?) { + val intent = body(this) ?: return push(intent, false) } diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/KThumbnailView.kt b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/KThumbnailView.kt index df6f4d600d..a8d20736ab 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/KThumbnailView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/v2/utilities/KThumbnailView.kt @@ -186,10 +186,6 @@ open class KThumbnailView: FrameLayout { slide = null } - fun showProgressSpinner() { - transferControls.showProgressSpinner() - } - fun setImageResource(glideRequests: GlideRequests, uri: Uri): ListenableFuture { val future = SettableFuture() @@ -210,18 +206,6 @@ open class KThumbnailView: FrameLayout { return future } - fun showDownloadText(showDownloadText: Boolean) { - transferControls.setShowDownloadText(showDownloadText) - } - - fun setDownloadClickListener(listener: SlidesClickedListener) { - transferControls.setDownloadClickListener { - slide?.let { slide -> - listener.onClick(it, listOf(slide)) - } - } - } - // endregion } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt index 16bc9b1df8..4986a1ce36 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/ActivityUtilities.kt @@ -64,5 +64,5 @@ interface ActivityDispatcher { @SuppressLint("WrongConstant") fun get(context: Context) = context.getSystemService(SERVICE) as? ActivityDispatcher } - fun dispatchIntent(body: (Context)->Intent) + fun dispatchIntent(body: (Context)->Intent?) } \ No newline at end of file