Retrieve map style url from .well-known.

This commit is contained in:
Onuray Sahin 2022-02-07 13:38:54 +03:00
parent 4ce1ab2665
commit 9d83bafa7b
5 changed files with 36 additions and 9 deletions

1
changelog.d/5175.feature Normal file
View file

@ -0,0 +1 @@
Retrieve map style url from .well-known

View file

@ -54,8 +54,11 @@ class LocationPreviewFragment @Inject constructor(
mapView = WeakReference(views.mapView)
views.mapView.onCreate(savedInstanceState)
views.mapView.initialize(urlMapProvider.mapUrl)
loadPinDrawable()
lifecycleScope.launchWhenCreated {
views.mapView.initialize(urlMapProvider.getMapUrl())
loadPinDrawable()
}
}
override fun onResume() {

View file

@ -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)

View file

@ -19,17 +19,27 @@ 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 {
append(MAP_BASE_URL)
append(keyParam)
suspend fun getMapUrl(): String {
return tryOrNull { rawService.getElementWellknown(session.sessionParams) }
?.mapTileServerConfig
?.mapStyleUrl
?: buildString {
append(MAP_BASE_URL)
append(keyParam)
}
}
fun buildStaticMapUrl(locationData: LocationData,

View file

@ -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
)