Skip to content

Commit

Permalink
Fix lint and PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yostyle committed Mar 27, 2024
1 parent b58c476 commit 83b67ff
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 25 deletions.
2 changes: 1 addition & 1 deletion library/ui-strings/src/main/res/values/donottranslate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
<string name="command_description_crash_application" translatable="false">Crash the application.</string>

<!-- WIP -->
<string name="location_map_view_copyright" translatable="false"MapTiler © OpenStreetMap contributors</string>
<string name="location_map_view_copyright" translatable="false"IGN</string> <!-- Tchap: Custom string -->
</resources>
2 changes: 1 addition & 1 deletion vector-config/src/main/java/im/vector/app/config/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Config {
*/
const val ALLOW_EXTERNAL_UNIFIED_PUSH_DISTRIBUTORS = false // Tchap: Disable UnifiedPush (use Firebase/background sync)

const val ENABLE_LOCATION_SHARING = true // Tchap: Disable Location Sharing
const val ENABLE_LOCATION_SHARING = true
const val LOCATION_MAP_TILER_KEY = "" // Tchap: Disable Location Sharing

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ abstract class BottomSheetMessagePreviewItem : VectorEpoxyModel<BottomSheetMessa
holder.body.isVisible = locationUiData == null
holder.mapViewContainer.isVisible = locationUiData != null
locationUiData?.let { safeLocationUiData ->
// Tchap: Generate and load map on device
mapRenderer.render(safeLocationUiData, holder.staticMapImageView)

val pinMatrixItem = matrixItem.takeIf { safeLocationUiData.locationOwnerId != null }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import im.vector.app.features.location.LocationData
* Data used to display Location data in the message bottom sheet.
*/
data class LocationUiData(
// Tchap: Generate and load map on device
val locationData: LocationData,
val mapZoom: Double,
val mapSize: Size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import im.vector.app.features.home.room.detail.timeline.tools.linkify
import im.vector.app.features.html.SpanUtils
import im.vector.app.features.location.INITIAL_MAP_ZOOM_IN_TIMELINE
import im.vector.app.features.location.MapRenderer
import im.vector.app.features.location.UrlMapProvider
import im.vector.app.features.location.toLocationData
import im.vector.app.features.media.ImageContentRenderer
import im.vector.app.features.settings.VectorPreferences
Expand Down Expand Up @@ -70,7 +69,7 @@ class MessageActionsEpoxyController @Inject constructor(
private val eventDetailsFormatter: EventDetailsFormatter,
private val vectorPreferences: VectorPreferences,
private val dateFormatter: VectorDateFormatter,
private val urlMapProvider: UrlMapProvider,
// private val urlMapProvider: UrlMapProvider,
private val locationPinProvider: LocationPinProvider
) : TypedEpoxyController<MessageActionState>() {

Expand Down Expand Up @@ -236,7 +235,7 @@ class MessageActionsEpoxyController @Inject constructor(

private fun buildLocationUiData(state: MessageActionState): LocationUiData? {
if (state.timelineEvent()?.root?.isLocationMessage() != true) return null

// Tchap: Generate and load map on device
val locationContent = state.timelineEvent()?.root?.getClearContent().toModel<MessageLocationContent>(catchError = true) ?: return null
val locationData = locationContent.toLocationData() ?: return null
val locationOwnerId = if (locationContent.isSelfLocation()) state.informationData.senderId else null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import im.vector.app.features.home.room.detail.timeline.item.MessageLiveLocation
import im.vector.app.features.home.room.detail.timeline.item.MessageLiveLocationStartItem_
import im.vector.app.features.location.INITIAL_MAP_ZOOM_IN_TIMELINE
import im.vector.app.features.location.MapRenderer
import im.vector.app.features.location.UrlMapProvider
import im.vector.app.features.location.toLocationData
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.timeline.TimelineEvent
Expand All @@ -45,7 +44,6 @@ class LiveLocationShareMessageItemFactory @Inject constructor(
private val dimensionConverter: DimensionConverter,
private val timelineMediaSizeProvider: TimelineMediaSizeProvider,
private val avatarSizeProvider: AvatarSizeProvider,
private val urlMapProvider: UrlMapProvider,
private val locationPinProvider: LocationPinProvider,
private val vectorDateFormatter: VectorDateFormatter,
private val mapRenderer: MapRenderer,
Expand Down Expand Up @@ -107,6 +105,7 @@ class LiveLocationShareMessageItemFactory @Inject constructor(
): MessageLiveLocationItem {
val size = Size(timelineMediaSizeProvider.getMaxSize().first, dimensionConverter.dpToPx(MessageItemFactory.MESSAGE_LOCATION_ITEM_HEIGHT_IN_DP))

// Tchap: Generate and load map on device
return MessageLiveLocationItem_()
.attributes(attributes)
.locationData(runningState.lastGeoUri.toLocationData())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import im.vector.app.features.html.SpanUtils
import im.vector.app.features.html.VectorHtmlCompressor
import im.vector.app.features.location.INITIAL_MAP_ZOOM_IN_TIMELINE
import im.vector.app.features.location.MapRenderer
import im.vector.app.features.location.UrlMapProvider
import im.vector.app.features.location.toLocationData
import im.vector.app.features.media.ImageContentRenderer
import im.vector.app.features.media.VideoContentRenderer
Expand Down Expand Up @@ -146,7 +145,7 @@ class MessageItemFactory @Inject constructor(
private val audioMessagePlaybackTracker: AudioMessagePlaybackTracker,
private val locationPinProvider: LocationPinProvider,
private val vectorPreferences: VectorPreferences,
private val urlMapProvider: UrlMapProvider,
// private val urlMapProvider: UrlMapProvider,
private val liveLocationShareMessageItemFactory: LiveLocationShareMessageItemFactory,
private val pollItemViewStateFactory: PollItemViewStateFactory,
private val voiceBroadcastItemFactory: VoiceBroadcastItemFactory,
Expand Down Expand Up @@ -234,7 +233,7 @@ class MessageItemFactory @Inject constructor(
val size = Size(timelineMediaSizeProvider.getMaxSize().first, dimensionConverter.dpToPx(MESSAGE_LOCATION_ITEM_HEIGHT_IN_DP))

val pinMatrixItem = if (locationContent.isSelfLocation()) informationData.matrixItem else null

// Tchap: Generate and load map on device
return MessageLocationItem_()
.attributes(attributes)
.locationData(locationContent.toLocationData())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>(
var mapZoom: Double = 0.0

@EpoxyAttribute
var mapSize: Size = Size(0,0)
var mapSize: Size = Size(0, 0)

@EpoxyAttribute
lateinit var mapRenderer: MapRenderer
Expand Down Expand Up @@ -89,6 +89,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder>(
height = mapSize.height
}

// Tchap: Generate and load map on device
mapRenderer.render(
location,
mapZoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@

package im.vector.app.features.location

// Tchap: Tiles from geo.data.gouv.fr
//const val MAP_BASE_URL = "https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json"
// Tchap: Tiles from IGN
const val MAP_BASE_URL = "https://data.geopf.fr/annexes/ressources/vectorTiles/styles/PLAN.IGN/standard.json"
//const val MAP_BASE_URL = "https://api.maptiler.com/maps/streets/style.json"

// Tchap: Tiles from geo.data.gouv.fr
// const val MAP_BASE_URL = "https://openmaptiles.geo.data.gouv.fr/styles/osm-bright/style.json"
// Tchap: Generate and load map on device
// 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 DEFAULT_PIN_ID = "DEFAULT_PIN_ID"

const val INITIAL_MAP_ZOOM_IN_PREVIEW = 15.0
Expand Down
36 changes: 25 additions & 11 deletions vector/src/main/java/im/vector/app/features/location/MapRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,37 @@ import android.graphics.drawable.Drawable
import android.util.Size
import android.widget.ImageView
import androidx.annotation.UiThread
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.engine.cache.SafeKeyGenerator
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.RequestOptions
import com.bumptech.glide.signature.ObjectKey
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.snapshotter.MapSnapshotter
import im.vector.app.core.glide.GlideApp
import im.vector.app.features.home.room.detail.timeline.action.LocationUiData
import org.matrix.android.sdk.api.extensions.tryOrNull
import timber.log.Timber
import java.io.File
import javax.inject.Inject

class MapRenderer @Inject constructor() {

companion object {
// TODO Tchap: should be replaced by getMapUrl()
private val styleBuilder = Style.Builder().fromUri(MAP_BASE_URL)
}

private lateinit var mapSnapshotter: MapSnapshotter

@UiThread
fun render(
locationUiData: LocationUiData,
imageView: ImageView
) {
val mapSnapshotter = getMapSnapshotter(imageView.context, locationUiData.locationData, locationUiData.mapZoom, locationUiData.mapSize)
mapSnapshotter = getMapSnapshotter(imageView.context, locationUiData.locationData, locationUiData.mapZoom, locationUiData.mapSize)
mapSnapshotter.start(
{
GlideApp.with(imageView)
Expand All @@ -68,21 +74,27 @@ class MapRenderer @Inject constructor() {
errorHandler: MapSnapshotter.ErrorHandler? = null,
) {
val context = imageView.context
val mapSnapshotFile = File(
context.cacheDir.absolutePath,
"${locationData.latitude}${locationData.longitude}${zoom}${size.width}${size.height}"
val filename = SafeKeyGenerator().getSafeKey(
ObjectKey("${locationData.latitude}${locationData.longitude}${zoom}${size.width}${size.height}")
)
val mapSnapshotFile = File(context.applicationContext.cacheDir, filename)

if (mapSnapshotFile.exists()) {
loadMap(imageView, mapSnapshotFile, imageCornerTransformation, listener)
} else {
val mapSnapshotter = getMapSnapshotter(context, locationData, zoom, size)
mapSnapshotter = getMapSnapshotter(context, locationData, zoom, size)
mapSnapshotter.start(
{ mapSnapshot ->
mapSnapshotFile.outputStream().use {
mapSnapshot.bitmap.compress(Bitmap.CompressFormat.PNG, 100, it)
loadMap(imageView, mapSnapshot.bitmap, imageCornerTransformation, listener)

runCatching {
Timber.d(filename)
mapSnapshotFile.outputStream().use {
mapSnapshot.bitmap.compress(Bitmap.CompressFormat.PNG, 100, it)
}
}.onFailure {
Timber.e("Map snapshot was not stored at this time")
}
loadMap(imageView, mapSnapshotFile, imageCornerTransformation, listener)
}, errorHandler
)
}
Expand All @@ -91,6 +103,7 @@ class MapRenderer @Inject constructor() {
fun clear(mapView: ImageView, pinView: ImageView) {
// It can be called after recycler view is destroyed, just silently catch
tryOrNull {
mapSnapshotter.cancel()
GlideApp.with(mapView).clear(mapView)
GlideApp.with(pinView).clear(pinView)
}
Expand All @@ -112,16 +125,17 @@ class MapRenderer @Inject constructor() {

private fun loadMap(
imageView: ImageView,
mapSnapshotFile: File,
mapSnapshot: Any,
imageCornerTransformation: BitmapTransformation,
listener: RequestListener<Drawable>,
) {
GlideApp.with(imageView)
.load(mapSnapshotFile)
.load(mapSnapshot)
.apply(RequestOptions.centerCropTransform())
.placeholder(imageView.drawable)
.listener(listener)
.transform(imageCornerTransformation)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.into(imageView)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,28 @@ class UrlMapProvider @Inject constructor(
?.mapStyleUrl
return upstreamMapUrl ?: fallbackMapUrl
}
// Tchap: Generate and load map on device
// fun buildStaticMapUrl(
// locationData: LocationData,
// zoom: Double,
// width: Int,
// height: Int
// ): String {
// return buildString {
// append(STATIC_MAP_BASE_URL)
// append(locationData.longitude)
// append(",")
// append(locationData.latitude)
// append(",")
// append(zoom)
// append("/")
// append(width)
// append("x")
// append(height)
// append(".png")
// append(keyParam)
// // Since the default copyright font is too small we put a custom one on map
// append("&attribution=false")
// }
// }
}

0 comments on commit 83b67ff

Please sign in to comment.