mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 09:20:19 +01:00
Implement UI and backend for sending story reactions.
Co-authored-by: Rashad Sookram <rashad@signal.org>
This commit is contained in:
committed by
Cody Henthorne
parent
7f4a12c179
commit
437c1e2f21
@@ -0,0 +1,72 @@
|
||||
package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.content.DialogInterface
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.annotation.LayoutRes
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.Fragment
|
||||
import org.thoughtcrime.securesms.stories.viewer.text.StoryTextPostPreviewFragment
|
||||
import org.thoughtcrime.securesms.util.fragments.requireListener
|
||||
|
||||
/**
|
||||
* Helper functions to display custom views in AlertDialogs anchored to the top of the specified view.
|
||||
*/
|
||||
object FragmentDialogs {
|
||||
|
||||
fun Fragment.displayInDialogAboveAnchor(
|
||||
anchorView: View,
|
||||
@LayoutRes contentLayoutId: Int,
|
||||
windowDim: Float = -1f,
|
||||
onShow: (DialogInterface, View) -> Unit = { _, _ -> }
|
||||
): DialogInterface {
|
||||
val contentView = LayoutInflater.from(anchorView.context).inflate(contentLayoutId, requireView() as ViewGroup, false)
|
||||
|
||||
contentView.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(contentView.layoutParams.width, View.MeasureSpec.EXACTLY),
|
||||
View.MeasureSpec.makeMeasureSpec(contentView.layoutParams.height, View.MeasureSpec.EXACTLY)
|
||||
)
|
||||
|
||||
contentView.layout(0, 0, contentView.measuredWidth, contentView.measuredHeight)
|
||||
|
||||
return displayInDialogAboveAnchor(anchorView, contentView, windowDim, onShow)
|
||||
}
|
||||
|
||||
fun Fragment.displayInDialogAboveAnchor(
|
||||
anchorView: View,
|
||||
contentView: View,
|
||||
windowDim: Float = -1f,
|
||||
onShow: (DialogInterface, View) -> Unit = { _, _ -> }
|
||||
): DialogInterface {
|
||||
val alertDialog = AlertDialog.Builder(requireContext())
|
||||
.setView(contentView)
|
||||
.create()
|
||||
|
||||
alertDialog.window!!.attributes = alertDialog.window!!.attributes.apply {
|
||||
val viewProjection = Projection.relativeToViewRoot(anchorView, null).translateY(anchorView.translationY)
|
||||
this.y = (viewProjection.y - contentView.height).toInt()
|
||||
this.gravity = Gravity.TOP
|
||||
|
||||
viewProjection.release()
|
||||
}
|
||||
|
||||
if (windowDim >= 0f) {
|
||||
alertDialog.window!!.setDimAmount(windowDim)
|
||||
}
|
||||
|
||||
alertDialog.window!!.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
|
||||
alertDialog.setOnDismissListener {
|
||||
requireListener<StoryTextPostPreviewFragment.Callback>().setIsDisplayingLinkPreviewTooltip(false)
|
||||
}
|
||||
|
||||
alertDialog.setOnShowListener { onShow(alertDialog, contentView) }
|
||||
|
||||
alertDialog.show()
|
||||
|
||||
return alertDialog
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ package org.thoughtcrime.securesms.util
|
||||
|
||||
import android.content.Context
|
||||
import org.thoughtcrime.securesms.R
|
||||
import org.thoughtcrime.securesms.database.MmsSmsColumns
|
||||
import org.thoughtcrime.securesms.database.model.MediaMmsMessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
||||
@@ -36,6 +37,9 @@ fun MessageRecord.isCaptionlessMms(context: Context): Boolean =
|
||||
fun MessageRecord.hasThumbnail(): Boolean =
|
||||
isMms && (this as MmsMessageRecord).slideDeck.thumbnailSlide != null
|
||||
|
||||
fun MessageRecord.isStoryReaction(): Boolean =
|
||||
isMms && MmsSmsColumns.Types.isStoryReaction((this as MmsMessageRecord).type)
|
||||
|
||||
fun MessageRecord.isBorderless(context: Context): Boolean {
|
||||
return isCaptionlessMms(context) &&
|
||||
hasThumbnail() &&
|
||||
|
||||
Reference in New Issue
Block a user