-
Notifications
You must be signed in to change notification settings - Fork 748
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 3 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 |
---|---|---|
|
@@ -27,12 +27,14 @@ import im.vector.app.core.platform.EmptyViewEvents | |
import im.vector.app.core.platform.VectorViewModel | ||
import im.vector.app.core.platform.VectorViewModelAction | ||
import im.vector.app.features.VectorFeatures | ||
import im.vector.app.features.location.UrlMapProvider | ||
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. This import should be removed. |
||
import im.vector.app.features.settings.VectorPreferences | ||
|
||
class AttachmentTypeSelectorViewModel @AssistedInject constructor( | ||
@Assisted initialState: AttachmentTypeSelectorViewState, | ||
private val vectorFeatures: VectorFeatures, | ||
private val vectorPreferences: VectorPreferences, | ||
private val urlMapProvider: UrlMapProvider | ||
artkoenig marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) : VectorViewModel<AttachmentTypeSelectorViewState, AttachmentTypeSelectorAction, EmptyViewEvents>(initialState) { | ||
@AssistedFactory | ||
interface Factory : MavericksAssistedViewModelFactory<AttachmentTypeSelectorViewModel, AttachmentTypeSelectorViewState> { | ||
|
@@ -48,7 +50,7 @@ class AttachmentTypeSelectorViewModel @AssistedInject constructor( | |
init { | ||
setState { | ||
copy( | ||
isLocationVisible = vectorFeatures.isLocationSharingEnabled(), | ||
isLocationVisible = vectorFeatures.isLocationSharingEnabled() && urlMapProvider.isMapConfigurationAvailable(), | ||
isVoiceBroadcastVisible = vectorFeatures.isVoiceBroadcastEnabled(), | ||
isTextFormattingEnabled = vectorPreferences.isTextFormattingEnabled(), | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,35 +16,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.epoxy.ClickListener | ||
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.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 | ||
|
@@ -65,61 +64,52 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>( | |
} | ||
|
||
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 { | ||
holder.staticMapView.updateLayoutParams { | ||
width = mapWidth | ||
height = mapHeight | ||
} | ||
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) | ||
holder.staticMapView.addOnDidFailLoadingMapListener { | ||
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. Some clean up about the map should be added in the 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. done |
||
holder.staticMapLoadingErrorView.isVisible = true | ||
val mapErrorViewState = MapLoadingErrorViewState(imageCornerTransformation) | ||
holder.staticMapLoadingErrorView.render(mapErrorViewState) | ||
} | ||
|
||
holder.staticMapView.addOnDidFinishLoadingMapListener { | ||
locationPinProvider?.create(locationUserId) { pinDrawable -> | ||
holder.staticMapPinImageView.setImageDrawable(pinDrawable) | ||
} | ||
holder.staticMapLoadingErrorView.isVisible = false | ||
} | ||
|
||
holder.staticMapView.clipToOutline = true | ||
holder.staticMapView.getMapAsync { mapbox -> | ||
mapbox.setStyle(mapStyleUrl) | ||
locationData?.let { | ||
mapbox.zoomToLocation(it, animate = false) | ||
} | ||
mapbox.uiSettings.setAllGesturesEnabled(false) | ||
mapbox.addOnMapClickListener { | ||
attributes.itemClickListener?.invoke(holder.staticMapView) | ||
true | ||
} | ||
mapbox.addOnMapLongClickListener { | ||
attributes.itemLongClickListener?.onLongClick(holder.staticMapView) | ||
true | ||
} | ||
} | ||
} | ||
|
||
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) | ||
} | ||
} |
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.
Here I think the zoom level may not be correct. What we want in the timeline is
INITIAL_MAP_ZOOM_IN_TIMELINE
. AndzoomToLocation
is not using this value but another one. We may have to change the extension method to pass the required zoom level.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.
done