From c47f75e9f24df585239229926d5fd0fbccb388df Mon Sep 17 00:00:00 2001
From: sathwikcs <85106054+sathwikcs@users.noreply.github.com>
Date: Wed, 11 Dec 2024 12:32:46 +0530
Subject: [PATCH] added the network check
---
.idea/other.xml | 2 +-
app/build.gradle.kts | 4 +-
.../screens/home/ui/componets/ErrorContent.kt | 128 ++++++++++++++++++
.../screens/home/ui/componets/permisions.kt | 42 ++++++
4 files changed, 173 insertions(+), 3 deletions(-)
create mode 100644 app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/ErrorContent.kt
create mode 100644 app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/permisions.kt
diff --git a/.idea/other.xml b/.idea/other.xml
index 49481ad..104e542 100644
--- a/.idea/other.xml
+++ b/.idea/other.xml
@@ -262,7 +262,7 @@
-
+
diff --git a/app/build.gradle.kts b/app/build.gradle.kts
index d834eb3..0e20fee 100644
--- a/app/build.gradle.kts
+++ b/app/build.gradle.kts
@@ -15,9 +15,9 @@ android {
applicationId = "in.sminnovations.attendanceapp.user"
minSdk = 26
targetSdk = 34
- versionCode = 3
+ versionCode = 4
- versionName = "3.0.1"
+ versionName = "3.0.2"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
diff --git a/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/ErrorContent.kt b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/ErrorContent.kt
new file mode 100644
index 0000000..751933b
--- /dev/null
+++ b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/ErrorContent.kt
@@ -0,0 +1,128 @@
+package `in`.sminnovations.attendanceapp.screens.home.ui.componets
+
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.OutlinedCard
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.buildAnnotatedString
+import androidx.compose.ui.text.withStyle
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+
+@Composable
+internal fun ErrorContent(
+ errorMessage: String,
+ userName: String?,
+ checkedOutTime: String
+) {
+
+ val errorExplanations = mapOf(
+ // Network and Data Access Errors
+ "Failed to fetch employee data" to "There was an issue retrieving your employee information. Please check your internet connection and try again.",
+ "Failed to fetch attendance data" to "Unable to retrieve attendance records. Please verify your internet connection and try again.",
+
+ // Employee Validation Errors
+ "Invalid employee ID" to "The scanned ID isn't recognized. Double-check the ID, and if the issue continues, contact your administrator.",
+ "Employee ID has expired" to "This ID is no longer active. Please contact HR to renew or reactivate your ID.",
+
+ // Attendance Process Errors
+ "Invalid attendance record" to "An unexpected issue occurred with your attendance record. Please contact support for assistance.",
+ "Already checked out for today." to "You've already completed your check-out for today. If you need to make corrections, please contact support.",
+ "Failed to check in" to "There was an issue recording your check-in. Please try again or contact support if the problem persists.",
+ "Failed to check out" to "There was an issue recording your check-out. Please try again or contact support if the problem persists.",
+
+ // Generic Error
+ "An error occurred" to "An unexpected error occurred. Please try again or contact support if the issue continues."
+ )
+
+
+ val detailedExplanation = errorExplanations[errorMessage] ?: "An unexpected error occurred."
+
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(20.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ // Only show the "Error Message for" text if we have a valid userName
+ if (!userName.isNullOrEmpty()) {
+ OutlinedCard(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(bottom = 16.dp)
+ ) {
+ Text(
+ text = buildAnnotatedString {
+ append("Error Message for ")
+ withStyle(style = SpanStyle(color = Color.Green)) {
+ append(userName)
+ }
+ },
+ style = MaterialTheme.typography.titleMedium,
+ modifier = Modifier.padding(16.dp)
+ )
+ }
+ }
+
+ OutlinedCard(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(bottom = 16.dp)
+ ) {
+ Text(
+ text = errorMessage,
+ style = MaterialTheme.typography.titleLarge,
+ color = MaterialTheme.colorScheme.error,
+ modifier = Modifier.padding(16.dp)
+ )
+ }
+
+ // Detailed explanation for the error
+ OutlinedCard(
+ modifier = Modifier
+ .fillMaxWidth()
+ .padding(bottom = if (checkedOutTime.isNotEmpty()) 16.dp else 0.dp)
+ ) {
+ Text(
+ letterSpacing = 2.sp,
+ lineHeight = 40.sp,
+ text = detailedExplanation,
+ fontSize = 18.sp,
+ style = MaterialTheme.typography.bodyMedium,
+ color = MaterialTheme.colorScheme.onSurface,
+ modifier = Modifier.padding(16.dp)
+ )
+ }
+
+ if (checkedOutTime.isNotEmpty()) {
+ OutlinedCard(
+ modifier = Modifier.fillMaxWidth()
+ ) {
+ Column(
+ modifier = Modifier.padding(16.dp),
+ horizontalAlignment = Alignment.CenterHorizontally
+ ) {
+ Text(
+ text = "Check Out Time",
+ style = MaterialTheme.typography.titleLarge
+ )
+ Spacer(modifier = Modifier.height(8.dp))
+ Text(
+ text = checkedOutTime,
+ style = MaterialTheme.typography.titleLarge,
+ color = Color.Green
+ )
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/permisions.kt b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/permisions.kt
new file mode 100644
index 0000000..7031193
--- /dev/null
+++ b/app/src/main/java/in/sminnovations/attendanceapp/screens/home/ui/componets/permisions.kt
@@ -0,0 +1,42 @@
+package `in`.sminnovations.attendanceapp.screens.home.ui.componets
+
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Button
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.text.style.TextAlign
+import androidx.compose.ui.unit.dp
+import com.google.accompanist.permissions.ExperimentalPermissionsApi
+import com.google.accompanist.permissions.PermissionState
+
+
+@OptIn(ExperimentalPermissionsApi::class)
+@Composable
+internal fun RequestPermissionsContent(cameraPermissionState: PermissionState) {
+ Column(
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(16.dp),
+ horizontalAlignment = Alignment.CenterHorizontally,
+ verticalArrangement = Arrangement.Center
+ ) {
+ Text(
+ text = "Camera Permission Required",
+ style = MaterialTheme.typography.headlineMedium,
+ textAlign = TextAlign.Center
+ )
+ Spacer(modifier = Modifier.height(16.dp))
+ Button(onClick = { cameraPermissionState.launchPermissionRequest() }) {
+ Text("Request Permission")
+ }
+ }
+}
+