From 2a0c4f23be8fd4ad9a13075882e2a380d16577b0 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 30 Jan 2023 20:02:38 +0530 Subject: [PATCH 1/2] empty default constructor for ApplicationDialogFragment.kt --- .../subFrags/ApplicationDialogFragment.kt | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt index 545f3983e..f144c1d1b 100644 --- a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt @@ -32,15 +32,33 @@ import dagger.hilt.android.AndroidEntryPoint import foundation.e.apps.R @AndroidEntryPoint -class ApplicationDialogFragment( - private val drawable: Int = -1, - private val title: String, - private val message: String, - private val positiveButtonText: String = "", - private val positiveButtonAction: (() -> Unit)? = null, - private val cancelButtonText: String = "", - private val cancelButtonAction: (() -> Unit)? = null, -) : DialogFragment() { +class ApplicationDialogFragment() : DialogFragment() { + + private var drawable: Int = -1 + private lateinit var title: String + private lateinit var message: String + private lateinit var positiveButtonText: String + private var positiveButtonAction: (() -> Unit)? = null + private lateinit var cancelButtonText: String + private var cancelButtonAction: (() -> Unit)? = null + + constructor( + drawable: Int = -1, + title: String, + message: String, + positiveButtonText: String = "", + positiveButtonAction: (() -> Unit)? = null, + cancelButtonText: String = "", + cancelButtonAction: (() -> Unit)? = null, + ) : this() { + this.drawable = drawable + this.title = title + this.message = message + this.positiveButtonText = positiveButtonText + this.positiveButtonAction = positiveButtonAction + this.cancelButtonText = cancelButtonText + this.cancelButtonAction = cancelButtonAction + } override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val positiveButtonText = -- GitLab From 82618b8da936126147570ffec5ace80ad78b3119 Mon Sep 17 00:00:00 2001 From: Sayantan Roychowdhury Date: Mon, 30 Jan 2023 20:07:07 +0530 Subject: [PATCH 2/2] make it more null safe --- .../subFrags/ApplicationDialogFragment.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt index f144c1d1b..e975c8d0f 100644 --- a/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt +++ b/app/src/main/java/foundation/e/apps/application/subFrags/ApplicationDialogFragment.kt @@ -35,11 +35,11 @@ import foundation.e.apps.R class ApplicationDialogFragment() : DialogFragment() { private var drawable: Int = -1 - private lateinit var title: String - private lateinit var message: String - private lateinit var positiveButtonText: String + private var title: String? = null + private var message: String? = null + private var positiveButtonText: String? = null private var positiveButtonAction: (() -> Unit)? = null - private lateinit var cancelButtonText: String + private var cancelButtonText: String? = null private var cancelButtonAction: (() -> Unit)? = null constructor( @@ -62,7 +62,7 @@ class ApplicationDialogFragment() : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { val positiveButtonText = - positiveButtonText.ifEmpty { getString(R.string.ok) } + positiveButtonText?.ifEmpty { getString(R.string.ok) } val materialAlertDialogBuilder = MaterialAlertDialogBuilder(requireContext()) .setTitle(Html.fromHtml(title, Html.FROM_HTML_MODE_COMPACT)) .setMessage(Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT)) @@ -70,7 +70,7 @@ class ApplicationDialogFragment() : DialogFragment() { positiveButtonAction?.invoke() this.dismiss() } - if (cancelButtonText.isNotEmpty()) { + if (cancelButtonText?.isNotEmpty() == true) { materialAlertDialogBuilder.setNegativeButton(cancelButtonText) { _, _ -> cancelButtonAction?.invoke() this.dismiss() -- GitLab