feat: adding text and shade, reverting other components to use old ThumbnailView

This commit is contained in:
jubb 2021-06-25 09:57:58 +10:00
parent b5f41b4383
commit 620d063194
15 changed files with 137 additions and 64 deletions

View File

@ -53,8 +53,8 @@ public class AlbumThumbnailView extends FrameLayout {
private void initialize() {
inflate(getContext(), R.layout.album_thumbnail_view, this);
albumCellContainer = findViewById(R.id.album_cell_container);
transferControls = new Stub<>(findViewById(R.id.album_transfer_controls_stub));
albumCellContainer = findViewById(R.id.albumCellContainer);
transferControls = new Stub<>(findViewById(R.id.albumTransferControlsStub));
}
public void setSlides(@NonNull GlideRequests glideRequests, @NonNull List<Slide> slides, boolean showControls) {

View File

@ -65,10 +65,6 @@ public class ConversationItemThumbnail extends FrameLayout {
if (attrs != null) {
TypedArray typedArray = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.ConversationItemThumbnail, 0, 0);
thumbnail.setBounds(typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minHeight, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxHeight, 0));
typedArray.recycle();
}
}

View File

@ -29,7 +29,6 @@ public class OutlinedThumbnailView extends ThumbnailView {
outliner = new Outliner();
outliner.setColor(ThemeUtil.getThemedColor(getContext(), R.attr.conversation_item_image_outline_color));
setRadius(0);
setWillNotDraw(false);
}

View File

