From f00774af080d7ba13e09b54f7b2ece60aa58e2d0 Mon Sep 17 00:00:00 2001
From: sathwikcs <85106054+sathwikcs@users.noreply.github.com>
Date: Mon, 17 Mar 2025 17:49:13 +0530
Subject: [PATCH] new version 3.1.5 , fixed the bug where check out is showing
after check in
---
.idea/other.xml | 55 +++++++++++++
app/build.gradle.kts | 2 +-
.../screens/home/viewModel/homeVM.kt | 77 +++++++++++--------
3 files changed, 100 insertions(+), 34 deletions(-)
diff --git a/.idea/other.xml b/.idea/other.xml
index e965764..22069ff 100644
--- a/.idea/other.xml
+++ b/.idea/other.xml
@@ -14,6 +14,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -102,6 +113,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -267,6 +289,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -300,6 +333,17 @@
+
+
+
+
+
+
+
+
+
+
+
@@ -488,6 +532,17 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index 79df26c..d3e61da 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -16,7 +16,7 @@ android {
targetSdk = 34
versionCode = 11
- versionName = "3.1.4"
+ versionName = "3.1.5"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
diff --git a/app/src/main/java/in/sminnovations/attendanceapp/screens/home/viewModel/homeVM.kt b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/viewModel/homeVM.kt
index 3638325..ab493b3 100644
--- a/app/src/main/java/in/sminnovations/attendanceapp/screens/home/viewModel/homeVM.kt
+++ b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/viewModel/homeVM.kt
@@ -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