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 9d6d332..8f32610 100644 --- a/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt +++ b/app/src/main/java/cz/qase/android/formbuilderproject/MainActivity.kt @@ -6,7 +6,22 @@ import androidx.appcompat.app.AppCompatActivity import cz.qase.android.formbuilderlibrary.Form import cz.qase.android.formbuilderlibrary.FormBuilder import cz.qase.android.formbuilderlibrary.FormStyleBundle -import cz.qase.android.formbuilderlibrary.element.* +import cz.qase.android.formbuilderlibrary.element.ActionElement +import cz.qase.android.formbuilderlibrary.element.ActionTextElement +import cz.qase.android.formbuilderlibrary.element.EditTextElement +import cz.qase.android.formbuilderlibrary.element.HeaderElement +import cz.qase.android.formbuilderlibrary.element.LabelCheckboxElement +import cz.qase.android.formbuilderlibrary.element.LabelDateTimeElement +import cz.qase.android.formbuilderlibrary.element.LabelInputElement +import cz.qase.android.formbuilderlibrary.element.LabelSpinnerElement +import cz.qase.android.formbuilderlibrary.element.LabelSwitchElement +import cz.qase.android.formbuilderlibrary.element.LabelTextElement +import cz.qase.android.formbuilderlibrary.element.NavigationElement +import cz.qase.android.formbuilderlibrary.element.NavigationWithErrorElement +import cz.qase.android.formbuilderlibrary.element.OpenableHeaderTextElement +import cz.qase.android.formbuilderlibrary.element.RadioButtonsElement +import cz.qase.android.formbuilderlibrary.element.TextAreaElement +import cz.qase.android.formbuilderlibrary.element.TextElement import cz.qase.android.formbuilderlibrary.element.generic.ActionCallback import cz.qase.android.formbuilderlibrary.element.generic.CheckboxCallback import cz.qase.android.formbuilderlibrary.element.generic.ValueCallback @@ -17,8 +32,8 @@ import cz.qase.android.formbuilderlibrary.validator.NotBlankFormValidator import cz.qase.android.formbuilderlibrary.validator.NotEqualToValidator import cz.qase.android.formbuilderlibrary.validator.NotInPastValidator import kotlinx.android.synthetic.main.activity_main.* -import org.joda.time.DateTime import java.text.SimpleDateFormat +import java.util.Date import java.util.Locale import kotlin.random.Random @@ -84,13 +99,13 @@ class MainActivity : AppCompatActivity() { toast?.show() } } - private val showToastDateTimeValueCallback = object : ValueCallback { + private val showToastDateTimeValueCallback = object : ValueCallback { private var toast: Toast? = null - override fun callback(value: DateTime) { + override fun callback(value: Date) { toast?.cancel() toast = Toast.makeText( this@MainActivity, - SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()).format(value.toDate()), + SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()).format(value), Toast.LENGTH_SHORT ) toast?.show() diff --git a/formbuilderlibrary/build.gradle b/formbuilderlibrary/build.gradle index 77fce8b..4682b8a 100644 --- a/formbuilderlibrary/build.gradle +++ b/formbuilderlibrary/build.gradle @@ -61,7 +61,6 @@ dependencies { androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' // Jodatime - implementation 'net.danlew:android.joda:2.9.9' implementation 'com.github.Qase:AndroidDateTimePicker:1.4.0' } \ 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 f671a11..05b7a0e 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 @@ -15,7 +15,6 @@ import cz.qase.android.formbuilderlibrary.common.setTextColorResourceId import cz.qase.android.formbuilderlibrary.element.generic.FormElementValidatable import cz.qase.android.formbuilderlibrary.element.generic.ValueCallback import cz.qase.android.formbuilderlibrary.validator.FormValidator -import org.joda.time.DateTime import wtf.qase.datetimepicker.DateTimePickerDialog import java.text.SimpleDateFormat import java.util.Date @@ -25,17 +24,17 @@ class LabelDateTimeElement( private val label: String, private var hint: String, private var supportFragmentManager: FragmentManager, - private val valueChangeListener: ValueCallback? = null, - private var value: DateTime? = null, + private val valueChangeListener: ValueCallback? = null, + private var value: Date? = null, private var sdf: SimpleDateFormat = SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()), - formValidators: MutableList> = ArrayList(), + formValidators: MutableList> = ArrayList(), private val groupComponent: Int = R.layout.form_group_item_inline, private val headerComponent: Int = R.layout.form_inline_label, private val textComponent: Int = R.layout.form_inline_text, private val formStyleBundle: FormStyleBundle? = null -) : FormElementValidatable(formValidators) { +) : FormElementValidatable(formValidators) { - override fun getVal(): DateTime? { + override fun getVal(): Date? { return value } @@ -102,7 +101,7 @@ class LabelDateTimeElement( textView.setTextColorResourceId(context, formStyleBundle.secondaryTextColor) val tmpValue = value textView.text = if (tmpValue != null) { - sdf.format(tmpValue.toDate()) + sdf.format(tmpValue) } else { hint } @@ -132,11 +131,10 @@ class LabelDateTimeElement( true } val callback: (date: Date) -> Unit = { newDate -> - val dateTime = DateTime(newDate) - value = dateTime + value = newDate textView.text = sdf.format(newDate) positiveValidation() - valueChangeListener?.callback(dateTime) + valueChangeListener?.callback(newDate) } textView.setOnClickListener { DateTimePickerDialog.show( diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/DateTimeNotNullValidator.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/DateTimeNotNullValidator.kt index ab22225..c36d2c6 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/DateTimeNotNullValidator.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/DateTimeNotNullValidator.kt @@ -1,10 +1,10 @@ package cz.qase.android.formbuilderlibrary.validator import cz.qase.android.formbuilderlibrary.ValidationException -import org.joda.time.DateTime +import java.util.Date -class DateTimeNotNullValidator(private val errorMsg: String) : FormValidator { - override fun validate(value: DateTime?) { +class DateTimeNotNullValidator(private val errorMsg: String) : FormValidator { + override fun validate(value: Date?) { if (value == null) { throw ValidationException(errorMsg) } diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInFutureValidator.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInFutureValidator.kt index 7bbf6dc..6597ba7 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInFutureValidator.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInFutureValidator.kt @@ -1,7 +1,7 @@ package cz.qase.android.formbuilderlibrary.validator import cz.qase.android.formbuilderlibrary.ValidationException -import org.joda.time.DateTime +import java.util.Date /** * MaxLengthFormValidator @@ -9,10 +9,10 @@ import org.joda.time.DateTime * Check if length of form value is bigger than specified value */ class NotInFutureValidator( - private val errorMsg: String -) : FormValidator { - override fun validate(value: DateTime?) { - if (value != null && value.isAfterNow) { + private val errorMsg: String +) : FormValidator { + override fun validate(value: Date?) { + if (value != null && value.after(Date())) { throw ValidationException(errorMsg) } } diff --git a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInPastValidator.kt b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInPastValidator.kt index 79669bd..3c6cd08 100644 --- a/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInPastValidator.kt +++ b/formbuilderlibrary/src/main/java/cz/qase/android/formbuilderlibrary/validator/NotInPastValidator.kt @@ -1,7 +1,7 @@ package cz.qase.android.formbuilderlibrary.validator import cz.qase.android.formbuilderlibrary.ValidationException -import org.joda.time.DateTime +import java.util.Date /** * MaxLengthFormValidator @@ -9,10 +9,10 @@ import org.joda.time.DateTime * Check if length of form value is bigger than specified value */ class NotInPastValidator( - private val errorMsg: String -) : FormValidator { - override fun validate(value: DateTime?) { - if (value != null && value.isBeforeNow) { + private val errorMsg: String +) : FormValidator { + override fun validate(value: Date?) { + if (value != null && value.before(Date())) { throw ValidationException(errorMsg) } }