diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt index 5fa6b67..8167718 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/EditTextElement.kt @@ -69,6 +69,15 @@ open class EditTextElement( } } + public override fun enable() { + super.disable() + editText?.isEnabled = true + } + + public override fun disable() { + super.disable() + editText?.isEnabled = false + } override fun getVal(): String? = editText?.text.toString() } \ No newline at end of file diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelCheckboxElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelCheckboxElement.kt index e751ee0..357f610 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelCheckboxElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelCheckboxElement.kt @@ -2,7 +2,6 @@ package cz.qase.android.formbuilderlibrary.element import android.content.Context import android.content.res.ColorStateList -import android.graphics.Color import android.support.v4.content.ContextCompat import android.support.v4.widget.CompoundButtonCompat import android.view.LayoutInflater @@ -27,10 +26,10 @@ class LabelCheckboxElement( private val formStyleBundle: FormStyleBundle? = null ) : FormElementValid() { - private lateinit var checkbox: CheckBox + private var checkbox: CheckBox? = null override fun getVal(): Boolean? { - return checkbox.isChecked + return checkbox?.isChecked } @@ -53,7 +52,7 @@ class LabelCheckboxElement( } private fun prepareCheckbox(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): CheckBox { - checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox + val checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox val color = ContextCompat.getColor(context,formStyleBundle.primaryBackgroundColor) @@ -63,9 +62,17 @@ class LabelCheckboxElement( checkbox.setOnClickListener { checkboxCallback.callback(checkbox.isChecked) } + this.checkbox = checkbox return checkbox } + public override fun enable() { + super.disable() + checkbox?.isEnabled = true + } - + public override fun disable() { + super.disable() + checkbox?.isEnabled = false + } } \ No newline at end of file diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelDateTimeElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelDateTimeElement.kt index 9fe9191..c59057b 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelDateTimeElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelDateTimeElement.kt @@ -39,6 +39,7 @@ class LabelDateTimeElement(private val label: String, private var textView: TextView? = null private var labelView: TextView? = null + private var viewGroup: ViewGroup? = null override fun createView(context: Context, formStyleBundle: FormStyleBundle): View { val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater val view = inflater.inflate(groupComponent, null) as ViewGroup @@ -65,6 +66,7 @@ class LabelDateTimeElement(private val label: String, } true } + viewGroup = view return view } @@ -141,6 +143,18 @@ class LabelDateTimeElement(private val label: String, } } + public override fun enable() { + super.enable() + viewGroup?.isEnabled = true + textView?.isEnabled = true + } + + public override fun disable() { + super.disable() + viewGroup?.isEnabled = false + textView?.isEnabled = false + } + private fun prepareLabel(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): TextView { val headerView = inflater.inflate(headerComponent, root, false) as TextView headerView.setTextColorResourceId(context, formStyleBundle.primaryTextColor) diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt index ca612cf..b7ebb90 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelInputElement.kt @@ -100,6 +100,16 @@ class LabelInputElement(private val label: String, } } + public override fun enable() { + super.enable() + textInputLayout?.isEnabled = true + } + + public override fun disable() { + super.disable() + textInputLayout?.isEnabled = false + } + private fun prepareLabel(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): TextView { val headerView = inflater.inflate(headerComponent, root, false) as TextView headerView.setTextColorResourceId(context, formStyleBundle.primaryTextColor) diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSpinnerElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSpinnerElement.kt index 9472653..00da5e4 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSpinnerElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSpinnerElement.kt @@ -87,6 +87,20 @@ class LabelSpinnerElement(private val label: String, } } + public override fun enable() { + super.enable() + spinner?.isEnabled = true + spinner?.isClickable = true + spinner?.isFocusable = true + } + + public override fun disable() { + super.disable() + spinner?.isEnabled = false + spinner?.isClickable = false + spinner?.isFocusable = false + } + override fun getVal(): T? { return spinner?.selectedIndex?.let { availableValues.get(it) } } diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSwitchElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSwitchElement.kt index 66071ca..4210436 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSwitchElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/LabelSwitchElement.kt @@ -1,6 +1,11 @@ package cz.qase.android.formbuilderlibrary.element import android.content.Context +import android.content.res.ColorStateList +import android.graphics.Color +import android.support.v4.content.ContextCompat +import android.support.v4.graphics.drawable.DrawableCompat +import android.support.v7.widget.SwitchCompat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -11,22 +16,17 @@ import cz.qase.android.formbuilderlibrary.common.setBackgroundColorResourceId import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback import cz.qase.android.formbuilderlibrary.element.generic.FormElementValid -import android.content.res.ColorStateList -import android.support.v4.graphics.drawable.DrawableCompat -import android.support.v7.widget.SwitchCompat -import android.graphics.Color -import android.support.v4.content.ContextCompat - class LabelSwitchElement(private val label: String, - private var checked: Boolean, + private var initialValue: Boolean, private val checkboxCallback: CheckboxCallback, private val groupComponent: Int = R.layout.form_group_item_inline, private val headerComponent: Int = R.layout.form_inline_label, private val switchComponent: Int = R.layout.form_inline_switch, private val formStyleBundle: FormStyleBundle? = null) : FormElementValid() { + private var switchView: SwitchCompat? = null override fun getVal(): Boolean { - return checked + return switchView?.isChecked == true } override fun createView(context: Context, formStyleBundle: FormStyleBundle): View { @@ -42,17 +42,16 @@ class LabelSwitchElement(private val label: String, return view } - private fun prepareSwitch(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): SwitchCompat { - val switchView = inflater.inflate(switchComponent, root, false) as SwitchCompat - switchView.isChecked = checked - switchView.setColor(formStyleBundle.primaryTextColor, context) - switchView.setTextColorResourceId(context, formStyleBundle.secondaryTextColor) - switchView.setOnCheckedChangeListener { _, isChecked -> - checked = isChecked - checkboxCallback.callback(checked) + val tmpSwitchView = inflater.inflate(switchComponent, root, false) as SwitchCompat + tmpSwitchView.isChecked = initialValue + tmpSwitchView.setColor(formStyleBundle.primaryTextColor, context) + tmpSwitchView.setTextColorResourceId(context, formStyleBundle.secondaryTextColor) + tmpSwitchView.setOnCheckedChangeListener { _, isChecked -> + checkboxCallback.callback(isChecked) } - return switchView + switchView = tmpSwitchView + return tmpSwitchView } private fun prepareHeader(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): TextView { @@ -63,7 +62,7 @@ class LabelSwitchElement(private val label: String, } - private fun SwitchCompat.setColor(colorRes: Int, context: Context){ + private fun SwitchCompat.setColor(colorRes: Int, context: Context) { // trackColor is the thumbColor with 30% transparency (77) val color = ContextCompat.getColor(context, colorRes) @@ -81,4 +80,14 @@ class LabelSwitchElement(private val label: String, intArrayOf(trackColor, Color.parseColor("#4D000000") // full black with 30% transparency (4D) ))) } + + public override fun enable() { + super.enable() + switchView?.isEnabled = true + } + + public override fun disable() { + super.disable() + switchView?.isEnabled = false + } } diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt index 19a9e45..11d67c1 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/TextAreaElement.kt @@ -125,4 +125,14 @@ class TextAreaElement( throw e } } + + public override fun enable() { + super.disable() + textInputEditText?.isEnabled = true + } + + public override fun disable() { + super.disable() + textInputEditText?.isEnabled = false + } } \ No newline at end of file diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElement.kt index 53fada7..69de231 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElement.kt @@ -7,6 +7,16 @@ import cz.qase.android.formbuilderlibrary.ValidationException abstract class FormElement() { + protected var enabled = true + + protected open fun enable() { + enabled = true + } + + protected open fun disable() { + enabled = false + } + abstract fun createView(context: Context, formStyleBundle: FormStyleBundle): View @Throws(ValidationException::class) diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElementValidatable.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElementValidatable.kt index 45d3deb..6ea40bb 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElementValidatable.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/generic/FormElementValidatable.kt @@ -11,8 +11,10 @@ abstract class FormElementValidatable(val formValidators: MutableList