diff --git a/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt b/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt index 2f89bd5..f242d72 100644 --- a/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt +++ b/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt @@ -41,12 +41,19 @@ class MainActivity : AppCompatActivity() { private lateinit var form: Form private val charPool: List = ('a'..'z') + ('A'..'Z') - private val stringValues = arrayOf("one", "two", "three", "four", "five").map { "Option $it" }.toList() + private val stringValues = arrayOf( + "one", + "two", + "three", + "four", + "really long long long long long five" + ).map { "Option $it" }.toList() private val longerStringValues = (1..5).map { randomString(25) } private val notEmptyValidator = NotBlankFormValidator("This field is empty") private val emailValidator = EmailValidator("This is not valid email!") - private val maxLengthValidator = MaxLengthFormValidator("This filed has more than 10 characters.", 10) + private val maxLengthValidator = + MaxLengthFormValidator("This filed has more than 10 characters.", 10) private val validateActionCallback = object : ActionCallback, Form.Callback { override fun successCallback() { @@ -115,15 +122,57 @@ class MainActivity : AppCompatActivity() { addElement(HeaderElement("Static elements"), true) addElement(TextElement("TextElement value"), true) addElement(LabelTextElement("LabelTextElement label", "LabelTextElement text"), true) + addElement( + LabelTextElement( + "LabelTextElement label with very long text which needs to overflow", + "LabelTextElement text with very long text which needs to overflow" + ), true + ) + addElement( + LabelTextElement( + "Label", + "LabelTextElement text with very long text which needs to overflow" + ), true + ) addElement(OpenableHeaderTextElement("OpenableHeaderTextElement label", longerStringValues)) addSpace() //input elements addElement(HeaderElement("Input elements"), true) - addElement(LabelSwitchElement("LabelSwitchElement label", true, showToastCheckboxCallback), true) - addElement(LabelSpinnerElement("LabelSpinnerElement label", "Option one", arrayListOf("Select...").plus(stringValues), null, formValidators = mutableListOf>(NotEqualToValidator("Select...", "You have to select a value!"))), true) - addElement(LabelCheckboxElement("LabelCheckboxElement label", true, showToastCheckboxCallback), true) - addElement(LabelDateTimeElement("Date picker", "Vyberte datum...", supportFragmentManager, showToastDateTimeValueCallback, formValidators = arrayListOf(NotInPastValidator("Date cannot be in past")))) + addElement( + LabelSwitchElement("LabelSwitchElement label", true, showToastCheckboxCallback), + true + ) + addElement( + LabelSpinnerElement( + "LabelSpinnerElement label", + "Option one", + arrayListOf("Select...").plus(stringValues), + null, + formValidators = mutableListOf>( + NotEqualToValidator( + "Select...", + "You have to select a value!" + ) + ) + ), true + ) + addElement( + LabelCheckboxElement( + "LabelCheckboxElement label", + true, + showToastCheckboxCallback + ), true + ) + addElement( + LabelDateTimeElement( + "Date picker", + "Vyberte datum...", + supportFragmentManager, + showToastDateTimeValueCallback, + formValidators = arrayListOf(NotInPastValidator("Date cannot be in past")) + ) + ) addSpace() diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/ActionElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/ActionElement.kt index 5e590ec..4253d01 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/ActionElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/ActionElement.kt @@ -5,10 +5,20 @@ import cz.qase.android.formbuilderlibrary.R import cz.qase.android.formbuilderlibrary.element.generic.ActionCallback -class ActionElement(actionCallback: ActionCallback, - label: String, - groupComponent: Int = R.layout.form_group_item_inline, - headerComponent: Int = R.layout.form_inline_label, - symbolComponent: Int = R.layout.form_button_symbol, - formStyleBundle: FormStyleBundle? = null -) : NavigationElement(actionCallback, label, groupComponent, headerComponent, symbolComponent, formStyleBundle) \ No newline at end of file +class ActionElement( + actionCallback: ActionCallback, + label: String, + groupComponent: Int = R.layout.form_group_item_inline, + headerComponent: Int = R.layout.form_inline_label, + symbolComponent: Int = R.layout.form_button_symbol, + groupComponentEnd: Int = R.layout.form_group_item_inline_end, + formStyleBundle: FormStyleBundle? = null +) : NavigationElement( + actionCallback, + label, + groupComponent, + headerComponent, + symbolComponent, + groupComponentEnd, + formStyleBundle +) \ 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 a0f1c82..aa6a278 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 @@ -17,13 +17,14 @@ import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback import cz.qase.android.formbuilderlibrary.element.generic.FormElementValid class LabelCheckboxElement( - private val label: String, - private val checked: Boolean, - private val checkboxCallback: CheckboxCallback, - private val groupComponent: Int = R.layout.form_group_item_inline, - private val labelComponent: Int = R.layout.form_inline_label, - private val checkboxComponent: Int = R.layout.form_checkbox_item, - private val formStyleBundle: FormStyleBundle? = null + private val label: String, + private val checked: Boolean, + private val checkboxCallback: CheckboxCallback, + private val groupComponent: Int = R.layout.form_group_item_inline, + private val labelComponent: Int = R.layout.form_inline_label, + private val checkboxComponent: Int = R.layout.form_checkbox_item, + private val groupComponentEnd: Int = R.layout.form_group_item_inline_end, + private val formStyleBundle: FormStyleBundle? = null ) : FormElementValid() { private var checkbox: CheckBox? = null @@ -45,28 +46,43 @@ class LabelCheckboxElement( 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 - val labelView = prepareLabel(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) - val checkboxView = prepareCheckbox(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) + val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup + val labelView = prepareLabel( + inflater, context, this.formStyleBundle + ?: formStyleBundle, view + ) + val checkboxView = prepareCheckbox( + inflater, context, this.formStyleBundle + ?: formStyleBundle, groupEnd + ) view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) view.addView(labelView) - view.addView(checkboxView) + groupEnd.addView(checkboxView) + view.addView(groupEnd) viewGroup = view return view } - private fun prepareLabel(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): TextView { + private fun prepareLabel( + inflater: LayoutInflater, + context: Context, + formStyleBundle: FormStyleBundle, + root: ViewGroup + ): TextView { val headerView = inflater.inflate(labelComponent, root, false) as TextView headerView.setTextColorResourceId(context, formStyleBundle.primaryTextColor) headerView.text = label return headerView } - private fun prepareCheckbox(inflater: LayoutInflater, context: Context, formStyleBundle: FormStyleBundle, root: ViewGroup): CheckBox { - val checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox - + private fun prepareCheckbox( + inflater: LayoutInflater, + context: Context, + formStyleBundle: FormStyleBundle, + root: ViewGroup + ): CheckBox { + val checkbox = inflater.inflate(checkboxComponent, root, false) as CheckBox val color = ContextCompat.getColor(context, formStyleBundle.primaryBackgroundColor) CompoundButtonCompat.setButtonTintList(checkbox, ColorStateList.valueOf(color)) checkbox.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) 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 6f2af33..2591fcc 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 @@ -17,13 +17,16 @@ import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback import cz.qase.android.formbuilderlibrary.element.generic.FormElementValid -class LabelSwitchElement(private val label: String, - 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() { +class LabelSwitchElement( + private val label: String, + 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 groupComponentEnd: Int = R.layout.form_group_item_inline_end, + private val formStyleBundle: FormStyleBundle? = null +) : FormElementValid() { private var switchView: SwitchCompat? = null private var viewGroup: ViewGroup? = null @@ -43,13 +46,19 @@ class LabelSwitchElement(private val label: String, 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 - val headerView = prepareHeader(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) - val textView = prepareSwitch(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) + val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup + val headerView = prepareHeader( + inflater, context, this.formStyleBundle + ?: formStyleBundle, view + ) + val textView = prepareSwitch( + inflater, context, this.formStyleBundle + ?: formStyleBundle, groupEnd + ) view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) view.addView(headerView) - view.addView(textView) + groupEnd.addView(textView) + view.addView(groupEnd) viewGroup = view return view } diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationElement.kt index e2792a6..d23fde7 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationElement.kt @@ -15,12 +15,15 @@ import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId import cz.qase.android.formbuilderlibrary.element.generic.ActionCallback import cz.qase.android.formbuilderlibrary.element.generic.FormElementNoValue -open class NavigationElement(private val actionCallback: ActionCallback, - private val label: String, - private val groupComponent: Int = R.layout.form_group_item_inline, - private val headerComponent: Int = R.layout.form_inline_label, - private val symbolComponent: Int = R.layout.form_navigation_symbol, - private val formStyleBundle: FormStyleBundle? = null) : FormElementNoValue() { +open class NavigationElement( + private val actionCallback: ActionCallback, + private val label: String, + private val groupComponent: Int = R.layout.form_group_item_inline, + private val headerComponent: Int = R.layout.form_inline_label, + private val symbolComponent: Int = R.layout.form_navigation_symbol, + private val groupComponentEnd: Int = R.layout.form_group_item_inline_end, + private val formStyleBundle: FormStyleBundle? = null +) : FormElementNoValue() { private var viewGroup: ViewGroup? = null @@ -35,14 +38,19 @@ open class NavigationElement(private val actionCallback: ActionCallback, 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 - val headerView = prepareLabel(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) - val symbolView = prepareSymbol(inflater, context, this.formStyleBundle - ?: formStyleBundle, view) + val groupEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup + val headerView = prepareLabel( + inflater, context, this.formStyleBundle + ?: formStyleBundle, view + ) + val symbolView = prepareSymbol( + inflater, context, this.formStyleBundle + ?: formStyleBundle, groupEnd + ) view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) view.addView(headerView) - view.addView(symbolView) - + groupEnd.addView(symbolView) + view.addView(groupEnd) view.isClickable = true view.setOnClickListener { actionCallback.callback() @@ -50,11 +58,17 @@ open class NavigationElement(private val actionCallback: ActionCallback, view.setOnTouchListener { _, event -> when (event.action) { MotionEvent.ACTION_UP -> { - view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) + view.setBackgroundColorResourceId( + context, + formStyleBundle.secondaryBackgroundColor + ) view.performClick() } MotionEvent.ACTION_CANCEL -> { - view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) + view.setBackgroundColorResourceId( + context, + formStyleBundle.secondaryBackgroundColor + ) } MotionEvent.ACTION_DOWN -> { view.setBackgroundColorResourceId(context, formStyleBundle.primaryBackgroundColor) diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationWithErrorElement.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationWithErrorElement.kt index c03a2c9..e65fc75 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationWithErrorElement.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/element/NavigationWithErrorElement.kt @@ -22,6 +22,7 @@ open class NavigationWithErrorElement( private val headerComponent: Int = R.layout.form_inline_label, private val warningSymbolComponent: Int = R.layout.form_error_symbol, private val symbolComponent: Int = R.layout.form_navigation_symbol, + private val groupComponentEnd: Int = R.layout.form_group_item_inline_end, private val formStyleBundle: FormStyleBundle? = null ) : FormElementNoValue() { @@ -38,19 +39,21 @@ open class NavigationWithErrorElement( 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 + val viewEnd = inflater.inflate(groupComponentEnd, view, false) as ViewGroup val headerView = prepareLabel( inflater, context, this.formStyleBundle ?: formStyleBundle, view ) - val errorView = inflater.inflate(warningSymbolComponent, view, false) as ImageView + val errorView = inflater.inflate(warningSymbolComponent, viewEnd, false) as ImageView val symbolView = prepareSymbol( inflater, context, this.formStyleBundle - ?: formStyleBundle, view + ?: formStyleBundle, viewEnd ) view.setBackgroundColorResourceId(context, formStyleBundle.secondaryBackgroundColor) view.addView(headerView) - view.addView(errorView) - view.addView(symbolView) + viewEnd.addView(errorView) + viewEnd.addView(symbolView) + view.addView(viewEnd) view.isClickable = true view.setOnClickListener { diff --git a/formbuilderlibrary/src/main/res/layout/form_checkbox_item.xml b/formbuilderlibrary/src/main/res/layout/form_checkbox_item.xml index b2bed30..8df204a 100644 --- a/formbuilderlibrary/src/main/res/layout/form_checkbox_item.xml +++ b/formbuilderlibrary/src/main/res/layout/form_checkbox_item.xml @@ -1,11 +1,7 @@ + /> diff --git a/formbuilderlibrary/src/main/res/layout/form_error_symbol.xml b/formbuilderlibrary/src/main/res/layout/form_error_symbol.xml index 4ee3454..79a2062 100644 --- a/formbuilderlibrary/src/main/res/layout/form_error_symbol.xml +++ b/formbuilderlibrary/src/main/res/layout/form_error_symbol.xml @@ -1,14 +1,9 @@ + /> diff --git a/formbuilderlibrary/src/main/res/layout/form_group_item_inline.xml b/formbuilderlibrary/src/main/res/layout/form_group_item_inline.xml index f51899c..323df54 100644 --- a/formbuilderlibrary/src/main/res/layout/form_group_item_inline.xml +++ b/formbuilderlibrary/src/main/res/layout/form_group_item_inline.xml @@ -1,8 +1,8 @@ - + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="center_vertical"> - \ No newline at end of file + \ No newline at end of file diff --git a/formbuilderlibrary/src/main/res/layout/form_group_item_inline_end.xml b/formbuilderlibrary/src/main/res/layout/form_group_item_inline_end.xml new file mode 100644 index 0000000..a4e60a7 --- /dev/null +++ b/formbuilderlibrary/src/main/res/layout/form_group_item_inline_end.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/formbuilderlibrary/src/main/res/layout/form_inline_input.xml b/formbuilderlibrary/src/main/res/layout/form_inline_input.xml deleted file mode 100644 index 8ebc546..0000000 --- a/formbuilderlibrary/src/main/res/layout/form_inline_input.xml +++ /dev/null @@ -1,15 +0,0 @@ - - diff --git a/formbuilderlibrary/src/main/res/layout/form_inline_label.xml b/formbuilderlibrary/src/main/res/layout/form_inline_label.xml index be56c98..790b49b 100644 --- a/formbuilderlibrary/src/main/res/layout/form_inline_label.xml +++ b/formbuilderlibrary/src/main/res/layout/form_inline_label.xml @@ -1,14 +1,11 @@ diff --git a/formbuilderlibrary/src/main/res/layout/form_inline_spinner.xml b/formbuilderlibrary/src/main/res/layout/form_inline_spinner.xml index 465b8d7..52280e6 100644 --- a/formbuilderlibrary/src/main/res/layout/form_inline_spinner.xml +++ b/formbuilderlibrary/src/main/res/layout/form_inline_spinner.xml @@ -5,11 +5,9 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="0dp" - android:width="160dp" + android:layout_weight="1" android:padding="10dp" android:textAlignment="textEnd" + android:gravity="end" app:arrowDrawable="@drawable/ic_arrow_down" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintRight_toRightOf="parent" app:popupTextAlignment="end" /> \ No newline at end of file diff --git a/formbuilderlibrary/src/main/res/layout/form_inline_switch.xml b/formbuilderlibrary/src/main/res/layout/form_inline_switch.xml index b2abcfa..65a9cbf 100644 --- a/formbuilderlibrary/src/main/res/layout/form_inline_switch.xml +++ b/formbuilderlibrary/src/main/res/layout/form_inline_switch.xml @@ -1,11 +1,5 @@ - \ No newline at end of file + android:layout_margin="6dp" /> \ No newline at end of file diff --git a/formbuilderlibrary/src/main/res/layout/form_inline_text.xml b/formbuilderlibrary/src/main/res/layout/form_inline_text.xml index 68ff94e..a85c7f4 100644 --- a/formbuilderlibrary/src/main/res/layout/form_inline_text.xml +++ b/formbuilderlibrary/src/main/res/layout/form_inline_text.xml @@ -1,15 +1,11 @@ diff --git a/formbuilderlibrary/src/main/res/layout/form_navigation_symbol.xml b/formbuilderlibrary/src/main/res/layout/form_navigation_symbol.xml index eae9de8..522c345 100644 --- a/formbuilderlibrary/src/main/res/layout/form_navigation_symbol.xml +++ b/formbuilderlibrary/src/main/res/layout/form_navigation_symbol.xml @@ -1,16 +1,11 @@ + android:src="@drawable/ic_arrow_down" /> diff --git a/formbuilderlibrary/src/main/res/layout/form_text_input_layout.xml b/formbuilderlibrary/src/main/res/layout/form_text_input_layout.xml index 19c3688..5ea42f2 100644 --- a/formbuilderlibrary/src/main/res/layout/form_text_input_layout.xml +++ b/formbuilderlibrary/src/main/res/layout/form_text_input_layout.xml @@ -1,10 +1,6 @@ + android:layout_weight="1" + xmlns:android="http://schemas.android.com/apk/res/android"> \ No newline at end of file