From b2b2183bfa023cfe464c41b5f6bbde404084e700 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filip=20=C5=A0m=C3=ADd?= Date: Tue, 31 Mar 2020 20:48:20 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Simplify=20structure=20of=20base?= =?UTF-8?q?=20Android=20classes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The explicitly created constructors are replaced one constructor with default value of parameter. The constructor has @JvmOverloads annotation to maintain Java interoperability. --- .../cz/eman/kaal/presentation/activity/BaseActivity.kt | 8 +++----- .../cz/eman/kaal/presentation/fragment/BaseFragment.kt | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/activity/BaseActivity.kt b/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/activity/BaseActivity.kt index dca2a37..b4db3d7 100644 --- a/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/activity/BaseActivity.kt +++ b/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/activity/BaseActivity.kt @@ -12,14 +12,12 @@ import kotlinx.coroutines.cancel * @see[AppCompatActivity] * @since 0.1.0 */ -abstract class BaseActivity : AppCompatActivity, CoroutineScope { +abstract class BaseActivity @JvmOverloads constructor( + @LayoutRes contentLayoutId: Int = 0 +) : AppCompatActivity(contentLayoutId), CoroutineScope { override val coroutineContext = Dispatchers.Main + SupervisorJob() - constructor(): super() - - constructor(@LayoutRes contentLayoutId: Int): super(contentLayoutId) - override fun onDestroy() { super.onDestroy() coroutineContext.cancel() diff --git a/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/fragment/BaseFragment.kt b/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/fragment/BaseFragment.kt index 6c0afbd..4a1766d 100644 --- a/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/fragment/BaseFragment.kt +++ b/kaal-presentation/src/main/kotlin/cz/eman/kaal/presentation/fragment/BaseFragment.kt @@ -12,14 +12,12 @@ import kotlinx.coroutines.cancel * @see[Fragment] * @since 0.1.0 */ -abstract class BaseFragment : Fragment, CoroutineScope { +abstract class BaseFragment @JvmOverloads constructor( + @LayoutRes contentLayoutId: Int = 0 +) : Fragment(contentLayoutId), CoroutineScope { override val coroutineContext = Dispatchers.Main + SupervisorJob() - constructor(): super() - - constructor(@LayoutRes contentLayoutId: Int): super(contentLayoutId) - override fun onDestroy() { super.onDestroy() coroutineContext.cancel()