new version 3.1.5 , fixed the bug where check out is showing after check in
This commit is contained in:
@@ -16,7 +16,7 @@ android {
|
||||
targetSdk = 34
|
||||
versionCode = 11
|
||||
|
||||
versionName = "3.1.4"
|
||||
versionName = "3.1.5"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
|
||||
@@ -14,11 +14,11 @@ import `in`.sminnovations.attendanceapp.utils.AppUpdater
|
||||
import `in`.sminnovations.attendanceapp.utils.NetworkMonitor
|
||||
import `in`.sminnovations.attendanceapp.utils.UpdateChecker
|
||||
import `in`.sminnovations.attendanceapp.utils.UpdateInfo
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.collectLatest
|
||||
import kotlinx.coroutines.flow.update
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.tasks.await
|
||||
@@ -67,7 +67,6 @@ class HomeViewModel @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
// In your ViewModel, assume:
|
||||
|
||||
|
||||
fun installUpdate(url: String) {
|
||||
@@ -106,20 +105,18 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
init {
|
||||
networkMonitor.startMonitoring()
|
||||
networkMonitor.isConnected.asFlow().onEach { isConnected ->
|
||||
_uiState.update { currentState ->
|
||||
currentState.copy(isConnected = isConnected)
|
||||
}
|
||||
}.launchIn(viewModelScope)
|
||||
if (uiState.value.isConnected) {
|
||||
viewModelScope.launch {
|
||||
startScanning()
|
||||
viewModelScope.launch {
|
||||
networkMonitor.isConnected.asFlow().collectLatest { isConnected ->
|
||||
_uiState.update { it.copy(isConnected = isConnected) }
|
||||
if (isConnected) {
|
||||
startScanning()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
fun reStartMonitoring() {
|
||||
networkMonitor.startMonitoring()
|
||||
}
|
||||
@@ -162,7 +159,6 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
private fun processQRCode(userId: String) {
|
||||
if (userId.isBlank()) return
|
||||
|
||||
viewModelScope.launch {
|
||||
try {
|
||||
setLoading(true)
|
||||
@@ -172,12 +168,13 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
// Fetch Employee Document
|
||||
val employeeDoc = getEmployeeDocument(userId)
|
||||
delay(200L)
|
||||
if (employeeDoc == null) {
|
||||
handleError("Invalid employee ID")
|
||||
return@launch
|
||||
}
|
||||
|
||||
if (!employeeDoc.getBoolean("EmployeeStatus")!!) {
|
||||
if (employeeDoc.getBoolean("EmployeeStatus") != true) {
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
userName = employeeDoc.getString("Name"),
|
||||
@@ -195,10 +192,13 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
if (attendanceDoc?.exists() == true) {
|
||||
handleExistingAttendance(attendanceDoc)
|
||||
_uiState.update { it.copy(isCheckedOut = true, qrCodeValue = null) }
|
||||
} else {
|
||||
handleNewAttendance(userId, currentDate)
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (e: Exception) {
|
||||
handleError("An error occurred: ${e.message}")
|
||||
} finally {
|
||||
@@ -269,23 +269,35 @@ class HomeViewModel @Inject constructor(
|
||||
val data = document.data ?: return
|
||||
val checkIns = data.filterKeys { it.startsWith("checkIn") }.size
|
||||
val checkOuts = data.filterKeys { it.startsWith("checkOut") }.size
|
||||
val checkIn = document.getString("checkIn$checkIns")!!
|
||||
if (isTimeDifferenceGreaterThanSec(givenTimeStr = checkIn, currentTimeStr = formatTimestamp(Timestamp.now()), secVal = 5L)) {
|
||||
if (!isTimeDifferenceGreaterThanMinutes(
|
||||
givenTimeStr = checkIn,
|
||||
currentTimeStr = formatTimestamp(Timestamp.now()),
|
||||
minutesVal = 5L
|
||||
)
|
||||
) {
|
||||
handleError("Wait 5 minutes before logging off")
|
||||
} else {
|
||||
if (checkIns > checkOuts) {
|
||||
processCheckOut(document, checkIns)
|
||||
} else {
|
||||
processCheckIn(document, checkIns + 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delay(200L)
|
||||
|
||||
val currentTimestamp = formatTimestamp(Timestamp.now())
|
||||
|
||||
val checkIn = document.getString("checkIn$checkIns") ?: run {
|
||||
handleError("Missing check-in data")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
if (isTimeDifferenceGreaterThanSec(givenTimeStr = checkIn, currentTimeStr = currentTimestamp, secVal = 5L)) {
|
||||
if (!isTimeDifferenceGreaterThanMinutes(givenTimeStr = checkIn, currentTimeStr = currentTimestamp, minutesVal = 5L)) {
|
||||
handleError("Wait 5 minutes before logging off")
|
||||
return
|
||||
} else {
|
||||
if (checkIns > checkOuts) {
|
||||
processCheckOut(document, checkIns)
|
||||
} else {
|
||||
processCheckIn(document, checkIns + 1)
|
||||
}
|
||||
}
|
||||
}else{
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -342,8 +354,7 @@ class HomeViewModel @Inject constructor(
|
||||
|
||||
private suspend fun processCheckIn(document: DocumentSnapshot, checkInCount: Int) {
|
||||
try {
|
||||
document.reference.update("checkIn$checkInCount", formatTimestamp(Timestamp.now()))
|
||||
.await()
|
||||
document.reference.update("checkIn$checkInCount", formatTimestamp(Timestamp.now())).await()
|
||||
_uiState.update {
|
||||
it.copy(
|
||||
isCheckedIn = true, qrCodeValue = null
|
||||
|
||||
Reference in New Issue
Block a user