From 172f53ec8f5915bf74de2343bb1402a1c53d83a1 Mon Sep 17 00:00:00 2001 From: Tommy-Geenexus Date: Wed, 28 Aug 2024 14:56:13 +0200 Subject: [PATCH] refactor: use updateLayoutParams() extension --- .../com/none/tom/exiferaser/ExifEraserActivity.kt | 13 ++++++------- .../com/none/tom/exiferaser/help/ui/HelpFragment.kt | 7 ++----- .../imageProcessing/ui/ImageProcessingFragment.kt | 6 +----- .../ui/ImageProcessingDetailsFragment.kt | 7 ++----- .../tom/exiferaser/settings/ui/SettingsFragment.kt | 7 ++----- 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt b/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt index fe14303..542c0a0 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/ExifEraserActivity.kt @@ -33,6 +33,7 @@ import androidx.core.os.bundleOf import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updateLayoutParams import androidx.navigation.NavController import androidx.navigation.fragment.NavHostFragment import androidx.navigation.ui.setupActionBarWithNavController @@ -85,13 +86,11 @@ class ExifEraserActivity : AppCompatActivity() { val insets = windowInsetsCompat.getInsets( WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout() ) - root.setLayoutParams( - (root.layoutParams as FrameLayout.LayoutParams).apply { - leftMargin = insets.left - topMargin = insets.top - rightMargin = insets.right - } - ) + root.updateLayoutParams { + leftMargin = insets.left + topMargin = insets.top + rightMargin = insets.right + } windowInsetsCompat } root.addView( diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt index c544f1b..c3595f0 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/help/ui/HelpFragment.kt @@ -27,6 +27,7 @@ import android.widget.FrameLayout import androidx.core.net.toUri import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updateLayoutParams import androidx.recyclerview.widget.LinearLayoutManager import com.google.android.material.transition.MaterialSharedAxis import com.none.tom.exiferaser.R @@ -52,11 +53,7 @@ class HelpFragment : super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) - view.setLayoutParams( - (view.layoutParams as FrameLayout.LayoutParams).apply { - bottomMargin = insets.bottom - } - ) + view.updateLayoutParams { bottomMargin = insets.bottom } WindowInsetsCompat.CONSUMED } binding.helpAndFeedback.apply { diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt index f9f5bca..38993f8 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessing/ui/ImageProcessingFragment.kt @@ -74,11 +74,7 @@ class ImageProcessingFragment : BaseFragment( super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) - view.setLayoutParams( - (view.layoutParams as FrameLayout.LayoutParams).apply { - bottomMargin = insets.bottom - } - ) + view.updateLayoutParams { bottomMargin = insets.bottom } WindowInsetsCompat.CONSUMED } val menuProvider = object : MenuProvider { diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt index 9bd5a5e..edb60c6 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/imageProcessingDetails/ui/ImageProcessingDetailsFragment.kt @@ -30,6 +30,7 @@ import androidx.activity.result.contract.ActivityResultContracts import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.doOnLayout +import androidx.core.view.updateLayoutParams import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope @@ -100,11 +101,7 @@ class ImageProcessingDetailsFragment : super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) - view.setLayoutParams( - (view.layoutParams as FrameLayout.LayoutParams).apply { - bottomMargin = insets.bottom - } - ) + view.updateLayoutParams { bottomMargin = insets.bottom } WindowInsetsCompat.CONSUMED } binding.details.apply { diff --git a/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt b/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt index a5d4aa2..6701dc9 100644 --- a/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt +++ b/app/src/main/kotlin/com/none/tom/exiferaser/settings/ui/SettingsFragment.kt @@ -28,6 +28,7 @@ import androidx.activity.result.contract.ActivityResultContracts.OpenDocumentTre import androidx.appcompat.app.AppCompatDelegate import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat +import androidx.core.view.updateLayoutParams import androidx.fragment.app.setFragmentResultListener import androidx.fragment.app.viewModels import androidx.lifecycle.Lifecycle @@ -77,11 +78,7 @@ class SettingsFragment : super.onViewCreated(view, savedInstanceState) ViewCompat.setOnApplyWindowInsetsListener(view) { _, windowInsetsCompat -> val insets = windowInsetsCompat.getInsets(WindowInsetsCompat.Type.navigationBars()) - view.setLayoutParams( - (view.layoutParams as FrameLayout.LayoutParams).apply { - bottomMargin = insets.bottom - } - ) + view.updateLayoutParams { bottomMargin = insets.bottom } WindowInsetsCompat.CONSUMED } binding.preferences.apply {