From 57486cab51d9839e8f3a2115c4856233ebb3a6d7 Mon Sep 17 00:00:00 2001 From: baheroff Date: Wed, 23 Oct 2024 16:19:59 +0300 Subject: [PATCH 1/2] MB-47298: bump lifecycle version --- navigation-base/build.gradle | 2 +- navigation-viewcontroller/build.gradle | 2 +- .../viewcontrollers/ViewController.kt | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/navigation-base/build.gradle b/navigation-base/build.gradle index ef03f06..ebd449a 100644 --- a/navigation-base/build.gradle +++ b/navigation-base/build.gradle @@ -64,7 +64,7 @@ dependencies { implementation("androidx.lifecycle:lifecycle-common-java8") { version { - require '2.2.0' + require '2.6.2' } } diff --git a/navigation-viewcontroller/build.gradle b/navigation-viewcontroller/build.gradle index 8734cef..b5de3e0 100644 --- a/navigation-viewcontroller/build.gradle +++ b/navigation-viewcontroller/build.gradle @@ -19,7 +19,7 @@ dependencies { implementation("androidx.lifecycle:lifecycle-common-java8") { version { - require '2.2.0' + require '2.6.2' } } } diff --git a/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/viewcontrollers/ViewController.kt b/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/viewcontrollers/ViewController.kt index f205033..611166d 100644 --- a/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/viewcontrollers/ViewController.kt +++ b/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/viewcontrollers/ViewController.kt @@ -73,7 +73,8 @@ open class ViewController( lifecycle.addObserver(LifecycleLoggingObserver(this)) } - override fun getLifecycle(): Lifecycle = fragment.viewLifecycleOwner.lifecycle + override val lifecycle: Lifecycle + get() = fragment.viewLifecycleOwner.lifecycle /** * Look for a child view with the given id. If this view has the given id, return this view. From f4c81cf2a280e80512c53019387a719c828e703c Mon Sep 17 00:00:00 2001 From: baheroff Date: Fri, 25 Oct 2024 13:11:16 +0300 Subject: [PATCH 2/2] fix crash on not initialized viewControllerClass field --- .../fragments/ViewControllerFragment.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/fragments/ViewControllerFragment.kt b/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/fragments/ViewControllerFragment.kt index 053f9a9..3884ead 100644 --- a/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/fragments/ViewControllerFragment.kt +++ b/navigation-viewcontroller/src/main/java/ru/touchin/roboswag/navigation_viewcontroller/fragments/ViewControllerFragment.kt @@ -80,7 +80,8 @@ open class ViewControllerFragment> private set + var viewControllerClass: Class>? = null + private set private var viewController: ViewController? = null @@ -241,14 +242,14 @@ open class ViewControllerFragment { - if (viewControllerClass.constructors.size != 1) { + if (viewControllerClass?.constructors?.size != 1) { throw IllegalStateException("There should be single constructor for $viewControllerClass") } - val constructor = viewControllerClass.constructors[0] - return when (constructor.parameterTypes.size) { + val constructor = viewControllerClass?.constructors?.get(0) + return when (constructor?.parameterTypes?.size) { 1 -> constructor.newInstance(creationContext) 2 -> constructor.newInstance(creationContext, savedInstanceState) - else -> throw IllegalArgumentException("Wrong constructor parameters count: ${constructor.parameterTypes.size}") + else -> throw IllegalArgumentException("Wrong constructor parameters count: ${constructor?.parameterTypes?.size}") } as ViewController }