set the card color into green if the incubation time equals to 15. and it turns red if the incubation time equals 25,
This commit is contained in:
@@ -15,7 +15,7 @@ android {
|
||||
namespace 'in.sminnovations.hpostesting'
|
||||
|
||||
defaultConfig {
|
||||
applicationId "in.sminnovations.hpostesting.prod"
|
||||
applicationId "in.sminnovations.hpostesting"
|
||||
minSdk 21
|
||||
targetSdk 34
|
||||
versionCode 14
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.example.hpostesting.presentation.adapter
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.graphics.Color
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@@ -45,6 +46,14 @@ class UserListAdapter(
|
||||
userId.text = "User ID:${model._id} \n Time: ${isBetween15And30Minutes(model.incubationTime)}"
|
||||
btnStartIncubation.visibility = View.GONE
|
||||
}
|
||||
|
||||
if (isTimeEqualTotime(model.incubationTime, 15)) {
|
||||
userCard.setCardBackgroundColor(Color.GREEN)
|
||||
} else if (isTimeEqualTotime(model.incubationTime, 25)) {
|
||||
userCard.setCardBackgroundColor(Color.RED)
|
||||
}
|
||||
|
||||
|
||||
Glide.with(view).load(model.userImageURL).into(userImage)
|
||||
if (model.testStatus!!) {
|
||||
teststatus.text = "Test concluded"
|
||||
@@ -123,4 +132,23 @@ class UserListAdapter(
|
||||
|
||||
return diffMillis / (60 * 1000)
|
||||
}
|
||||
|
||||
|
||||
|
||||
private fun isTimeEqualTotime(createdAt: String, targetMinutes: Int): Boolean {
|
||||
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault())
|
||||
val createdAtDate: Date = formatter.parse(createdAt) ?: return false // Return false if parsing fails
|
||||
|
||||
val currentTime = Calendar.getInstance().time
|
||||
|
||||
val diffMillis = currentTime.time - createdAtDate.time
|
||||
val diffMinutes = diffMillis / (60 * 1000)
|
||||
|
||||
// Check if the difference in minutes is equal to the targetMinutes
|
||||
return diffMinutes.toInt() == targetMinutes
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user