-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactored location sharing timeline items to use the mapserver configured by the wellknown file #7852
base: develop
Are you sure you want to change the base?
Refactored location sharing timeline items to use the mapserver configured by the wellknown file #7852
Changes from all commits
b7a68ed
0f3e1cd
2bb6cc8
dd976f4
8f2aa1e
96780ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Refactored location sharing timeline items to use the mapserver configured by the wellknown file |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
/* | ||
* Copyright (c) 2021 New Vector Ltd | ||
* Copyright (c) 2022 BWI GmbH | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are there these changes of copyrights? I am not entirely sure is is allowed to be changed to something else than There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like @artkoenig has added here the copyright notice to show that copyright goes to BWI GmbH. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not an expert in this area but I know there has been irritation about this topic recently. So just to double check that we're doing the correct thing here: Has this particular question been confirmed with legal? |
||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -16,35 +17,34 @@ | |
|
||
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.annotation.IdRes | ||
import androidx.annotation.LayoutRes | ||
import androidx.core.view.isVisible | ||
import androidx.core.view.updateLayoutParams | ||
import com.airbnb.epoxy.EpoxyAttribute | ||
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 com.mapbox.mapboxsdk.maps.MapView | ||
import im.vector.app.R | ||
import im.vector.app.core.glide.GlideApp | ||
import im.vector.app.core.utils.DimensionConverter | ||
import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider | ||
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout | ||
import im.vector.app.features.home.room.detail.timeline.style.granularRoundedCorners | ||
import im.vector.app.features.location.INITIAL_MAP_ZOOM_IN_TIMELINE | ||
import im.vector.app.features.location.LocationData | ||
import im.vector.app.features.location.MapLoadingErrorView | ||
import im.vector.app.features.location.MapLoadingErrorViewState | ||
import im.vector.app.features.location.zoomToLocation | ||
|
||
abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>( | ||
@LayoutRes layoutId: Int = R.layout.item_timeline_event_base | ||
) : AbsMessageItem<H>(layoutId) { | ||
|
||
@EpoxyAttribute | ||
var locationUrl: String? = null | ||
var locationData: LocationData? = null | ||
|
||
@EpoxyAttribute | ||
var mapStyleUrl: String? = null | ||
|
||
@EpoxyAttribute | ||
var locationUserId: String? = null | ||
|
@@ -64,62 +64,65 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>( | |
bindMap(holder) | ||
} | ||
|
||
override fun onViewAttachedToWindow(holder: H) { | ||
super.onViewAttachedToWindow(holder) | ||
holder.staticMapView.onStart() | ||
} | ||
|
||
override fun onViewDetachedFromWindow(holder: H) { | ||
super.onViewDetachedFromWindow(holder) | ||
holder.staticMapView.onStop() | ||
} | ||
|
||
private fun bindMap(holder: Holder) { | ||
val location = locationUrl ?: return | ||
val messageLayout = attributes.informationData.messageLayout | ||
val imageCornerTransformation = if (messageLayout is TimelineMessageLayout.Bubble) { | ||
messageLayout.cornersRadius.granularRoundedCorners() | ||
} else { | ||
val dimensionConverter = DimensionConverter(holder.view.resources) | ||
RoundedCorners(dimensionConverter.dpToPx(8)) | ||
} | ||
holder.staticMapImageView.updateLayoutParams { | ||
width = mapWidth | ||
height = mapHeight | ||
|
||
holder.staticMapView.apply { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a general practice in the project, we try to avoid using apply as much as possible as it leads sometimes to strange bugs since the scope of |
||
updateLayoutParams { | ||
width = mapWidth | ||
height = mapHeight | ||
} | ||
addOnDidFailLoadingMapListener { | ||
holder.staticMapLoadingErrorView.isVisible = true | ||
val mapErrorViewState = MapLoadingErrorViewState(imageCornerTransformation) | ||
holder.staticMapLoadingErrorView.render(mapErrorViewState) | ||
} | ||
|
||
addOnDidFinishLoadingMapListener { | ||
locationPinProvider?.create(locationUserId) { pinDrawable -> | ||
holder.staticMapPinImageView.setImageDrawable(pinDrawable) | ||
} | ||
holder.staticMapLoadingErrorView.isVisible = false | ||
} | ||
|
||
clipToOutline = true | ||
getMapAsync { mapbox -> | ||
mapbox.setStyle(mapStyleUrl) | ||
locationData?.let { | ||
mapbox.zoomToLocation(it, false, INITIAL_MAP_ZOOM_IN_TIMELINE) | ||
} | ||
mapbox.uiSettings.setAllGesturesEnabled(false) | ||
mapbox.addOnMapClickListener { | ||
attributes.itemClickListener?.invoke(holder.staticMapView) | ||
true | ||
} | ||
mapbox.addOnMapLongClickListener { | ||
attributes.itemLongClickListener?.onLongClick(holder.staticMapView) | ||
true | ||
} | ||
} | ||
} | ||
GlideApp.with(holder.staticMapImageView) | ||
.load(location) | ||
.apply(RequestOptions.centerCropTransform()) | ||
.placeholder(holder.staticMapImageView.drawable) | ||
.listener(object : RequestListener<Drawable> { | ||
override fun onLoadFailed( | ||
e: GlideException?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
holder.staticMapPinImageView.setImageDrawable(null) | ||
holder.staticMapLoadingErrorView.isVisible = true | ||
val mapErrorViewState = MapLoadingErrorViewState(imageCornerTransformation) | ||
holder.staticMapLoadingErrorView.render(mapErrorViewState) | ||
holder.staticMapCopyrightTextView.isVisible = false | ||
return false | ||
} | ||
|
||
override fun onResourceReady( | ||
resource: Drawable?, | ||
model: Any?, | ||
target: Target<Drawable>?, | ||
dataSource: DataSource?, | ||
isFirstResource: Boolean | ||
): Boolean { | ||
locationPinProvider?.create(locationUserId) { pinDrawable -> | ||
// we are not using Glide since it does not display it correctly when there is no user photo | ||
holder.staticMapPinImageView.setImageDrawable(pinDrawable) | ||
} | ||
holder.staticMapLoadingErrorView.isVisible = false | ||
holder.staticMapCopyrightTextView.isVisible = true | ||
return false | ||
} | ||
}) | ||
.transform(imageCornerTransformation) | ||
.into(holder.staticMapImageView) | ||
} | ||
|
||
abstract class Holder(@IdRes stubId: Int) : AbsMessageItem.Holder(stubId) { | ||
val staticMapImageView by bind<ImageView>(R.id.staticMapImageView) | ||
val staticMapView by bind<MapView>(R.id.staticMapView) | ||
val staticMapPinImageView by bind<ImageView>(R.id.staticMapPinImageView) | ||
val staticMapLoadingErrorView by bind<MapLoadingErrorView>(R.id.staticMapLoadingError) | ||
val staticMapCopyrightTextView by bind<TextView>(R.id.staticMapCopyrightTextView) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ package im.vector.app.features.location | |
|
||
data class LocationSharingConfig( | ||
val mapTilerKey: String, | ||
val isMapTilerFallbackEnabled: Boolean | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a trailing comma here? |
||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import should be removed.