@ -6,9 +6,11 @@ import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.album_thumbnail_view.view.*
import network.loki.messenger.R
import org.thoughtcrime.securesms.components.CornerMask
import org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
import org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
import org.thoughtcrime.securesms.mms.GlideRequests
@ -20,13 +22,10 @@ class AlbumThumbnailView: FrameLayout {
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { initialize() }
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { initialize() }
private val albumCellContainer by lazy { album_cell_container }
private lateinit var cornerMask: CornerMask
private val cornerMask by lazy { CornerMask(this) }
private fun initialize() {
LayoutInflater.from(context).inflate(R.layout.album_thumbnail_view, this)
cornerMask = CornerMask(this)
cornerMask.setRadius(80)
}
override fun dispatchDraw(canvas: Canvas?) {
@ -50,8 +49,10 @@ class AlbumThumbnailView: FrameLayout {
LayoutInflater.from(context).inflate(layoutRes(slides.size), albumCellContainer)
// iterate
slides.take(5).forEachIndexed { position, slide ->
getThumbnailView(position).setImageResource(glideRequests, slide, showControls = false, isPreview = false)
val imageResource = getThumbnailView(position).setImageResource(glideRequests, slide, showControls = false, isPreview = false)
}
albumCellBodyParent.isVisible = message.body.isNotEmpty()
albumCellBodyText.text = message.body
}
// endregion
@ -66,12 +67,12 @@ class AlbumThumbnailView: FrameLayout {
else -> R.layout.album_thumbnail_many// five or more
}
fun getThumbnailView(position: Int): ThumbnailView = when (position) {
0 -> albumCellContainer.findViewById<ViewGroup>(R.id.album_cell_container).findViewById(R.id.album_cell_1)
1 -> albumCellContainer.findViewById<ViewGroup>(R.id.album_cell_container).findViewById(R.id.album_cell_2)
2 -> albumCellContainer.findViewById<ViewGroup>(R.id.album_cell_container).findViewById(R.id.album_cell_3)
3 -> albumCellContainer.findViewById<ViewGroup>(R.id.album_cell_container).findViewById(R.id.album_cell_4)
4 -> albumCellContainer.findViewById<ViewGroup>(R.id.album_cell_container).findViewById(R.id.album_cell_5)
fun getThumbnailView(position: Int): KThumbnailView = when (position) {
0 -> albumCellContainer.findViewById<ViewGroup>(R.id.albumCellContainer).findViewById(R.id.album_cell_1)
1 -> albumCellContainer.findViewById<ViewGroup>(R.id.albumCellContainer).findViewById(R.id.album_cell_2)
2 -> albumCellContainer.findViewById<ViewGroup>(R.id.albumCellContainer).findViewById(R.id.album_cell_3)
3 -> albumCellContainer.findViewById<ViewGroup>(R.id.albumCellContainer).findViewById(R.id.album_cell_4)
4 -> albumCellContainer.findViewById<ViewGroup>(R.id.albumCellContainer).findViewById(R.id.album_cell_5)
else -> throw Exception("Can't get thumbnail view for non-existent thumbnail at position: $position")
}

View File

@ -7,7 +7,6 @@ import android.database.Cursor
import android.graphics.Rect
import android.graphics.Typeface
import android.os.Bundle
import android.util.Log
import android.util.TypedValue
import android.view.*
import android.widget.RelativeLayout
@ -31,7 +30,6 @@ import org.session.libsession.messaging.mentions.MentionsManager
import org.session.libsession.messaging.open_groups.OpenGroupAPIV2
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.ApplicationContext
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.conversation.v2.dialogs.*
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton

View File

@ -19,7 +19,7 @@ import network.loki.messenger.R
import org.session.libsession.utilities.ThemeUtil
import org.session.libsession.utilities.ViewUtil
import org.session.libsession.utilities.recipients.Recipient
import org.thoughtcrime.securesms.components.v2.AlbumThumbnailView
import org.thoughtcrime.securesms.conversation.v2.AlbumThumbnailView
import org.thoughtcrime.securesms.components.emoji.EmojiTextView
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
@ -87,6 +87,7 @@ class VisibleMessageContentView : LinearLayout {
val albumThumbnailView = AlbumThumbnailView(context)
mainContainer.addView(albumThumbnailView)
// isStart and isEnd of cluster needed for calculating the mask for full bubble image groups
// bind after add view because views are inflated and calculated during bind
albumThumbnailView.bind(glide, message, isStartOfMessageCluster, isEndOfMessageCluster)
} else if (message.isOpenGroupInvitation) {
val openGroupInvitationView = OpenGroupInvitationView(context)

View File

@ -3,11 +3,14 @@ package org.thoughtcrime.securesms.conversation.v2.utilities
import android.content.Context
import android.graphics.Bitmap
import android.graphics.drawable.Drawable
import android.net.Uri
import android.util.AttributeSet
import android.widget.FrameLayout
import android.widget.ProgressBar
import androidx.core.view.isVisible
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions
import com.bumptech.glide.request.RequestOptions
import kotlinx.android.synthetic.main.thumbnail_view.view.*
@ -15,14 +18,15 @@ import network.loki.messenger.R
import org.session.libsession.messaging.sending_receiving.attachments.AttachmentTransferProgress
import org.session.libsession.utilities.Util.equals
import org.session.libsession.utilities.ViewUtil
import org.session.libsignal.utilities.ListenableFuture
import org.session.libsignal.utilities.SettableFuture
import org.thoughtcrime.securesms.components.GlideBitmapListeningTarget
import org.thoughtcrime.securesms.components.GlideDrawableListeningTarget
import org.thoughtcrime.securesms.components.TransferControlView
import org.thoughtcrime.securesms.mms.*
import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri
import org.thoughtcrime.securesms.mms.GlideRequest
import org.thoughtcrime.securesms.mms.GlideRequests
import org.thoughtcrime.securesms.mms.Slide
import org.thoughtcrime.securesms.mms.SlideClickListener
class ThumbnailView: FrameLayout {
open class KThumbnailView: FrameLayout {
companion object {
private const val WIDTH = 0
@ -45,16 +49,19 @@ class ThumbnailView: FrameLayout {
var thumbnailClickListener: SlideClickListener? = null
private var slide: Slide? = null
private var radius: Int = 0
private fun initialize(attrs: AttributeSet?) {
inflate(context, R.layout.thumbnail_view, this)
if (attrs != null) {
val typedArray = context.theme.obtainStyledAttributes(attrs, R.styleable.ThumbnailView, 0, 0)
dimensDelegate.setBounds(typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_minHeight, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ConversationItemThumbnail_conversationThumbnail_maxHeight, 0))
dimensDelegate.setBounds(typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_minHeight, 0),
typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxWidth, 0),
typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_maxHeight, 0))
radius = typedArray.getDimensionPixelSize(R.styleable.ThumbnailView_thumbnail_radius, 0)
typedArray.recycle()
}
@ -82,13 +89,13 @@ class ThumbnailView: FrameLayout {
// endregion
// region Interaction
fun setImageResource(glide: GlideRequests, slide: Slide, showControls: Boolean, isPreview: Boolean) {
fun setImageResource(glide: GlideRequests, slide: Slide, showControls: Boolean, isPreview: Boolean): ListenableFuture<Boolean> {
return setImageResource(glide, slide, showControls, isPreview, 0, 0)
}
fun setImageResource(glide: GlideRequests, slide: Slide,
showControls: Boolean, isPreview: Boolean,
naturalWidth: Int, naturalHeight: Int) {
naturalWidth: Int, naturalHeight: Int): ListenableFuture<Boolean> {
val currentSlide = this.slide
@ -104,7 +111,7 @@ class ThumbnailView: FrameLayout {
if (equals(currentSlide, slide)) {
// don't re-load slide
return
return SettableFuture(false)
}
@ -121,17 +128,21 @@ class ThumbnailView: FrameLayout {
dimensDelegate.setDimens(naturalWidth, naturalHeight)
invalidate()
val result = SettableFuture<Boolean>()
when {
slide.thumbnailUri != null -> {
buildThumbnailGlideRequest(glide, slide).into(image)
buildThumbnailGlideRequest(glide, slide).into(GlideDrawableListeningTarget(image, result))
}
slide.hasPlaceholder() -> {
buildPlaceholderGlideRequest(glide, slide).into(image)
buildPlaceholderGlideRequest(glide, slide).into(GlideBitmapListeningTarget(image, result))
}
else -> {
glide.clear(image)
result.set(false)
}
}
return result
}
fun buildThumbnailGlideRequest(glide: GlideRequests, slide: Slide): GlideRequest<Drawable> {
@ -169,6 +180,45 @@ class ThumbnailView: FrameLayout {
}
.fitCenter()
}
open fun clear(glideRequests: GlideRequests) {
glideRequests.clear(image)
transferControls.clear()
slide = null
}
fun showProgressSpinner() {
transferControls.showProgressSpinner()
}
fun setImageResource(glideRequests: GlideRequests, uri: Uri): ListenableFuture<Boolean> {
val future = SettableFuture<Boolean>()
transferControls.isVisible = false
var request: GlideRequest<Drawable> = glideRequests.load(DecryptableUri(uri))
.diskCacheStrategy(DiskCacheStrategy.NONE)
.transition(DrawableTransitionOptions.withCrossFade())
request = if (radius > 0) {
request.transforms(CenterCrop(), RoundedCorners(radius))
} else {
request.transforms(CenterCrop())
}
request.into(GlideDrawableListeningTarget(image, future))
return future
}
fun showDownloadText(showDownloadText: Boolean) {
transferControls.setShowDownloadText(showDownloadText)
}
fun setDownloadClickListener(listener: SlidesClickedListener) {
}
// endregion
}

View File

@ -83,7 +83,7 @@ public class AttachmentManager {
private final @NonNull AttachmentListener attachmentListener;
private RemovableEditableMediaView removableMediaView;
private ThumbnailView thumbnail;
private ThumbnailView thumbnail;
private MessageAudioView audioView;
private DocumentView documentView;

View File

@ -6,14 +6,14 @@
android:layout_width="@dimen/media_bubble_default_dimens"
android:layout_height="@dimen/media_bubble_default_dimens">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:conversationThumbnail_minWidth="@dimen/media_bubble_min_width"
app:conversationThumbnail_maxWidth="@dimen/media_bubble_max_width"
app:conversationThumbnail_minHeight="@dimen/media_bubble_min_height"
app:conversationThumbnail_maxHeight="@dimen/media_bubble_max_height"
app:minWidth="@dimen/media_bubble_min_width"
app:maxWidth="@dimen/media_bubble_max_width"
app:minHeight="@dimen/media_bubble_min_height"
app:maxHeight="@dimen/media_bubble_max_height"
app:thumbnail_radius="1dp"/>
</FrameLayout>

View File

@ -7,13 +7,13 @@
android:layout_width="@dimen/album_total_width"
android:layout_height="@dimen/album_2_total_height">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="@dimen/album_2_cell_width"
android:layout_height="@dimen/album_2_total_height"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_2"
android:layout_width="@dimen/album_2_cell_width"
android:layout_height="@dimen/album_2_total_height"

View File

@ -6,20 +6,20 @@
android:layout_width="@dimen/album_total_width"
android:layout_height="@dimen/album_3_total_height">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="@dimen/album_3_cell_width_big"
android:layout_height="@dimen/album_3_total_height"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_2"
android:layout_width="@dimen/album_3_cell_size_small"
android:layout_height="@dimen/album_3_cell_size_small"
android:layout_gravity="right|end|top"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_3"
android:layout_width="@dimen/album_3_cell_size_small"
android:layout_height="@dimen/album_3_cell_size_small"

View File

@ -6,27 +6,27 @@
android:layout_width="@dimen/album_total_width"
android:layout_height="@dimen/album_4_total_height">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="@dimen/album_4_cell_size"
android:layout_height="@dimen/album_4_cell_size"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_2"
android:layout_width="@dimen/album_4_cell_size"
android:layout_height="@dimen/album_4_cell_size"
android:layout_gravity="right|end|top"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_3"
android:layout_width="@dimen/album_4_cell_size"
android:layout_height="@dimen/album_4_cell_size"
android:layout_gravity="left|start|bottom"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_4"
android:layout_width="@dimen/album_4_cell_size"
android:layout_height="@dimen/album_4_cell_size"

View File

@ -6,34 +6,34 @@
android:layout_width="@dimen/album_total_width"
android:layout_height="@dimen/album_5_total_height">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="@dimen/album_5_cell_size_big"
android:layout_height="@dimen/album_5_cell_size_big"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_2"
android:layout_width="@dimen/album_5_cell_size_big"
android:layout_height="@dimen/album_5_cell_size_big"
android:layout_gravity="right|end|top"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_3"
android:layout_width="@dimen/album_5_cell_size_small"
android:layout_height="@dimen/album_5_cell_size_small"
android:layout_gravity="left|start|bottom"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_4"
android:layout_width="@dimen/album_5_cell_size_small"
android:layout_height="@dimen/album_5_cell_size_small"
android:layout_gravity="center_horizontal|bottom"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_5"
android:layout_width="@dimen/album_5_cell_size_small"
android:layout_height="@dimen/album_5_cell_size_small"

View File

@ -7,27 +7,27 @@
android:layout_width="@dimen/album_total_width"
android:layout_height="@dimen/album_5_total_height">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_1"
android:layout_width="@dimen/album_5_cell_size_big"
android:layout_height="@dimen/album_5_cell_size_big"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_2"
android:layout_width="@dimen/album_5_cell_size_big"
android:layout_height="@dimen/album_5_cell_size_big"
android:layout_gravity="right|end|top"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_3"
android:layout_width="@dimen/album_5_cell_size_small"
android:layout_height="@dimen/album_5_cell_size_small"
android:layout_gravity="left|start|bottom"
app:thumbnail_radius="0dp"/>
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_4"
android:layout_width="@dimen/album_5_cell_size_small"
android:layout_height="@dimen/album_5_cell_size_small"
@ -39,7 +39,7 @@
android:layout_height="@dimen/album_5_cell_size_small"
android:layout_gravity="right|end|bottom">
<org.thoughtcrime.securesms.conversation.v2.utilities.ThumbnailView
<org.thoughtcrime.securesms.conversation.v2.utilities.KThumbnailView
android:id="@+id/album_cell_5"
android:layout_height="match_parent"
android:layout_width="match_parent"

View File

@ -1,21 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<merge
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<FrameLayout
android:id="@+id/album_cell_container"
android:id="@+id/albumCellContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="?conversation_background"/>
/>
<ViewStub
android:id="@+id/album_transfer_controls_stub"
android:id="@+id/albumTransferControlsStub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout="@layout/transfer_controls_stub" />
<FrameLayout
android:visibility="gone"
android:layout_gravity="bottom"
android:id="@+id/albumCellBodyParent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/albumCellShade"
android:src="@drawable/image_shade"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<View
android:layout_margin="@dimen/small_spacing"
android:layout_width="@dimen/small_spacing"
android:layout_height="match_parent"
android:background="@color/accent"/>
<TextView
android:id="@+id/albumCellBodyText"
android:textColor="@color/core_white"
android:layout_margin="@dimen/small_spacing"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</FrameLayout>
</merge>