mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-02 20:26:47 +01:00
Avoid error log when the Event is not a LocationEvent
This commit is contained in:
parent
c849cc5c5d
commit
24915591f2
@ -33,7 +33,7 @@ import im.vector.app.core.extensions.setTextOrHide
|
|||||||
import im.vector.app.core.glide.GlideApp
|
import im.vector.app.core.glide.GlideApp
|
||||||
import im.vector.app.features.displayname.getBestName
|
import im.vector.app.features.displayname.getBestName
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
|
import im.vector.app.features.home.room.detail.timeline.action.LocationUiData
|
||||||
import im.vector.app.features.home.room.detail.timeline.item.BindingOptions
|
import im.vector.app.features.home.room.detail.timeline.item.BindingOptions
|
||||||
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.media.ImageContentRenderer
|
import im.vector.app.features.media.ImageContentRenderer
|
||||||
@ -71,13 +71,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
|
|||||||
var time: String? = null
|
var time: String? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var locationUrl: String? = null
|
var locationUiData: LocationUiData? = null
|
||||||
|
|
||||||
@EpoxyAttribute
|
|
||||||
var locationPinProvider: LocationPinProvider? = null
|
|
||||||
|
|
||||||
@EpoxyAttribute
|
|
||||||
var locationOwnerId: String? = null
|
|
||||||
|
|
||||||
@EpoxyAttribute
|
@EpoxyAttribute
|
||||||
var movementMethod: MovementMethod? = null
|
var movementMethod: MovementMethod? = null
|
||||||
@ -101,18 +95,15 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
|
|||||||
body.charSequence.findPillsAndProcess(coroutineScope) { it.bind(holder.body) }
|
body.charSequence.findPillsAndProcess(coroutineScope) { it.bind(holder.body) }
|
||||||
holder.timestamp.setTextOrHide(time)
|
holder.timestamp.setTextOrHide(time)
|
||||||
|
|
||||||
if (locationUrl == null) {
|
holder.body.isVisible = locationUiData == null
|
||||||
holder.body.isVisible = true
|
holder.mapViewContainer.isVisible = locationUiData != null
|
||||||
holder.mapViewContainer.isVisible = false
|
locationUiData?.let { safeLocationUiData ->
|
||||||
} else {
|
|
||||||
holder.body.isVisible = false
|
|
||||||
holder.mapViewContainer.isVisible = true
|
|
||||||
GlideApp.with(holder.staticMapImageView)
|
GlideApp.with(holder.staticMapImageView)
|
||||||
.load(locationUrl)
|
.load(safeLocationUiData.locationUrl)
|
||||||
.apply(RequestOptions.centerCropTransform())
|
.apply(RequestOptions.centerCropTransform())
|
||||||
.into(holder.staticMapImageView)
|
.into(holder.staticMapImageView)
|
||||||
|
|
||||||
locationPinProvider?.create(locationOwnerId) { pinDrawable ->
|
safeLocationUiData.locationPinProvider.create(safeLocationUiData.locationOwnerId) { pinDrawable ->
|
||||||
GlideApp.with(holder.staticMapPinImageView)
|
GlideApp.with(holder.staticMapPinImageView)
|
||||||
.load(pinDrawable)
|
.load(pinDrawable)
|
||||||
.into(holder.staticMapPinImageView)
|
.into(holder.staticMapPinImageView)
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.home.room.detail.timeline.action
|
||||||
|
|
||||||
|
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data used to display Location data in the message bottom sheet
|
||||||
|
*/
|
||||||
|
data class LocationUiData(
|
||||||
|
val locationUrl: String,
|
||||||
|
val locationOwnerId: String?,
|
||||||
|
val locationPinProvider: LocationPinProvider,
|
||||||
|
)
|
@ -49,7 +49,9 @@ import org.matrix.android.sdk.api.extensions.orFalse
|
|||||||
import org.matrix.android.sdk.api.extensions.orTrue
|
import org.matrix.android.sdk.api.extensions.orTrue
|
||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.message.MessageContent
|
||||||
import org.matrix.android.sdk.api.session.room.model.message.MessageLocationContent
|
import org.matrix.android.sdk.api.session.room.model.message.MessageLocationContent
|
||||||
|
import org.matrix.android.sdk.api.session.room.model.message.MessageType
|
||||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -80,12 +82,7 @@ class MessageActionsEpoxyController @Inject constructor(
|
|||||||
val formattedDate = dateFormatter.format(date, DateFormatKind.MESSAGE_DETAIL)
|
val formattedDate = dateFormatter.format(date, DateFormatKind.MESSAGE_DETAIL)
|
||||||
val body = state.messageBody.linkify(host.listener)
|
val body = state.messageBody.linkify(host.listener)
|
||||||
val bindingOptions = spanUtils.getBindingOptions(body)
|
val bindingOptions = spanUtils.getBindingOptions(body)
|
||||||
|
val locationUiData = buildLocationUiData(state)
|
||||||
val locationContent = state.timelineEvent()?.root?.getClearContent()
|
|
||||||
?.toModel<MessageLocationContent>(catchError = true)
|
|
||||||
val locationUrl = locationContent?.toLocationData()
|
|
||||||
?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) }
|
|
||||||
val locationOwnerId = if (locationContent?.isSelfLocation().orTrue()) state.informationData.matrixItem.id else null
|
|
||||||
|
|
||||||
bottomSheetMessagePreviewItem {
|
bottomSheetMessagePreviewItem {
|
||||||
id("preview")
|
id("preview")
|
||||||
@ -99,9 +96,7 @@ class MessageActionsEpoxyController @Inject constructor(
|
|||||||
body(body.toEpoxyCharSequence())
|
body(body.toEpoxyCharSequence())
|
||||||
bodyDetails(host.eventDetailsFormatter.format(state.timelineEvent()?.root)?.toEpoxyCharSequence())
|
bodyDetails(host.eventDetailsFormatter.format(state.timelineEvent()?.root)?.toEpoxyCharSequence())
|
||||||
time(formattedDate)
|
time(formattedDate)
|
||||||
locationUrl(locationUrl)
|
locationUiData(locationUiData)
|
||||||
locationPinProvider(host.locationPinProvider)
|
|
||||||
locationOwnerId(locationOwnerId)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send state
|
// Send state
|
||||||
@ -222,6 +217,24 @@ class MessageActionsEpoxyController @Inject constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun buildLocationUiData(state: MessageActionState): LocationUiData? {
|
||||||
|
val clearContent = state.timelineEvent()?.root?.getClearContent()
|
||||||
|
val isLocationEvent = clearContent?.get(MessageContent.MSG_TYPE_JSON_KEY) == MessageType.MSGTYPE_LOCATION
|
||||||
|
if (!isLocationEvent) return null
|
||||||
|
|
||||||
|
val locationContent = clearContent.toModel<MessageLocationContent>(catchError = true)
|
||||||
|
val locationUrl = locationContent?.toLocationData()
|
||||||
|
?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) }
|
||||||
|
?: return null
|
||||||
|
val locationOwnerId = if (locationContent.isSelfLocation().orTrue()) state.informationData.matrixItem.id else null
|
||||||
|
|
||||||
|
return LocationUiData(
|
||||||
|
locationUrl = locationUrl,
|
||||||
|
locationOwnerId = locationOwnerId,
|
||||||
|
locationPinProvider = locationPinProvider,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
private fun EventSharedAction.shouldShowBetaLabel(): Boolean =
|
private fun EventSharedAction.shouldShowBetaLabel(): Boolean =
|
||||||
this is EventSharedAction.ReplyInThread && !vectorPreferences.areThreadMessagesEnabled()
|
this is EventSharedAction.ReplyInThread && !vectorPreferences.areThreadMessagesEnabled()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user