fixed so many issues regarding the qr state and check in checkout added date remember state and optimised code
This commit is contained in:
@@ -7,6 +7,7 @@ import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
@@ -17,6 +18,7 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
@@ -44,7 +46,6 @@ import `in`.sminnovations.attendanceapp.screens.home.ui.componets.QRCodeScannerS
|
||||
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.RequestPermissions
|
||||
import `in`.sminnovations.attendanceapp.screens.home.viewModel.HomeViewModel
|
||||
|
||||
|
||||
@OptIn(ExperimentalPermissionsApi::class, ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
@@ -53,7 +54,9 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
val checkInTime by viewModel.checkedIn.collectAsState()
|
||||
val checkOutTime by viewModel.checkedOut.collectAsState()
|
||||
val isCheckedIn by viewModel.isCheckedIn.collectAsState()
|
||||
|
||||
val isCheckedOut by viewModel.isCheckedOut.collectAsState()
|
||||
val isLoading by viewModel.isLoading.collectAsState()
|
||||
val errorMessage by viewModel.errorMessage.collectAsState()
|
||||
|
||||
val cameraPermissionState = rememberPermissionState(Manifest.permission.CAMERA)
|
||||
val locationPermissionState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
|
||||
@@ -92,12 +95,40 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedCard(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight(.47f)
|
||||
.align(Alignment.BottomCenter)
|
||||
.padding(10.dp), onClick = { }
|
||||
// Loading Indicator
|
||||
if (isLoading) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
|
||||
// Display Error Message
|
||||
errorMessage?.let { message ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.align(Alignment.BottomCenter)
|
||||
.padding(16.dp)
|
||||
) {
|
||||
Text(
|
||||
text = message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier
|
||||
.background(Color(0xFFFFCDD2)) // Light red background for error
|
||||
.padding(8.dp)
|
||||
.align(Alignment.Center)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
OutlinedCard(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight(.47f)
|
||||
.align(Alignment.BottomCenter)
|
||||
.padding(10.dp),
|
||||
onClick = { }
|
||||
) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(
|
||||
@@ -106,9 +137,20 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
.align(Alignment.TopCenter)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
AnimatedVisibility(visible = isCheckedIn) {
|
||||
errorMessage?.let { message ->
|
||||
Text(
|
||||
text = "You already checked it Scanning Again will logout",
|
||||
text = message,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
fontWeight = FontWeight.Bold,
|
||||
modifier = Modifier
|
||||
.background(Color(0xFFFFCDD2)) // Light red background for error
|
||||
.padding(8.dp)
|
||||
|
||||
)
|
||||
}
|
||||
AnimatedVisibility(visible = isCheckedIn && !isCheckedOut) {
|
||||
Text(
|
||||
text = "You already checked in. Scanning again will Check out.",
|
||||
letterSpacing = 2.sp,
|
||||
lineHeight = 40.sp,
|
||||
fontSize = 30.sp,
|
||||
@@ -116,7 +158,7 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
}
|
||||
androidx.compose.animation.AnimatedVisibility(visible = !isCheckedIn) {
|
||||
AnimatedVisibility(visible = !isCheckedIn && !isCheckedOut) {
|
||||
Text(
|
||||
text = "Please Check In",
|
||||
letterSpacing = 2.sp,
|
||||
@@ -127,40 +169,47 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
||||
)
|
||||
}
|
||||
Column(Modifier.padding(15.dp)) {
|
||||
androidx.compose.animation.AnimatedVisibility(visible = !isCheckedIn) {
|
||||
Text(text = "Check in $checkInTime")
|
||||
AnimatedVisibility(visible = isCheckedIn || isCheckedOut) {
|
||||
Text(text = "Check-in: $checkInTime")
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
}
|
||||
androidx.compose.animation.AnimatedVisibility(visible = isCheckedIn) {
|
||||
Text(text = "Check Out$checkOutTime")
|
||||
AnimatedVisibility(visible = (isCheckedIn && isCheckedOut) || isCheckedOut ) {
|
||||
Text(text = "Check-out: $checkOutTime")
|
||||
Spacer(modifier = Modifier.height(10.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Column(Modifier.align(Alignment.BottomCenter)) {
|
||||
LargeButton(text = if (isScanning) "Close" else "Scan",
|
||||
LargeButton(
|
||||
text = if (isScanning) "Close" else "Scan",
|
||||
onClick = if (isScanning) {
|
||||
{ viewModel.stopScanning() }
|
||||
} else {
|
||||
{ viewModel.startScanning() }
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(bottom = 24.dp))
|
||||
if (isScanning) {
|
||||
BackHandler { viewModel.stopScanning() }
|
||||
}
|
||||
|
||||
LargeButton(
|
||||
text = "Login", onClick = {
|
||||
viewModel.loginNow()
|
||||
}, modifier = Modifier
|
||||
.padding(bottom = 24.dp)
|
||||
modifier = Modifier.padding(bottom = 24.dp)
|
||||
)
|
||||
if (isScanning) {
|
||||
BackHandler { viewModel.stopScanning() }
|
||||
}
|
||||
|
||||
AnimatedVisibility(visible = !isCheckedIn) {
|
||||
LargeButton(
|
||||
text = "Check In",
|
||||
onClick = { viewModel.loginNow() },
|
||||
modifier = Modifier.padding(bottom = 24.dp)
|
||||
)
|
||||
}
|
||||
AnimatedVisibility(visible = isCheckedIn ) {
|
||||
LargeButton(
|
||||
text = "Check Out",
|
||||
onClick = { viewModel.loginNow() },
|
||||
modifier = Modifier.padding(bottom = 24.dp)
|
||||
)
|
||||
}
|
||||
if (isScanning) {
|
||||
BackHandler { viewModel.stopScanning() }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user