Merge pull request #5176 from vector-im/feature/ons/map_wellknown_support
Retrieve map style url from .well-known
This commit is contained in:
commit
49a0555704
|
@ -0,0 +1 @@
|
|||
Retrieve map style url from .well-known
|
|
@ -54,9 +54,12 @@ class LocationPreviewFragment @Inject constructor(
|
|||
|
||||
mapView = WeakReference(views.mapView)
|
||||
views.mapView.onCreate(savedInstanceState)
|
||||
views.mapView.initialize(urlMapProvider.mapUrl)
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
views.mapView.initialize(urlMapProvider.getMapUrl())
|
||||
loadPinDrawable()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
|
|
@ -21,6 +21,7 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.view.isGone
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
|
@ -53,7 +54,10 @@ class LocationSharingFragment @Inject constructor(
|
|||
|
||||
mapView = WeakReference(views.mapView)
|
||||
views.mapView.onCreate(savedInstanceState)
|
||||
views.mapView.initialize(urlMapProvider.mapUrl)
|
||||
|
||||
lifecycleScope.launchWhenCreated {
|
||||
views.mapView.initialize(urlMapProvider.getMapUrl())
|
||||
}
|
||||
|
||||
views.shareLocationContainer.debouncedClicks {
|
||||
viewModel.handle(LocationSharingAction.OnShareLocation)
|
||||
|
|
|
@ -19,19 +19,31 @@ package im.vector.app.features.location
|
|||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.core.resources.LocaleProvider
|
||||
import im.vector.app.core.resources.isRTL
|
||||
import im.vector.app.features.raw.wellknown.getElementWellknown
|
||||
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||
import org.matrix.android.sdk.api.raw.RawService
|
||||
import org.matrix.android.sdk.api.session.Session
|
||||
import javax.inject.Inject
|
||||
|
||||
class UrlMapProvider @Inject constructor(
|
||||
private val localeProvider: LocaleProvider
|
||||
private val localeProvider: LocaleProvider,
|
||||
private val session: Session,
|
||||
private val rawService: RawService
|
||||
) {
|
||||
private val keyParam = "?key=${BuildConfig.mapTilerKey}"
|
||||
|
||||
// This is static so no need for a fun
|
||||
val mapUrl = buildString {
|
||||
private val fallbackMapUrl = buildString {
|
||||
append(MAP_BASE_URL)
|
||||
append(keyParam)
|
||||
}
|
||||
|
||||
suspend fun getMapUrl(): String {
|
||||
val upstreamMapUrl = tryOrNull { rawService.getElementWellknown(session.sessionParams) }
|
||||
?.mapTileServerConfig
|
||||
?.mapStyleUrl
|
||||
return upstreamMapUrl ?: fallbackMapUrl
|
||||
}
|
||||
|
||||
fun buildStaticMapUrl(locationData: LocationData,
|
||||
zoom: Double,
|
||||
width: Int,
|
||||
|
|
|
@ -35,7 +35,10 @@ data class ElementWellKnown(
|
|||
val elementE2E: E2EWellKnownConfig? = null,
|
||||
|
||||
@Json(name = "im.vector.riot.e2ee")
|
||||
val riotE2E: E2EWellKnownConfig? = null
|
||||
val riotE2E: E2EWellKnownConfig? = null,
|
||||
|
||||
@Json(name = "org.matrix.msc3488.tile_server")
|
||||
val mapTileServerConfig: MapTileServerConfig? = null
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
|
@ -53,3 +56,9 @@ data class WellKnownPreferredConfig(
|
|||
@Json(name = "preferredDomain")
|
||||
val preferredDomain: String? = null
|
||||
)
|
||||
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class MapTileServerConfig(
|
||||
@Json(name = "map_style_url")
|
||||
val mapStyleUrl: String? = null
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue