|  |  | @ -1,20 +1,20 @@ | 
			
		
	
		
		
			
				
					
					|  |  |  | package org.thoughtcrime.securesms.conversation.v2.messages |  |  |  | package org.thoughtcrime.securesms.conversation.v2.messages | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.content.Context |  |  |  | import android.content.Context | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.graphics.drawable.Drawable |  |  |  | import android.graphics.Outline | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.graphics.Path | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.graphics.RectF | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.os.Build | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.util.AttributeSet |  |  |  | import android.util.AttributeSet | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.util.Log | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.view.LayoutInflater |  |  |  | import android.view.LayoutInflater | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | import android.view.View | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.view.ViewOutlineProvider |  |  |  | import android.view.ViewOutlineProvider | 
			
		
	
		
		
			
				
					
					|  |  |  | import android.widget.LinearLayout |  |  |  | import android.widget.LinearLayout | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.bumptech.glide.load.engine.DiskCacheStrategy |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.bumptech.glide.load.resource.bitmap.CenterCrop |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import kotlinx.android.synthetic.main.view_link_preview.view.* |  |  |  | import kotlinx.android.synthetic.main.view_link_preview.view.* | 
			
		
	
		
		
			
				
					
					|  |  |  | import network.loki.messenger.R |  |  |  | import network.loki.messenger.R | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.database.model.MmsMessageRecord |  |  |  | import org.thoughtcrime.securesms.database.model.MmsMessageRecord | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.mms.GlideRequests |  |  |  | import org.thoughtcrime.securesms.mms.GlideRequests | 
			
		
	
		
		
			
				
					
					|  |  |  | import org.thoughtcrime.securesms.mms.ImageSlide |  |  |  |  | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | class LinkPreviewView : LinearLayout { |  |  |  | class LinkPreviewView : LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
	
		
		
			
				
					|  |  | @ -29,7 +29,9 @@ class LinkPreviewView : LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |     // endregion |  |  |  |     // endregion | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     // region Updating |  |  |  |     // region Updating | 
			
		
	
		
		
			
				
					
					|  |  |  |     fun bind(message: MmsMessageRecord, glide: GlideRequests) { |  |  |  |     fun bind(message: MmsMessageRecord, glide: GlideRequests, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         mainLinkPreviewContainer.outlineProvider = getOutlineProvider(message.isOutgoing, isStartOfMessageCluster, isEndOfMessageCluster) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         mainLinkPreviewContainer.clipToOutline = true | 
			
		
	
		
		
			
				
					
					|  |  |  |         // Thumbnail |  |  |  |         // Thumbnail | 
			
		
	
		
		
			
				
					
					|  |  |  |         val linkPreview = message.linkPreviews.first() |  |  |  |         val linkPreview = message.linkPreviews.first() | 
			
		
	
		
		
			
				
					
					|  |  |  |         // TODO: Handle downloading state |  |  |  |         // TODO: Handle downloading state | 
			
		
	
	
		
		
			
				
					|  |  | @ -44,4 +46,32 @@ class LinkPreviewView : LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |         // TODO: Implement |  |  |  |         // TODO: Implement | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |     // endregion |  |  |  |     // endregion | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // region Convenience | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     private fun getOutlineProvider(isOutgoing: Boolean, isStartOfMessageCluster: Boolean, isEndOfMessageCluster: Boolean): ViewOutlineProvider { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         return object : ViewOutlineProvider() { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             override fun getOutline(view: View, outline: Outline) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 val path = Path() | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 val rect = RectF(0.0f, 0.0f, view.width.toFloat(), view.height.toFloat()) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 val topLeft = if (isOutgoing) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     resources.getDimension(R.dimen.message_corner_radius) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     if (isStartOfMessageCluster) resources.getDimension(R.dimen.message_corner_radius) else resources.getDimension(R.dimen.message_corner_collapse_radius) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 val topRight = if (isOutgoing) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     if (isStartOfMessageCluster) resources.getDimension(R.dimen.message_corner_radius) else resources.getDimension(R.dimen.message_corner_collapse_radius) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     resources.getDimension(R.dimen.message_corner_radius) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 path.addRoundRect(rect, floatArrayOf( topLeft, topLeft, topRight, topRight, 0.0f, 0.0f, 0.0f, 0.0f ), Path.Direction.CW) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     outline.setPath(path) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                     @Suppress("DEPRECATION") outline.setConvexPath(path) | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     // endregion | 
			
		
	
		
		
			
				
					
					|  |  |  | } |  |  |  | } |