From 5e59eb474aeae85a2410c410accf4e3ed6a446cf Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 25 Jul 2022 10:36:28 +0200 Subject: [PATCH] Adding attribute to control alpha of the banner background --- ...ylable_location_live_ended_banner_view.xml | 8 ++++++ .../live/LocationLiveEndedBannerView.kt | 28 ++++++++++++++++--- ...line_event_live_location_inactive_stub.xml | 3 +- .../view_location_live_ended_banner.xml | 1 - 4 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 library/ui-styles/src/main/res/values/stylable_location_live_ended_banner_view.xml diff --git a/library/ui-styles/src/main/res/values/stylable_location_live_ended_banner_view.xml b/library/ui-styles/src/main/res/values/stylable_location_live_ended_banner_view.xml new file mode 100644 index 0000000000..cd187586e7 --- /dev/null +++ b/library/ui-styles/src/main/res/values/stylable_location_live_ended_banner_view.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/vector/src/main/java/im/vector/app/features/location/live/LocationLiveEndedBannerView.kt b/vector/src/main/java/im/vector/app/features/location/live/LocationLiveEndedBannerView.kt index 95b444aee5..dc4938fe7a 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/LocationLiveEndedBannerView.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/LocationLiveEndedBannerView.kt @@ -17,9 +17,11 @@ package im.vector.app.features.location.live import android.content.Context +import android.content.res.TypedArray import android.util.AttributeSet import android.view.LayoutInflater import androidx.constraintlayout.widget.ConstraintLayout +import im.vector.app.R import im.vector.app.databinding.ViewLocationLiveEndedBannerBinding class LocationLiveEndedBannerView @JvmOverloads constructor( @@ -28,10 +30,28 @@ class LocationLiveEndedBannerView @JvmOverloads constructor( defStyleAttr: Int = 0 ) : ConstraintLayout(context, attrs, defStyleAttr) { + private val binding = ViewLocationLiveEndedBannerBinding.inflate( + LayoutInflater.from(context), + this + ) + init { - ViewLocationLiveEndedBannerBinding.inflate( - LayoutInflater.from(context), - this - ) + context.theme.obtainStyledAttributes( + attrs, + R.styleable.LocationLiveEndedBannerView, + 0, + 0 + ).run { + try { + setBackgroundAlpha(this) + } finally { + recycle() + } + } + } + + private fun setBackgroundAlpha(typedArray: TypedArray) { + val withAlpha = typedArray.getBoolean(R.styleable.LocationLiveEndedBannerView_locLiveEndedBkgWithAlpha, false) + binding.locationLiveEndedBannerBackground.alpha = if (withAlpha) 0.75f else 1f } } diff --git a/vector/src/main/res/layout/item_timeline_event_live_location_inactive_stub.xml b/vector/src/main/res/layout/item_timeline_event_live_location_inactive_stub.xml index df8559f34b..074ebf2f86 100644 --- a/vector/src/main/res/layout/item_timeline_event_live_location_inactive_stub.xml +++ b/vector/src/main/res/layout/item_timeline_event_live_location_inactive_stub.xml @@ -21,7 +21,8 @@ android:layout_height="48dp" app:layout_constraintBottom_toBottomOf="@id/locationLiveInactiveMap" app:layout_constraintEnd_toEndOf="@id/locationLiveInactiveMap" - app:layout_constraintStart_toStartOf="@id/locationLiveInactiveMap" /> + app:layout_constraintStart_toStartOf="@id/locationLiveInactiveMap" + app:locLiveEndedBkgWithAlpha="true" />