MainScreen.kt

This commit is contained in:
sathwikcs
2025-01-27 18:00:26 +05:30
parent 77e9f5d2ac
commit f41af9f130
2 changed files with 14 additions and 18 deletions

View File

@@ -5,10 +5,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import `in`.sminnovations.attendanceapp.navigation.BottomNavigationBar
import `in`.sminnovations.attendanceapp.navigation.Navigation
import `in`.sminnovations.attendanceapp.navigation.data.navItems
import `in`.sminnovations.attendanceapp.screens.home.ui.HomeScreen

View File

@@ -28,7 +28,7 @@ import javax.inject.Inject
@HiltViewModel
class HomeViewModel @Inject constructor(
private val applicationContext: Context,
applicationContext: Context,
private val firebaseFirestore: FirebaseFirestore,
private val networkMonitor: NetworkMonitor
) : ViewModel() {
@@ -42,7 +42,7 @@ class HomeViewModel @Inject constructor(
private val _isUpdateDialogVisible = MutableStateFlow(false)
val isUpdateDialogVisible = _isUpdateDialogVisible.asStateFlow()
private val _downloadProgress = MutableStateFlow<Boolean>(false)
private val _downloadProgress = MutableStateFlow(false)
val downloadProgress = _downloadProgress.asStateFlow()
private val appUpdater = AppUpdater(applicationContext)
@@ -55,13 +55,13 @@ class HomeViewModel @Inject constructor(
_isUpdateDialogVisible.value = true
}
}
.onFailure { error ->
.onFailure { _ ->
// Handle error
}
}
}
fun installUpdate(context: Context, url: String) {
fun installUpdate( url: String) {
appUpdater.downloadAndInstall(url)
viewModelScope.launch {
appUpdater.updateState.collect { state ->
@@ -117,7 +117,7 @@ class HomeViewModel @Inject constructor(
fun startScanning() {
viewModelScope.launch {
_uiState.update { currentState ->
_uiState.update { _ ->
AttendanceUiState( // Reset to completely fresh state
isScanning = true
)
@@ -185,7 +185,7 @@ class HomeViewModel @Inject constructor(
val attendanceDoc = getAttendanceDocument(userId, currentDate)
if (attendanceDoc?.exists() == true) {
handleExistingAttendance(userId, attendanceDoc)
handleExistingAttendance( attendanceDoc)
} else {
handleNewAttendance(userId, currentDate)
}
@@ -210,11 +210,11 @@ class HomeViewModel @Inject constructor(
}
}
private suspend fun handleExistingAttendance(userId: String, document: DocumentSnapshot) {
private suspend fun handleExistingAttendance( document: DocumentSnapshot) {
val checkOut = document.getString("checkOut")
when {
checkOut == "NA" -> processCheckOut(userId, document)
checkOut == "NA" -> processCheckOut( document)
checkOut != null -> {
_uiState.update {
it.copy(
@@ -248,7 +248,7 @@ class HomeViewModel @Inject constructor(
}
}
private suspend fun processCheckOut(userId: String, document: DocumentSnapshot) {
private suspend fun processCheckOut( document: DocumentSnapshot) {
try {
val checkOutData = hashMapOf(
"checkOut" to formatTimestamp(Timestamp.now()), "DayCompleted" to true
@@ -304,11 +304,11 @@ class HomeViewModel @Inject constructor(
}
fun isAppDisabled(): Boolean {
val a = firebaseFirestore.collection("deviceState").document("state")
println(a)
return true
}
// fun isAppDisabled(): Boolean {
// val a = firebaseFirestore.collection("deviceState").document("state")
// println(a)
// return true
// }
override fun onCleared() {
super.onCleared()