Merge pull request #6247 from vector-im/feature/ons/fix_static_map_copyright_size

Fix copyright attributions of map views [PSF-1058] - [PSF-1072]
This commit is contained in:
Benoit Marty 2022-06-10 13:56:24 +02:00 committed by GitHub
commit 990a6832bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 58 additions and 11 deletions

1
changelog.d/6247.bugfix Normal file
View File

@ -0,0 +1 @@
Fix copyright attributions of map views

View File

@ -7,7 +7,8 @@
<dimen name="text_size_body">14sp</dimen>
<dimen name="text_size_caption">12sp</dimen>
<dimen name="text_size_micro">10sp</dimen>
<dimen name="text_size_nano">8sp</dimen>
<dimen name="text_size_button">14sp</dimen>
</resources>
</resources>

View File

@ -40,4 +40,9 @@
<item name="android:gravity">center</item>
</style>
<style name="Widget.Vector.TextView.Nano.Copyright">
<!-- Static map view is always light in both light and dark theme. So we need to use a static dark color -->
<item name="android:textColor">@color/element_content_primary_light</item>
</style>
</resources>

View File

@ -48,4 +48,9 @@
<item name="lineHeight">16sp</item>
</style>
</resources>
<style name="Widget.Vector.TextView.Nano">
<item name="android:textAppearance">@style/TextAppearance.Vector.Nano</item>
<item name="lineHeight">16sp</item>
</style>
</resources>

View File

@ -85,4 +85,11 @@
<item name="android:letterSpacing">0.02</item>
</style>
<style name="TextAppearance.Vector.Nano" parent="TextAppearance.MaterialComponents.Caption">
<item name="fontFamily">sans-serif</item>
<item name="android:fontFamily">sans-serif</item>
<item name="android:textSize">@dimen/text_size_nano</item>
<item name="android:letterSpacing">0</item>
</style>
</resources>

View File

@ -85,6 +85,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder> : AbsMe
): Boolean {
holder.staticMapPinImageView.setImageResource(R.drawable.ic_location_pin_failed)
holder.staticMapErrorTextView.isVisible = true
holder.staticMapCopyrightTextView.isVisible = false
return false
}
@ -100,6 +101,7 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder> : AbsMe
holder.staticMapPinImageView.setImageDrawable(pinDrawable)
}
holder.staticMapErrorTextView.isVisible = false
holder.staticMapCopyrightTextView.isVisible = true
return false
}
})
@ -111,5 +113,6 @@ abstract class AbsMessageLocationItem<H : AbsMessageLocationItem.Holder> : AbsMe
val staticMapImageView by bind<ImageView>(R.id.staticMapImageView)
val staticMapPinImageView by bind<ImageView>(R.id.staticMapPinImageView)
val staticMapErrorTextView by bind<TextView>(R.id.staticMapErrorTextView)
val staticMapCopyrightTextView by bind<TextView>(R.id.staticMapCopyrightTextView)
}
}

View File

@ -33,6 +33,7 @@ import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
import com.mapbox.mapboxsdk.style.layers.Property
import im.vector.app.R
import im.vector.app.core.utils.DimensionConverter
import timber.log.Timber
class MapTilerMapView @JvmOverloads constructor(
@ -56,6 +57,7 @@ class MapTilerMapView @JvmOverloads constructor(
private var mapRefs: MapRefs? = null
private var initZoomDone = false
private var showLocationButton = false
private var dimensionConverter: DimensionConverter? = null
init {
context.theme.obtainStyledAttributes(
@ -70,6 +72,7 @@ class MapTilerMapView @JvmOverloads constructor(
recycle()
}
}
dimensionConverter = DimensionConverter(resources)
}
private fun setLocateButtonVisibility(typedArray: TypedArray) {
@ -151,7 +154,12 @@ class MapTilerMapView @JvmOverloads constructor(
pendingState = state
}
safeMapRefs.map.uiSettings.setLogoMargins(0, 0, 0, state.logoMarginBottom)
safeMapRefs.map.uiSettings.apply {
setLogoMargins(0, 0, 0, state.logoMarginBottom)
dimensionConverter?.let {
setAttributionMargins(it.dpToPx(88), 0, 0, state.logoMarginBottom)
}
}
val pinDrawable = state.pinDrawable ?: userLocationDrawable
pinDrawable?.let { drawable ->

View File

@ -17,8 +17,6 @@
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
@ -26,7 +24,6 @@ import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
class UrlMapProvider @Inject constructor(
private val localeProvider: LocaleProvider,
private val session: Session,
private val rawService: RawService
) {
@ -63,10 +60,8 @@ class UrlMapProvider @Inject constructor(
append(height)
append(".png")
append(keyParam)
if (!localeProvider.isRTL()) {
// On LTR languages we want the legal mentions to be displayed on the bottom left of the image
append("&attribution=bottomleft")
}
// Since the default copyright font is too small we put a custom one on map
append("&attribution=false")
}
}
}

View File

@ -25,6 +25,7 @@ import androidx.core.graphics.drawable.toBitmap
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.geometry.LatLngBounds
import com.mapbox.mapboxsdk.maps.MapView
@ -40,6 +41,7 @@ import im.vector.app.R
import im.vector.app.core.extensions.addChildFragment
import im.vector.app.core.extensions.configureWith
import im.vector.app.core.platform.VectorBaseFragment
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.databinding.FragmentLocationLiveMapViewBinding
import im.vector.app.features.location.UrlMapProvider
import im.vector.app.features.location.zoomToBounds
@ -58,6 +60,7 @@ class LocationLiveMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
@Inject lateinit var urlMapProvider: UrlMapProvider
@Inject lateinit var bottomSheetController: LiveLocationBottomSheetController
@Inject lateinit var dimensionConverter: DimensionConverter
private val viewModel: LocationLiveMapViewModel by fragmentViewModel()
@ -94,6 +97,13 @@ class LocationLiveMapViewFragment @Inject constructor() : VectorBaseFragment<Fra
private fun setupMap() {
val mapFragment = getOrCreateSupportMapFragment()
mapFragment.getMapAsync { mapboxMap ->
val bottomSheetHeight = BottomSheetBehavior.from(views.bottomSheet).peekHeight
mapboxMap.uiSettings.apply {
// Place copyright above the user list bottom sheet
setLogoMargins(dimensionConverter.dpToPx(8), 0, 0, bottomSheetHeight + dimensionConverter.dpToPx(8))
setAttributionMargins(dimensionConverter.dpToPx(96), 0, 0, bottomSheetHeight + dimensionConverter.dpToPx(8))
}
lifecycleScope.launch {
mapboxMap.setStyle(urlMapProvider.getMapUrl()) { style ->
mapStyle = style

View File

@ -16,8 +16,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_live_location_users_bottom_sheet"
app:behavior_peekHeight="200dp"
app:behavior_hideable="false"
app:behavior_peekHeight="200dp"
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
<View

View File

@ -62,4 +62,14 @@
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5" />
<TextView
android:id="@+id/staticMapCopyrightTextView"
style="@style/Widget.Vector.TextView.Nano.Copyright"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:text="@string/location_map_view_copyright"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -42,4 +42,6 @@
<string name="ftue_auth_email_verification_subtitle">To confirm your email address, tap the button in the email we just sent to %s</string>
<string name="ftue_auth_email_verification_footer">Did not receive an email?</string>
<string name="ftue_auth_email_resend_email">Resend email</string>
<string name="location_map_view_copyright" translatable="false">© MapTiler © OpenStreetMap contributors</string>
</resources>