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.features.displayname.getBestName
|
||||
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.tools.findPillsAndProcess
|
||||
import im.vector.app.features.media.ImageContentRenderer
|
||||
@ -71,13 +71,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
|
||||
var time: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var locationUrl: String? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var locationPinProvider: LocationPinProvider? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var locationOwnerId: String? = null
|
||||
var locationUiData: LocationUiData? = null
|
||||
|
||||
@EpoxyAttribute
|
||||
var movementMethod: MovementMethod? = null
|
||||
@ -101,18 +95,15 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
|
||||
body.charSequence.findPillsAndProcess(coroutineScope) { it.bind(holder.body) }
|
||||
holder.timestamp.setTextOrHide(time)
|
||||
|
||||
if (locationUrl == null) {
|
||||
holder.body.isVisible = true
|
||||
holder.mapViewContainer.isVisible = false
|
||||
} else {
|
||||
holder.body.isVisible = false
|
||||
holder.mapViewContainer.isVisible = true
|
||||
holder.body.isVisible = locationUiData == null
|
||||
holder.mapViewContainer.isVisible = locationUiData != null
|
||||
locationUiData?.let { safeLocationUiData ->
|
||||
GlideApp.with(holder.staticMapImageView)
|
||||
.load(locationUrl)
|
||||
.load(safeLocationUiData.locationUrl)
|
||||
.apply(RequestOptions.centerCropTransform())
|
||||
.into(holder.staticMapImageView)
|
||||
|
||||
locationPinProvider?.create(locationOwnerId) { pinDrawable ->
|
||||
safeLocationUiData.locationPinProvider.create(safeLocationUiData.locationOwnerId) { pinDrawable ->
|
||||
GlideApp.with(holder.staticMapPinImageView)
|
||||
.load(pinDrawable)
|
||||
.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.failure.Failure
|
||||
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.MessageType
|
||||
import org.matrix.android.sdk.api.session.room.send.SendState
|
||||
import javax.inject.Inject
|
||||
|
||||
@ -80,12 +82,7 @@ class MessageActionsEpoxyController @Inject constructor(
|
||||
val formattedDate = dateFormatter.format(date, DateFormatKind.MESSAGE_DETAIL)
|
||||
val body = state.messageBody.linkify(host.listener)
|
||||
val bindingOptions = spanUtils.getBindingOptions(body)
|
||||
|
||||
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
|
||||
val locationUiData = buildLocationUiData(state)
|
||||
|
||||
bottomSheetMessagePreviewItem {
|
||||
id("preview")
|
||||
@ -99,9 +96,7 @@ class MessageActionsEpoxyController @Inject constructor(
|
||||
body(body.toEpoxyCharSequence())
|
||||
bodyDetails(host.eventDetailsFormatter.format(state.timelineEvent()?.root)?.toEpoxyCharSequence())
|
||||
time(formattedDate)
|
||||
locationUrl(locationUrl)
|
||||
locationPinProvider(host.locationPinProvider)
|
||||
locationOwnerId(locationOwnerId)
|
||||
locationUiData(locationUiData)
|
||||
}
|
||||
|
||||
// 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 =
|
||||
this is EventSharedAction.ReplyInThread && !vectorPreferences.areThreadMessagesEnabled()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user