Code review fixes.

This commit is contained in:
Onuray Sahin 2022-02-02 19:33:34 +03:00
parent a131d28b3e
commit c2daab4211
8 changed files with 16 additions and 14 deletions

View File

@ -66,10 +66,10 @@ data class MessageLocationContent(
fun getBestGeoUri() = locationInfo?.geoUri ?: geoUri fun getBestGeoUri() = locationInfo?.geoUri ?: geoUri
/** /**
* @return true if location asset is different than LocationAssetType.SELF * @return true if the location asset is a user location, not a generic one.
*/ */
fun isGenericLocation(): Boolean { fun isSelfLocation(): Boolean {
// Should behave like m.self if locationAsset is null // Should behave like m.self if locationAsset is null
return locationAsset != null && locationAsset.type != LocationAssetType.SELF return locationAsset?.type == null || locationAsset.type == LocationAssetType.SELF
} }
} }

View File

@ -610,14 +610,14 @@ class TimelineFragment @Inject constructor(
} }
private fun handleShowLocationPreview(locationContent: MessageLocationContent, senderId: String) { private fun handleShowLocationPreview(locationContent: MessageLocationContent, senderId: String) {
val isGenericLocation = locationContent.isGenericLocation() val isSelfLocation = locationContent.isSelfLocation()
navigator navigator
.openLocationSharing( .openLocationSharing(
context = requireContext(), context = requireContext(),
roomId = timelineArgs.roomId, roomId = timelineArgs.roomId,
mode = LocationSharingMode.PREVIEW, mode = LocationSharingMode.PREVIEW,
initialLocationData = locationContent.toLocationData(), initialLocationData = locationContent.toLocationData(),
locationOwnerId = if (isGenericLocation) null else senderId locationOwnerId = if (isSelfLocation) senderId else null
) )
} }

View File

@ -82,7 +82,7 @@ class MessageActionsEpoxyController @Inject constructor(
?.toModel<MessageLocationContent>(catchError = true) ?.toModel<MessageLocationContent>(catchError = true)
val locationUrl = locationContent?.toLocationData() val locationUrl = locationContent?.toLocationData()
?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) } ?.let { urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, 1200, 800) }
val locationOwnerId = if (locationContent?.isGenericLocation().orFalse()) null else state.informationData.matrixItem.id val locationOwnerId = if (locationContent?.isSelfLocation().orFalse()) state.informationData.matrixItem.id else null
bottomSheetMessagePreviewItem { bottomSheetMessagePreviewItem {
id("preview") id("preview")

View File

@ -219,7 +219,7 @@ class MessageItemFactory @Inject constructor(
urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, width, height) urlMapProvider.buildStaticMapUrl(it, INITIAL_MAP_ZOOM_IN_TIMELINE, width, height)
} }
val userId = if (locationContent.isGenericLocation()) null else informationData.senderId val userId = if (locationContent.isSelfLocation()) informationData.senderId else null
return MessageLocationItem_() return MessageLocationItem_()
.attributes(attributes) .attributes(attributes)

View File

@ -18,7 +18,7 @@ package im.vector.app.features.location
const val MAP_BASE_URL = "https://api.maptiler.com/maps/streets/style.json" const val MAP_BASE_URL = "https://api.maptiler.com/maps/streets/style.json"
const val STATIC_MAP_BASE_URL = "https://api.maptiler.com/maps/basic/static/" const val STATIC_MAP_BASE_URL = "https://api.maptiler.com/maps/basic/static/"
const val USER_PIN_NAME = "USER_PIN_NAME" const val DEFAULT_PIN_ID = "DEFAULT_PIN_ID"
const val INITIAL_MAP_ZOOM_IN_PREVIEW = 15.0 const val INITIAL_MAP_ZOOM_IN_PREVIEW = 15.0
const val INITIAL_MAP_ZOOM_IN_TIMELINE = 17.0 const val INITIAL_MAP_ZOOM_IN_TIMELINE = 17.0

View File

@ -121,7 +121,7 @@ class LocationPreviewFragment @Inject constructor(
MapState( MapState(
zoomOnlyOnce = true, zoomOnlyOnce = true,
pinLocationData = location, pinLocationData = location,
pinId = args.locationOwnerId ?: USER_PIN_NAME, pinId = args.locationOwnerId ?: DEFAULT_PIN_ID,
pinDrawable = pinDrawable pinDrawable = pinDrawable
) )
) )

View File

@ -42,6 +42,6 @@ data class LocationSharingViewState(
fun LocationSharingViewState.toMapState() = MapState( fun LocationSharingViewState.toMapState() = MapState(
zoomOnlyOnce = true, zoomOnlyOnce = true,
pinLocationData = lastKnownLocation, pinLocationData = lastKnownLocation,
pinId = USER_PIN_NAME, pinId = DEFAULT_PIN_ID,
pinDrawable = pinDrawable pinDrawable = pinDrawable
) )

View File

@ -17,7 +17,9 @@
package im.vector.app.features.location package im.vector.app.features.location
import org.amshove.kluent.shouldBeEqualTo import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldBeFalse
import org.amshove.kluent.shouldBeNull import org.amshove.kluent.shouldBeNull
import org.amshove.kluent.shouldBeTrue
import org.junit.Test import org.junit.Test
import org.matrix.android.sdk.api.session.room.model.message.LocationAsset import org.matrix.android.sdk.api.session.room.model.message.LocationAsset
import org.matrix.android.sdk.api.session.room.model.message.LocationAssetType import org.matrix.android.sdk.api.session.room.model.message.LocationAssetType
@ -62,14 +64,14 @@ class LocationDataTest {
} }
@Test @Test
fun genericLocationTest() { fun selfLocationTest() {
val contentWithNullAsset = MessageLocationContent(body = "", geoUri = "", locationAsset = null) val contentWithNullAsset = MessageLocationContent(body = "", geoUri = "", locationAsset = null)
contentWithNullAsset.isGenericLocation() shouldBeEqualTo(false) contentWithNullAsset.isSelfLocation().shouldBeTrue()
val contentWithNullAssetType = MessageLocationContent(body = "", geoUri = "", locationAsset = LocationAsset(type = null)) val contentWithNullAssetType = MessageLocationContent(body = "", geoUri = "", locationAsset = LocationAsset(type = null))
contentWithNullAssetType.isGenericLocation() shouldBeEqualTo(true) contentWithNullAssetType.isSelfLocation().shouldBeTrue()
val contentWithSelfAssetType = MessageLocationContent(body = "", geoUri = "", locationAsset = LocationAsset(type = LocationAssetType.SELF)) val contentWithSelfAssetType = MessageLocationContent(body = "", geoUri = "", locationAsset = LocationAsset(type = LocationAssetType.SELF))
contentWithSelfAssetType.isGenericLocation() shouldBeEqualTo(false) contentWithSelfAssetType.isSelfLocation().shouldBeTrue()
} }
} }