diff --git a/changelog.d/5143.bugfix b/changelog.d/5143.bugfix new file mode 100644 index 0000000000..ba8f42b6cb --- /dev/null +++ b/changelog.d/5143.bugfix @@ -0,0 +1 @@ +Fix location rendering in timeline if map cannot be loaded \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt index d60f2b5d05..5511fc3f8c 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/item/MessageLocationItem.kt @@ -16,11 +16,19 @@ package im.vector.app.features.home.room.detail.timeline.item +import android.graphics.drawable.Drawable import android.widget.ImageView +import android.widget.TextView +import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams import com.airbnb.epoxy.EpoxyAttribute import com.airbnb.epoxy.EpoxyModelClass +import com.bumptech.glide.load.DataSource +import com.bumptech.glide.load.engine.GlideException import com.bumptech.glide.load.resource.bitmap.RoundedCorners +import com.bumptech.glide.request.RequestListener +import com.bumptech.glide.request.RequestOptions +import com.bumptech.glide.request.target.Target import im.vector.app.R import im.vector.app.core.glide.GlideApp import im.vector.app.core.utils.DimensionConverter @@ -63,14 +71,26 @@ abstract class MessageLocationItem : AbsMessageItem( } GlideApp.with(holder.staticMapImageView) .load(location) + .apply(RequestOptions.centerCropTransform()) + .listener(object : RequestListener { + override fun onLoadFailed(e: GlideException?, model: Any?, target: Target?, isFirstResource: Boolean): Boolean { + holder.staticMapPinImageView.setImageResource(R.drawable.ic_location_pin_failed) + holder.staticMapErrorTextView.isVisible = true + return false + } + + override fun onResourceReady(resource: Drawable?, model: Any?, target: Target?, dataSource: DataSource?, isFirstResource: Boolean): Boolean { + locationPinProvider?.create(userId) { pinDrawable -> + GlideApp.with(holder.staticMapPinImageView) + .load(pinDrawable) + .into(holder.staticMapPinImageView) + } + holder.staticMapErrorTextView.isVisible = false + return false + } + }) .transform(imageCornerTransformation) .into(holder.staticMapImageView) - - locationPinProvider?.create(userId) { pinDrawable -> - GlideApp.with(holder.staticMapPinImageView) - .load(pinDrawable) - .into(holder.staticMapPinImageView) - } } override fun getViewStubId() = STUB_ID @@ -78,6 +98,7 @@ abstract class MessageLocationItem : AbsMessageItem( class Holder : AbsMessageItem.Holder(STUB_ID) { val staticMapImageView by bind(R.id.staticMapImageView) val staticMapPinImageView by bind(R.id.staticMapPinImageView) + val staticMapErrorTextView by bind(R.id.staticMapErrorTextView) } companion object { diff --git a/vector/src/main/res/drawable/ic_location_pin_failed.xml b/vector/src/main/res/drawable/ic_location_pin_failed.xml new file mode 100644 index 0000000000..250d048836 --- /dev/null +++ b/vector/src/main/res/drawable/ic_location_pin_failed.xml @@ -0,0 +1,9 @@ + + + diff --git a/vector/src/main/res/layout/item_timeline_event_location_stub.xml b/vector/src/main/res/layout/item_timeline_event_location_stub.xml index 77c7b932ce..f735c2b00e 100644 --- a/vector/src/main/res/layout/item_timeline_event_location_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_location_stub.xml @@ -1,5 +1,4 @@ - + + diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml index aa4964698b..ec9310cd36 100644 --- a/vector/src/main/res/values/strings.xml +++ b/vector/src/main/res/values/strings.xml @@ -3767,6 +3767,7 @@ Enable location sharing Once enabled you will be able to send your location to any room Render user locations in the timeline + Failed to load map Show Message bubbles