personalised error message , now it shows the check out time if already checked Out
This commit is contained in:
@@ -7,17 +7,16 @@ import androidx.compose.animation.expandVertically
|
|||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.fadeIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.fadeOut
|
||||||
import androidx.compose.animation.shrinkVertically
|
import androidx.compose.animation.shrinkVertically
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.wrapContentHeight
|
||||||
import androidx.compose.foundation.layout.wrapContentSize
|
import androidx.compose.foundation.layout.wrapContentSize
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.ArrowBack
|
import androidx.compose.material.icons.filled.ArrowBack
|
||||||
@@ -37,14 +36,16 @@ import androidx.compose.runtime.remember
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
import androidx.compose.ui.text.SpanStyle
|
||||||
|
import androidx.compose.ui.text.buildAnnotatedString
|
||||||
import androidx.compose.ui.text.font.FontWeight
|
import androidx.compose.ui.text.font.FontWeight
|
||||||
|
import androidx.compose.ui.text.withStyle
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
import com.google.accompanist.permissions.ExperimentalPermissionsApi
|
||||||
import com.google.accompanist.permissions.isGranted
|
import com.google.accompanist.permissions.isGranted
|
||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.LargeButton
|
|
||||||
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.QRCodeScannerScreen
|
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.QRCodeScannerScreen
|
||||||
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.RequestPermissions
|
import `in`.sminnovations.attendanceapp.screens.home.ui.componets.RequestPermissions
|
||||||
import `in`.sminnovations.attendanceapp.screens.home.viewModel.HomeViewModel
|
import `in`.sminnovations.attendanceapp.screens.home.viewModel.HomeViewModel
|
||||||
@@ -55,6 +56,7 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
|||||||
val isScanning by viewModel.isScanning.collectAsState()
|
val isScanning by viewModel.isScanning.collectAsState()
|
||||||
val qrCodeValue by viewModel.qrCodeValue.collectAsState()
|
val qrCodeValue by viewModel.qrCodeValue.collectAsState()
|
||||||
val userName by viewModel.userName.collectAsState()
|
val userName by viewModel.userName.collectAsState()
|
||||||
|
val checkedOutTime by viewModel.checkedOut.collectAsState()
|
||||||
val isLoading by viewModel.isLoading.collectAsState()
|
val isLoading by viewModel.isLoading.collectAsState()
|
||||||
val isCheckedIn by viewModel.isCheckedIn.collectAsState()
|
val isCheckedIn by viewModel.isCheckedIn.collectAsState()
|
||||||
val isCheckedOut by viewModel.isCheckedOut.collectAsState()
|
val isCheckedOut by viewModel.isCheckedOut.collectAsState()
|
||||||
@@ -165,6 +167,71 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
errorMessage?.let { message ->
|
||||||
|
AnimatedVisibility(
|
||||||
|
visible = message != "" && message != null,
|
||||||
|
enter = expandVertically(expandFrom = Alignment.Bottom) + fadeIn(),
|
||||||
|
exit = shrinkVertically(shrinkTowards = Alignment.Bottom) + fadeOut()
|
||||||
|
) {
|
||||||
|
Box(
|
||||||
|
contentAlignment = Alignment.TopCenter,
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
.padding(20.dp)
|
||||||
|
) {
|
||||||
|
Column {
|
||||||
|
if (userName != null && userName != "") {
|
||||||
|
Text(
|
||||||
|
text = buildAnnotatedString {
|
||||||
|
append("This Error Message is for ")
|
||||||
|
withStyle(style = SpanStyle(color = Color.Green)) {
|
||||||
|
append(userName)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
color = MaterialTheme.colorScheme.error,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
letterSpacing = 2.sp,
|
||||||
|
lineHeight = 40.sp,
|
||||||
|
fontSize = 20.sp,
|
||||||
|
modifier = Modifier.padding(8.dp)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
OutlinedCard(
|
||||||
|
modifier = Modifier
|
||||||
|
.wrapContentSize()
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = message,
|
||||||
|
letterSpacing = 2.sp,
|
||||||
|
lineHeight = 40.sp,
|
||||||
|
fontSize = 30.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
modifier = Modifier.padding(10.dp, 7.dp),
|
||||||
|
color = MaterialTheme.colorScheme.error
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (checkedOutTime !="") {
|
||||||
|
Spacer(modifier = Modifier.height(15.dp))
|
||||||
|
Text(
|
||||||
|
text = "check Out Time",
|
||||||
|
lineHeight = 40.sp,
|
||||||
|
fontSize = 30.sp,
|
||||||
|
fontWeight = FontWeight.Bold
|
||||||
|
)
|
||||||
|
Spacer(modifier = Modifier.height(15.dp))
|
||||||
|
Text(
|
||||||
|
text = checkedOutTime,
|
||||||
|
lineHeight = 40.sp,
|
||||||
|
fontSize = 30.sp,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = Color.Green
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Loading Indicator
|
// Loading Indicator
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
@@ -177,48 +244,33 @@ fun HomeScreen(viewModel: HomeViewModel = hiltViewModel()) {
|
|||||||
|
|
||||||
OutlinedCard(modifier = Modifier
|
OutlinedCard(modifier = Modifier
|
||||||
.fillMaxWidth()
|
.fillMaxWidth()
|
||||||
.fillMaxHeight(.4f)
|
.wrapContentHeight()
|
||||||
.align(Alignment.BottomCenter)
|
.align(Alignment.BottomCenter)
|
||||||
.padding(10.dp), onClick = { }) {
|
.padding(10.dp), onClick ={
|
||||||
Box(modifier = Modifier.fillMaxSize()) {
|
if (isScanning) {
|
||||||
|
viewModel.stopScanning()
|
||||||
errorMessage?.let { message ->
|
} else {
|
||||||
OutlinedCard(
|
viewModel.startScanning()
|
||||||
modifier = Modifier
|
|
||||||
.wrapContentSize()
|
|
||||||
.align(Alignment.TopCenter)
|
|
||||||
.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)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
) {
|
||||||
|
Box(modifier = Modifier.fillMaxWidth()) {
|
||||||
Column(Modifier.align(Alignment.BottomCenter)) {
|
Column(Modifier.align(Alignment.BottomCenter)) {
|
||||||
Row(
|
Row(
|
||||||
Modifier.fillMaxWidth(),
|
Modifier
|
||||||
|
.wrapContentHeight()
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(bottom = 24.dp, top = 24.dp),
|
||||||
horizontalArrangement = Arrangement.Center,
|
horizontalArrangement = Arrangement.Center,
|
||||||
verticalAlignment = Alignment.CenterVertically
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
) {
|
) {
|
||||||
LargeButton(text = if (isScanning) "Close Scanner" else "Open Scanner",
|
Text(
|
||||||
onClick = if (isScanning) {
|
text = if (isScanning) "Close Scanner" else "Open Scanner",
|
||||||
{
|
fontSize = 18.sp,
|
||||||
viewModel.stopScanning()
|
fontWeight = FontWeight.Bold,
|
||||||
}
|
modifier =Modifier.padding(20.dp,10.dp)
|
||||||
} else {
|
)
|
||||||
{
|
|
||||||
viewModel.startScanning()
|
|
||||||
|
|
||||||
}
|
|
||||||
},
|
|
||||||
modifier = Modifier.padding(bottom = 24.dp))
|
|
||||||
}
|
}
|
||||||
LaunchedEffect(qrCodeValue) {
|
LaunchedEffect(qrCodeValue) {
|
||||||
viewModel.login()
|
viewModel.login()
|
||||||
|
|||||||
Reference in New Issue
Block a user