Skip to content

Commit

Permalink
REF: delete joda DateTime
Browse files Browse the repository at this point in the history
  • Loading branch information
balakz committed Aug 3, 2021
1 parent b5f1188 commit b8f574d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -84,13 +99,13 @@ class MainActivity : AppCompatActivity() {
toast?.show()
}
}
private val showToastDateTimeValueCallback = object : ValueCallback<DateTime> {
private val showToastDateTimeValueCallback = object : ValueCallback<Date> {
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()
Expand Down
1 change: 0 additions & 1 deletion formbuilderlibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,17 +24,17 @@ class LabelDateTimeElement(
private val label: String,
private var hint: String,
private var supportFragmentManager: FragmentManager,
private val valueChangeListener: ValueCallback<DateTime>? = null,
private var value: DateTime? = null,
private val valueChangeListener: ValueCallback<Date>? = null,
private var value: Date? = null,
private var sdf: SimpleDateFormat = SimpleDateFormat("dd.MM.yyyy - HH:mm", Locale.getDefault()),
formValidators: MutableList<FormValidator<DateTime>> = ArrayList(),
formValidators: MutableList<FormValidator<Date>> = 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<DateTime>(formValidators) {
) : FormElementValidatable<Date>(formValidators) {

override fun getVal(): DateTime? {
override fun getVal(): Date? {
return value
}

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DateTime> {
override fun validate(value: DateTime?) {
class DateTimeNotNullValidator(private val errorMsg: String) : FormValidator<Date> {
override fun validate(value: Date?) {
if (value == null) {
throw ValidationException(errorMsg)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package cz.qase.android.formbuilderlibrary.validator

import cz.qase.android.formbuilderlibrary.ValidationException
import org.joda.time.DateTime
import java.util.Date

/**
* MaxLengthFormValidator
*
* Check if length of form value is bigger than specified value
*/
class NotInFutureValidator(
private val errorMsg: String
) : FormValidator<DateTime> {
override fun validate(value: DateTime?) {
if (value != null && value.isAfterNow) {
private val errorMsg: String
) : FormValidator<Date> {
override fun validate(value: Date?) {
if (value != null && value.after(Date())) {
throw ValidationException(errorMsg)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package cz.qase.android.formbuilderlibrary.validator

import cz.qase.android.formbuilderlibrary.ValidationException
import org.joda.time.DateTime
import java.util.Date

/**
* MaxLengthFormValidator
*
* Check if length of form value is bigger than specified value
*/
class NotInPastValidator(
private val errorMsg: String
) : FormValidator<DateTime> {
override fun validate(value: DateTime?) {
if (value != null && value.isBeforeNow) {
private val errorMsg: String
) : FormValidator<Date> {
override fun validate(value: Date?) {
if (value != null && value.before(Date())) {
throw ValidationException(errorMsg)
}
}
Expand Down

0 comments on commit b8f574d

Please sign in to comment.