-
-
Notifications
You must be signed in to change notification settings - Fork 6k
/
StoryTextLoader.kt
69 lines (57 loc) · 2.26 KB
/
StoryTextLoader.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.thoughtcrime.securesms.stories.viewer.post
import android.view.LayoutInflater
import android.view.View
import android.widget.TextView
import org.signal.core.util.DimensionUnit
import org.thoughtcrime.securesms.R
import org.thoughtcrime.securesms.linkpreview.LinkPreview
import org.thoughtcrime.securesms.stories.StoryTextPostView
import org.thoughtcrime.securesms.util.CommunicationActions
import org.thoughtcrime.securesms.util.FragmentDialogs.displayInDialogAboveAnchor
/**
* Render logic for story text posts
*/
class StoryTextLoader(
private val fragment: StoryPostFragment,
private val text: StoryTextPostView,
private val state: StoryPostState.TextPost,
private val callback: StoryPostFragment.Callback
) {
fun load() {
text.bindFromStoryTextPost(state.storyTextPostId, state.storyTextPost!!, state.bodyRanges)
text.bindLinkPreview(state.linkPreview, state.storyTextPost.body.isBlank())
text.postAdjustLinkPreviewTranslationY()
if (state.linkPreview != null) {
text.setLinkPreviewClickListener {
showLinkPreviewTooltip(it, state.linkPreview)
}
} else {
text.setLinkPreviewClickListener(null)
}
if (state.typeface != null) {
text.setTypeface(state.typeface)
}
if (state.typeface != null && state.loadState == StoryPostState.LoadState.LOADED) {
callback.onContentReady()
}
}
private fun showLinkPreviewTooltip(view: View, linkPreview: LinkPreview) {
callback.setIsDisplayingLinkPreviewTooltip(true)
val contentView = LayoutInflater.from(fragment.requireContext()).inflate(R.layout.stories_link_popup, null, false)
contentView.findViewById<TextView>(R.id.url).text = linkPreview.url
contentView.setOnClickListener {
CommunicationActions.openBrowserLink(fragment.requireContext(), linkPreview.url)
}
contentView.measure(
View.MeasureSpec.makeMeasureSpec(DimensionUnit.DP.toPixels(275f).toInt(), View.MeasureSpec.EXACTLY),
0
)
contentView.layout(0, 0, contentView.measuredWidth, contentView.measuredHeight)
fragment.displayInDialogAboveAnchor(view, contentView, windowDim = 0f, onDismiss = {
val activity = fragment.activity
if (activity != null) {
callback.setIsDisplayingLinkPreviewTooltip(false)
}
})
}
}