mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-10 09:00:41 +01:00
PreviewUrl: handle click
This commit is contained in:
parent
770041eceb
commit
19315fc65e
@ -1652,6 +1652,14 @@ class RoomDetailFragment @Inject constructor(
|
|||||||
roomDetailViewModel.handle(RoomDetailAction.EnterTrackingUnreadMessagesState)
|
roomDetailViewModel.handle(RoomDetailAction.EnterTrackingUnreadMessagesState)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPreviewUrlClicked(url: String) {
|
||||||
|
onUrlClicked(url, url)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPreviewUrlCloseClicked(url: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
private fun onShareActionClicked(action: EventSharedAction.Share) {
|
||||||
if (action.messageContent is MessageTextContent) {
|
if (action.messageContent is MessageTextContent) {
|
||||||
shareText(requireContext(), action.messageContent.body)
|
shareText(requireContext(), action.messageContent.body)
|
||||||
|
@ -76,7 +76,13 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
|||||||
private val backgroundHandler: Handler
|
private val backgroundHandler: Handler
|
||||||
) : EpoxyController(backgroundHandler, backgroundHandler), Timeline.Listener, EpoxyController.Interceptor {
|
) : EpoxyController(backgroundHandler, backgroundHandler), Timeline.Listener, EpoxyController.Interceptor {
|
||||||
|
|
||||||
interface Callback : BaseCallback, ReactionPillCallback, AvatarCallback, UrlClickCallback, ReadReceiptsCallback {
|
interface Callback :
|
||||||
|
BaseCallback,
|
||||||
|
ReactionPillCallback,
|
||||||
|
AvatarCallback,
|
||||||
|
UrlClickCallback,
|
||||||
|
ReadReceiptsCallback,
|
||||||
|
PreviewUrlCallback {
|
||||||
fun onLoadMore(direction: Timeline.Direction)
|
fun onLoadMore(direction: Timeline.Direction)
|
||||||
fun onEventInvisible(event: TimelineEvent)
|
fun onEventInvisible(event: TimelineEvent)
|
||||||
fun onEventVisible(event: TimelineEvent)
|
fun onEventVisible(event: TimelineEvent)
|
||||||
@ -118,6 +124,11 @@ class TimelineEventController @Inject constructor(private val dateFormatter: Vec
|
|||||||
fun onUrlLongClicked(url: String): Boolean
|
fun onUrlLongClicked(url: String): Boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface PreviewUrlCallback {
|
||||||
|
fun onPreviewUrlClicked(url: String)
|
||||||
|
fun onPreviewUrlCloseClicked(url: String)
|
||||||
|
}
|
||||||
|
|
||||||
// Map eventId to adapter position
|
// Map eventId to adapter position
|
||||||
private val adapterPositionMapping = HashMap<String, Int>()
|
private val adapterPositionMapping = HashMap<String, Int>()
|
||||||
private val modelCache = arrayListOf<CacheItemData?>()
|
private val modelCache = arrayListOf<CacheItemData?>()
|
||||||
|
@ -428,6 +428,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
.searchForPills(isFormatted)
|
.searchForPills(isFormatted)
|
||||||
.previewUrlRetriever(previewUrlRetriever)
|
.previewUrlRetriever(previewUrlRetriever)
|
||||||
.imageContentRenderer(imageContentRenderer)
|
.imageContentRenderer(imageContentRenderer)
|
||||||
|
.previewUrlCallback(callback)
|
||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
@ -535,6 +536,7 @@ class MessageItemFactory @Inject constructor(
|
|||||||
.leftGuideline(avatarSizeProvider.leftGuideline)
|
.leftGuideline(avatarSizeProvider.leftGuideline)
|
||||||
.previewUrlRetriever(previewUrlRetriever)
|
.previewUrlRetriever(previewUrlRetriever)
|
||||||
.imageContentRenderer(imageContentRenderer)
|
.imageContentRenderer(imageContentRenderer)
|
||||||
|
.previewUrlCallback(callback)
|
||||||
.attributes(attributes)
|
.attributes(attributes)
|
||||||
.highlighted(highlight)
|
.highlighted(highlight)
|
||||||
.movementMethod(createLinkMovementMethod(callback))
|
.movementMethod(createLinkMovementMethod(callback))
|
||||||
|
@ -23,6 +23,7 @@ import androidx.core.widget.TextViewCompat
|
|||||||
import com.airbnb.epoxy.EpoxyAttribute
|
import com.airbnb.epoxy.EpoxyAttribute
|
||||||
import com.airbnb.epoxy.EpoxyModelClass
|
import com.airbnb.epoxy.EpoxyModelClass
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
|
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
||||||
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
|
import im.vector.app.features.home.room.detail.timeline.tools.findPillsAndProcess
|
||||||
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
|
||||||
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlUiState
|
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlUiState
|
||||||
@ -44,6 +45,9 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
|||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var previewUrlRetriever: PreviewUrlRetriever? = null
|
var previewUrlRetriever: PreviewUrlRetriever? = null
|
||||||
|
|
||||||
|
@EpoxyAttribute
|
||||||
|
var previewUrlCallback: TimelineEventController.PreviewUrlCallback? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var imageContentRenderer: ImageContentRenderer? = null
|
var imageContentRenderer: ImageContentRenderer? = null
|
||||||
|
|
||||||
@ -53,9 +57,11 @@ abstract class MessageTextItem : AbsMessageItem<MessageTextItem.Holder>() {
|
|||||||
private val previewUrlViewUpdater = PreviewUrlViewUpdater()
|
private val previewUrlViewUpdater = PreviewUrlViewUpdater()
|
||||||
|
|
||||||
override fun bind(holder: Holder) {
|
override fun bind(holder: Holder) {
|
||||||
|
// Preview URL
|
||||||
previewUrlViewUpdater.previewUrlView = holder.previewUrlView
|
previewUrlViewUpdater.previewUrlView = holder.previewUrlView
|
||||||
previewUrlViewUpdater.imageContentRenderer = imageContentRenderer
|
previewUrlViewUpdater.imageContentRenderer = imageContentRenderer
|
||||||
previewUrlRetriever?.addListener(attributes.informationData.eventId, previewUrlViewUpdater)
|
previewUrlRetriever?.addListener(attributes.informationData.eventId, previewUrlViewUpdater)
|
||||||
|
holder.previewUrlView.delegate = previewUrlCallback
|
||||||
|
|
||||||
if (useBigFont) {
|
if (useBigFont) {
|
||||||
holder.messageView.textSize = 44F
|
holder.messageView.textSize = 44F
|
||||||
|
@ -60,7 +60,7 @@ class PreviewUrlRetriever @Inject constructor(
|
|||||||
}.fold(
|
}.fold(
|
||||||
{
|
{
|
||||||
synchronized(data) {
|
synchronized(data) {
|
||||||
updateState(eventId, PreviewUrlUiState.Data(it))
|
updateState(eventId, PreviewUrlUiState.Data(urlToRetrieve, it))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -35,5 +35,5 @@ sealed class PreviewUrlUiState {
|
|||||||
data class Error(val throwable: Throwable) : PreviewUrlUiState()
|
data class Error(val throwable: Throwable) : PreviewUrlUiState()
|
||||||
|
|
||||||
// PreviewUrl data
|
// PreviewUrl data
|
||||||
data class Data(val previewUrlData: PreviewUrlData) : PreviewUrlUiState()
|
data class Data(val url: String, val previewUrlData: PreviewUrlData) : PreviewUrlUiState()
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import butterknife.BindView
|
|||||||
import butterknife.ButterKnife
|
import butterknife.ButterKnife
|
||||||
import im.vector.app.R
|
import im.vector.app.R
|
||||||
import im.vector.app.core.extensions.setTextOrHide
|
import im.vector.app.core.extensions.setTextOrHide
|
||||||
|
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
|
||||||
import im.vector.app.features.media.ImageContentRenderer
|
import im.vector.app.features.media.ImageContentRenderer
|
||||||
import org.matrix.android.sdk.api.session.media.PreviewUrlData
|
import org.matrix.android.sdk.api.session.media.PreviewUrlData
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ class PreviewUrlView @JvmOverloads constructor(
|
|||||||
@BindView(R.id.url_preview_site)
|
@BindView(R.id.url_preview_site)
|
||||||
lateinit var siteView: TextView
|
lateinit var siteView: TextView
|
||||||
|
|
||||||
var delegate: Delegate? = null
|
var delegate: TimelineEventController.PreviewUrlCallback? = null
|
||||||
|
|
||||||
init {
|
init {
|
||||||
setupView()
|
setupView()
|
||||||
@ -85,7 +86,7 @@ class PreviewUrlView @JvmOverloads constructor(
|
|||||||
|
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
when (val finalState = state) {
|
when (val finalState = state) {
|
||||||
is PreviewUrlUiState.Data -> delegate?.onUrlClicked(finalState.previewUrlData.url)
|
is PreviewUrlUiState.Data -> delegate?.onPreviewUrlClicked(finalState.url)
|
||||||
else -> Unit
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,15 +130,4 @@ class PreviewUrlView @JvmOverloads constructor(
|
|||||||
descriptionView.isVisible = false
|
descriptionView.isVisible = false
|
||||||
siteView.isVisible = false
|
siteView.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An interface to delegate some actions to another object
|
|
||||||
*/
|
|
||||||
interface Delegate {
|
|
||||||
// TODO
|
|
||||||
fun onUrlClicked(url: String)
|
|
||||||
|
|
||||||
// TODO
|
|
||||||
// fun close()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user