mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
Code review fixes.
This commit is contained in:
parent
a131d28b3e
commit
c2daab4211
8 changed files with 16 additions and 14 deletions
|
@ -66,10 +66,10 @@ data class MessageLocationContent(
|
|||
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
|
||||
return locationAsset != null && locationAsset.type != LocationAssetType.SELF
|
||||
return locationAsset?.type == null || locationAsset.type == LocationAssetType.SELF
|
||||
}
|
||||
}
|
||||
|
|
|
@ -610,14 +610,14 @@ class TimelineFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun handleShowLocationPreview(locationContent: MessageLocationContent, senderId: String) {
|
||||
val isGenericLocation = locationContent.isGenericLocation()
|
||||
val isSelfLocation = locationContent.isSelfLocation()
|
||||
navigator
|
||||
.openLocationSharing(
|
||||
context = requireContext(),
|
||||
roomId = timelineArgs.roomId,
|
||||
mode = LocationSharingMode.PREVIEW,
|
||||
initialLocationData = locationContent.toLocationData(),
|
||||
locationOwnerId = if (isGenericLocation) null else senderId
|
||||
locationOwnerId = if (isSelfLocation) senderId else null
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ class MessageActionsEpoxyController @Inject constructor(
|
|||
?.toModel<MessageLocationContent>(catchError = true)
|
||||
val locationUrl = locationContent?.toLocationData()
|
||||
?.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 {
|
||||
id("preview")
|
||||
|
|
|
@ -219,7 +219,7 @@ class MessageItemFactory @Inject constructor(
|
|||
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_()
|
||||
.attributes(attributes)
|
||||
|
|
|
@ -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 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_TIMELINE = 17.0
|
||||
|
|
|
@ -121,7 +121,7 @@ class LocationPreviewFragment @Inject constructor(
|
|||
MapState(
|
||||
zoomOnlyOnce = true,
|
||||
pinLocationData = location,
|
||||
pinId = args.locationOwnerId ?: USER_PIN_NAME,
|
||||
pinId = args.locationOwnerId ?: DEFAULT_PIN_ID,
|
||||
pinDrawable = pinDrawable
|
||||
)
|
||||
)
|
||||
|
|
|
@ -42,6 +42,6 @@ data class LocationSharingViewState(
|
|||
fun LocationSharingViewState.toMapState() = MapState(
|
||||
zoomOnlyOnce = true,
|
||||
pinLocationData = lastKnownLocation,
|
||||
pinId = USER_PIN_NAME,
|
||||
pinId = DEFAULT_PIN_ID,
|
||||
pinDrawable = pinDrawable
|
||||
)
|
||||
|
|
|
@ -17,7 +17,9 @@
|
|||
package im.vector.app.features.location
|
||||
|
||||
import org.amshove.kluent.shouldBeEqualTo
|
||||
import org.amshove.kluent.shouldBeFalse
|
||||
import org.amshove.kluent.shouldBeNull
|
||||
import org.amshove.kluent.shouldBeTrue
|
||||
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.LocationAssetType
|
||||
|
@ -62,14 +64,14 @@ class LocationDataTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun genericLocationTest() {
|
||||
fun selfLocationTest() {
|
||||
val contentWithNullAsset = MessageLocationContent(body = "", geoUri = "", locationAsset = null)
|
||||
contentWithNullAsset.isGenericLocation() shouldBeEqualTo(false)
|
||||
contentWithNullAsset.isSelfLocation().shouldBeTrue()
|
||||
|
||||
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))
|
||||
contentWithSelfAssetType.isGenericLocation() shouldBeEqualTo(false)
|
||||
contentWithSelfAssetType.isSelfLocation().shouldBeTrue()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue