From d62cf70b8c01496cc07acca12b57f41b2d7b9e1a Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Wed, 27 Jul 2022 09:58:52 +0200 Subject: [PATCH] Add usage of TypedArray.use when possible --- .../vector/app/features/location/MapTilerMapView.kt | 9 +++------ .../location/live/LocationLiveEndedBannerView.kt | 11 ++++------- .../location/option/LocationSharingOptionView.kt | 11 ++++------- 3 files changed, 11 insertions(+), 20 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt b/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt index 1f9cb44c91..cc41ff696f 100644 --- a/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt +++ b/vector/src/main/java/im/vector/app/features/location/MapTilerMapView.kt @@ -22,6 +22,7 @@ import android.util.AttributeSet import android.view.Gravity import android.widget.ImageView import androidx.core.content.ContextCompat +import androidx.core.content.res.use import androidx.core.view.marginBottom import androidx.core.view.marginTop import androidx.core.view.updateLayoutParams @@ -65,12 +66,8 @@ class MapTilerMapView @JvmOverloads constructor( R.styleable.MapTilerMapView, 0, 0 - ).run { - try { - setLocateButtonVisibility(this) - } finally { - recycle() - } + ).use { + setLocateButtonVisibility(it) } dimensionConverter = DimensionConverter(resources) } 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 49d6985840..e2b4936f6e 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 @@ -21,6 +21,7 @@ import android.content.res.TypedArray import android.util.AttributeSet import android.view.LayoutInflater import androidx.constraintlayout.widget.ConstraintLayout +import androidx.core.content.res.use import androidx.core.view.updateLayoutParams import im.vector.app.R import im.vector.app.databinding.ViewLocationLiveEndedBannerBinding @@ -42,13 +43,9 @@ class LocationLiveEndedBannerView @JvmOverloads constructor( R.styleable.LocationLiveEndedBannerView, 0, 0 - ).run { - try { - setBackgroundAlpha(this) - setIconMarginStart(this) - } finally { - recycle() - } + ).use { + setBackgroundAlpha(it) + setIconMarginStart(it) } } diff --git a/vector/src/main/java/im/vector/app/features/location/option/LocationSharingOptionView.kt b/vector/src/main/java/im/vector/app/features/location/option/LocationSharingOptionView.kt index d11ff00261..63dd8c9744 100644 --- a/vector/src/main/java/im/vector/app/features/location/option/LocationSharingOptionView.kt +++ b/vector/src/main/java/im/vector/app/features/location/option/LocationSharingOptionView.kt @@ -24,6 +24,7 @@ import android.widget.ImageView import androidx.annotation.ColorInt import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat +import androidx.core.content.res.use import androidx.core.view.setPadding import im.vector.app.R import im.vector.app.core.extensions.tintBackground @@ -50,13 +51,9 @@ class LocationSharingOptionView @JvmOverloads constructor( R.styleable.LocationSharingOptionView, 0, 0 - ).run { - try { - setIcon(this) - setTitle(this) - } finally { - recycle() - } + ).use { + setIcon(it) + setTitle(it) } }