Как проверить материал RangeDatePicker из первого выбора (точки) в Android? - PullRequest
0 голосов
/ 13 июля 2020

Я хочу проверить средство выбора даты от первого выбора до 6 месяцев, но не смог.

enter image description here Tried to catch(detect) first user selection(date) on range picker from this 'CalendarConstraints.Builder()'

        val constDate = CalendarConstraints.Builder()
        constDate.setValidator(object : CalendarConstraints.DateValidator {
              ...

             //this code not work correctly
              override fun isValid(date: Long): Boolean {
                   val calendar = Calendar.getInstance()
                if (initTime == 0.toLong())
                    initTime = System.currentTimeMillis()
                return if (System.currentTimeMillis() > initTime + 1000) {
                    Log.e("DateActivity", "isValid: 크다")
                    if (firstOrder == 0) {
                        firstSelect = date
                        firstOrder++
                        calendar.time = Date(firstSelect)
                        calendar.add(Calendar.MONTH, 6)
                    }
                    val remainDate = Calendar.getInstance()
                    remainDate.time = Date(date)
                    calendar > remainDate
                } else {
                    Log.e("DateActivity", "isValid: 크지 않다.")
                    true
                }
              }
        }

        builder.setCalendarConstraints(constDate.build())
        val picker = builder.build()

By time difference(System.currentTimeMillis()) try to catch first selection but when swipe picker other date catched in override fun isValid() . so I tried setOnTouchListener{} but no found way picker's setOnTouchListener in override fun isValid() cause picker built after CalendarConstraints set.

This is just static validation. I Think.

{ ссылка }
{ ссылка }

...