From 33f022aefbb8662416b276d5ff7e1686e71feee7 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 21 Jun 2021 23:02:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/association/FileAssociationActivity.kt | 2 +- .../viewbindingdelegate/ActivityViewBindings.kt | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt index 0fa73e39e..b5e27b72a 100644 --- a/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/FileAssociationActivity.kt @@ -15,7 +15,7 @@ class FileAssociationActivity : override val binding by viewBinding(ActivityTranslucenceBinding::inflate) - override val viewModel: FileAssociationViewModel by viewModels() + override val viewModel by viewModels() override fun onActivityCreated(savedInstanceState: Bundle?) { binding.rotateLoading.show() diff --git a/app/src/main/java/io/legado/app/utils/viewbindingdelegate/ActivityViewBindings.kt b/app/src/main/java/io/legado/app/utils/viewbindingdelegate/ActivityViewBindings.kt index 5ace190cc..bc52f95ba 100644 --- a/app/src/main/java/io/legado/app/utils/viewbindingdelegate/ActivityViewBindings.kt +++ b/app/src/main/java/io/legado/app/utils/viewbindingdelegate/ActivityViewBindings.kt @@ -6,8 +6,16 @@ import android.view.LayoutInflater import androidx.core.app.ComponentActivity import androidx.viewbinding.ViewBinding -inline fun ComponentActivity.viewBinding(crossinline bindingInflater: (LayoutInflater) -> T) = - lazy(LazyThreadSafetyMode.SYNCHRONIZED) { - val invoke = bindingInflater.invoke(layoutInflater) - invoke +/** + * + */ +inline fun ComponentActivity.viewBinding( + crossinline bindingInflater: (LayoutInflater) -> T, + setContentView: Boolean = false +) = lazy(LazyThreadSafetyMode.SYNCHRONIZED) { + val binding = bindingInflater.invoke(layoutInflater) + if (setContentView) { + setContentView(binding.root) } + binding +}