From 6e1911e686a402c8503b0377bbda3bbd65aee4dc Mon Sep 17 00:00:00 2001 From: Onuray Sahin Date: Tue, 28 Dec 2021 17:04:51 +0300 Subject: [PATCH] Lint fixes. --- .../timeline/factory/MessageItemFactory.kt | 14 ++++++++- .../timeline/item/MessageLocationItem.kt | 29 +++++++++++-------- .../app/features/location/LocationTracker.kt | 3 +- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt index 607e4c1252..e293b1ecbd 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/timeline/factory/MessageItemFactory.kt @@ -33,6 +33,7 @@ import im.vector.app.core.resources.ColorProvider import im.vector.app.core.resources.StringProvider import im.vector.app.core.utils.DimensionConverter import im.vector.app.core.utils.containsOnlyEmojis +import im.vector.app.features.home.room.detail.RoomDetailAction import im.vector.app.features.home.room.detail.timeline.TimelineEventController import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder @@ -71,6 +72,7 @@ import im.vector.app.features.html.PillsPostProcessor import im.vector.app.features.html.SpanUtils import im.vector.app.features.html.VectorHtmlCompressor import im.vector.app.features.location.LocationData +import im.vector.app.features.location.VectorMapView import im.vector.app.features.media.ImageContentRenderer import im.vector.app.features.media.VideoContentRenderer import me.gujun.android.span.span @@ -188,6 +190,16 @@ class MessageItemFactory @Inject constructor( val geoUri = locationContent.locationInfo?.geoUri ?: locationContent.geoUri val locationData = LocationData.create(geoUri) + val mapCallback: MessageLocationItem.Callback = object: MessageLocationItem.Callback { + override fun onMapReady(mapView: VectorMapView) { + mapView.onClick { + locationData?.let { + callback?.onTimelineItemAction(RoomDetailAction.ShowLocation(it, informationData.senderId)) + } + } + } + } + return MessageLocationItem_() .attributes(attributes) .locationData(locationData) @@ -195,7 +207,7 @@ class MessageItemFactory @Inject constructor( .locationPinProvider(locationPinProvider) .highlighted(highlight) .leftGuideline(avatarSizeProvider.leftGuideline) - .callback(callback) + .callback(mapCallback) } private fun buildPollItem(pollContent: MessagePollContent, 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 d4995d3fad..2d65fd3131 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 @@ -27,12 +27,17 @@ import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvid import im.vector.app.features.location.LocationData import im.vector.app.features.location.MapTilerMapView import im.vector.app.features.location.VectorMapListener +import im.vector.app.features.location.VectorMapView @EpoxyModelClass(layout = R.layout.item_timeline_event_base) abstract class MessageLocationItem : AbsMessageItem() { + interface Callback { + fun onMapReady(mapView: VectorMapView) + } + @EpoxyAttribute - var callback: TimelineEventController.Callback? = null + var callback: Callback? = null @EpoxyAttribute var locationData: LocationData? = null @@ -50,20 +55,20 @@ abstract class MessageLocationItem : AbsMessageItem( val location = locationData ?: return val locationOwnerId = userId ?: return - holder.mapView.initialize(object : VectorMapListener { - override fun onMapReady() { - holder.mapView.zoomToLocation(location.latitude, location.longitude, INITIAL_ZOOM) + holder.mapView.apply { + initialize(object : VectorMapListener { + override fun onMapReady() { + zoomToLocation(location.latitude, location.longitude, INITIAL_ZOOM) - locationPinProvider?.create(locationOwnerId) { pinDrawable -> - holder.mapView.addPinToMap(locationOwnerId, pinDrawable) - holder.mapView.updatePinLocation(locationOwnerId, location.latitude, location.longitude) - } + locationPinProvider?.create(locationOwnerId) { pinDrawable -> + addPinToMap(locationOwnerId, pinDrawable) + updatePinLocation(locationOwnerId, location.latitude, location.longitude) + } - holder.mapView.onClick { - callback?.onTimelineItemAction(RoomDetailAction.ShowLocation(location, locationOwnerId)) + callback?.onMapReady(this@apply) } - } - }) + }) + } } override fun getViewType() = STUB_ID diff --git a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt index 6e55735f9b..48692ef216 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationTracker.kt @@ -24,6 +24,7 @@ import android.location.LocationManager import androidx.annotation.RequiresPermission import timber.log.Timber import javax.inject.Inject +import androidx.core.content.getSystemService class LocationTracker @Inject constructor( private val context: Context) : LocationListener { @@ -36,7 +37,7 @@ class LocationTracker @Inject constructor( var callback: Callback? = null fun start() { - val locationManager = context.getSystemService(Context.LOCATION_SERVICE) as? LocationManager + val locationManager = context.getSystemService() locationManager?.let { val isGpsEnabled = it.isProviderEnabled(LocationManager.GPS_PROVIDER)