Advertisement
Hanafi112

historyflag

Jun 20th, 2023
1,307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 4.18 KB | Source Code | 0 0
  1. private fun onClick() {
  2.     binding?.calendarViewHistory?.setOnDayClickListener(object : OnDayClickListener {
  3.         override fun onDayClick(eventDay: EventDay) {
  4.             val clickedDayCalendar = eventDay.calendar
  5.             binding?.tvCurrentDate?.text = clickedDayCalendar.toDate().toDay()
  6.             binding?.tvCurrentMonth?.text = clickedDayCalendar.toDate().toMonth()
  7.  
  8.             if (dataHistories != null) {
  9.                 var isCheckedIn = false
  10.                 var isCheckedOut = false
  11.                 for (dataHistory in dataHistories!!) {
  12.                     val updateDate = dataHistory?.updatedAt
  13.                     val calendarUpdated = updateDate?.fromTimeStampToDate()?.toCalendar()
  14.                     if (clickedDayCalendar.get(Calendar.DAY_OF_MONTH) == calendarUpdated?.get(Calendar.DAY_OF_MONTH)) {
  15.                         if (dataHistory.status == 1) {
  16.                             isCheckedIn = true
  17.                             isCheckedOut = true
  18.                             val checkInTime = dataHistory.detail?.get(0)?.createdAt.toString()
  19.                             val checkOutTime = dataHistory.detail?.get(1)?.createdAt.toString()
  20.  
  21.                             binding?.tvTimeCheckIn?.text = checkInTime.fromTimeStampToDate()?.toTime()
  22.                             binding?.tvTimeCheckOut?.text = checkOutTime.fromTimeStampToDate()?.toTime()
  23.                             break
  24.                         } else {
  25.                             isCheckedIn = true
  26.                             val checkInTime = dataHistory.detail?.get(0)?.createdAt.toString()
  27.                             binding?.tvTimeCheckIn?.text = checkInTime.fromTimeStampToDate()?.toTime()
  28.                             break
  29.                         }
  30.                     }
  31.                 }
  32.                 if (!isCheckedIn) {
  33.                     binding?.tvTimeCheckIn?.text = getString(R.string.default_text)
  34.                 }
  35.                 if (!isCheckedOut) {
  36.                     binding?.tvTimeCheckOut?.text = getString(R.string.default_text)
  37.                 }
  38.             }
  39.         }
  40.     })
  41. }
  42. private fun onClick() {
  43.     binding?.calendarViewHistory?.setOnDayClickListener(object : OnDayClickListener {
  44.         override fun onDayClick(eventDay: EventDay) {
  45.             val clickedDayCalendar = eventDay.calendar
  46.             binding?.tvCurrentDate?.text = clickedDayCalendar.toDate().toDay()
  47.             binding?.tvCurrentMonth?.text = clickedDayCalendar.toDate().toMonth()
  48.  
  49.             if (dataHistories != null) {
  50.                 var isCheckedIn = false
  51.                 var isCheckedOut = false
  52.                 for (dataHistory in dataHistories!!) {
  53.                     val updateDate = dataHistory?.updatedAt
  54.                     val calendarUpdated = updateDate?.fromTimeStampToDate()?.toCalendar()
  55.                     if (clickedDayCalendar.get(Calendar.DAY_OF_MONTH) == calendarUpdated?.get(Calendar.DAY_OF_MONTH)) {
  56.                         if (dataHistory.status == 1) {
  57.                             isCheckedIn = true
  58.                             isCheckedOut = true
  59.                             val checkInTime = dataHistory.detail?.get(0)?.createdAt.toString()
  60.                             val checkOutTime = dataHistory.detail?.get(1)?.createdAt.toString()
  61.  
  62.                             binding?.tvTimeCheckIn?.text = checkInTime.fromTimeStampToDate()?.toTime()
  63.                             binding?.tvTimeCheckOut?.text = checkOutTime.fromTimeStampToDate()?.toTime()
  64.                             break
  65.                         } else {
  66.                             isCheckedIn = true
  67.                             val checkInTime = dataHistory.detail?.get(0)?.createdAt.toString()
  68.                             binding?.tvTimeCheckIn?.text = checkInTime.fromTimeStampToDate()?.toTime()
  69.                             break
  70.                         }
  71.                     }
  72.                 }
  73.                 if (!isCheckedIn) {
  74.                     binding?.tvTimeCheckIn?.text = getString(R.string.default_text)
  75.                 }
  76.                 if (!isCheckedOut) {
  77.                     binding?.tvTimeCheckOut?.text = getString(R.string.default_text)
  78.                 }
  79.             }
  80.         }
  81.     })
  82. }
  83.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement