new version 3.1.5 , fixed the bug where check out is showing after check in
This commit is contained in:
55
.idea/other.xml
generated
55
.idea/other.xml
generated
@@ -14,6 +14,17 @@
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1280" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="OnePlus" />
|
||||
<option name="codename" value="OP5552L1" />
|
||||
<option name="id" value="OP5552L1" />
|
||||
<option name="manufacturer" value="OnePlus" />
|
||||
<option name="name" value="CPH2415" />
|
||||
<option name="screenDensity" value="480" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2412" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="OPPO" />
|
||||
@@ -102,6 +113,17 @@
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="1272" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="motorola" />
|
||||
<option name="codename" value="austin" />
|
||||
<option name="id" value="austin" />
|
||||
<option name="manufacturer" value="Motorola" />
|
||||
<option name="name" value="moto g 5G (2022)" />
|
||||
<option name="screenDensity" value="280" />
|
||||
<option name="screenX" value="720" />
|
||||
<option name="screenY" value="1600" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="33" />
|
||||
<option name="brand" value="samsung" />
|
||||
@@ -267,6 +289,17 @@
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2340" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="gta9pwifi" />
|
||||
<option name="id" value="gta9pwifi" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="SM-X210" />
|
||||
<option name="screenDensity" value="240" />
|
||||
<option name="screenX" value="1200" />
|
||||
<option name="screenY" value="1920" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
@@ -300,6 +333,17 @@
|
||||
<option name="screenX" value="1600" />
|
||||
<option name="screenY" value="2560" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="samsung" />
|
||||
<option name="codename" value="gts9fe" />
|
||||
<option name="id" value="gts9fe" />
|
||||
<option name="manufacturer" value="Samsung" />
|
||||
<option name="name" value="Galaxy Tab S9 FE 5G" />
|
||||
<option name="screenDensity" value="280" />
|
||||
<option name="screenX" value="1440" />
|
||||
<option name="screenY" value="2304" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="34" />
|
||||
<option name="brand" value="google" />
|
||||
@@ -488,6 +532,17 @@
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2424" />
|
||||
</PersistentDeviceSelectionData>
|
||||
<PersistentDeviceSelectionData>
|
||||
<option name="api" value="35" />
|
||||
<option name="brand" value="google" />
|
||||
<option name="codename" value="tokay" />
|
||||
<option name="id" value="tokay" />
|
||||
<option name="manufacturer" value="Google" />
|
||||
<option name="name" value="Pixel 9" />
|
||||
<option name="screenDensity" value="420" />
|
||||
<option name="screenX" value="1080" />
|
||||
<option name="screenY" value="2424" />
|
||||
</PersistentDeviceSelectionData>
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -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