Compare commits
3 Commits
2024-04-12
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
30ab8e2fe9 | ||
|
cf9e8b483c | ||
|
4914bc3666 |
@ -1,6 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
|
||||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<component name="ProjectType">
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="VcsDirectoryMappings">
|
<component name="VcsDirectoryMappings">
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
<mapping directory="" vcs="Git" />
|
||||||
</component>
|
</component>
|
||||||
</project>
|
</project>
|
@ -1,6 +1,7 @@
|
|||||||
package it.edu.cassandroferminervi.flowschool.remote
|
package it.edu.cassandroferminervi.flowschool.remote
|
||||||
|
|
||||||
import it.edu.cassandroferminervi.flowschool.remote.dto.LoginResult
|
import it.edu.cassandroferminervi.flowschool.remote.dto.LoginResult
|
||||||
|
import it.edu.cassandroferminervi.flowschool.remote.dto.PresenceResult
|
||||||
import it.edu.cassandroferminervi.flowschool.remote.dto.TeacherInfoResult
|
import it.edu.cassandroferminervi.flowschool.remote.dto.TeacherInfoResult
|
||||||
import retrofit2.Response
|
import retrofit2.Response
|
||||||
import retrofit2.http.Field
|
import retrofit2.http.Field
|
||||||
@ -17,14 +18,17 @@ interface ApiService {
|
|||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("presenza.php")
|
@POST("presenza.php")
|
||||||
suspend fun postPresence(@Field("token") token: String): Response<Boolean>
|
suspend fun postPresence(
|
||||||
|
@Field("token") token: String,
|
||||||
|
@Field("codice") qrcode: String
|
||||||
|
): Response<PresenceResult>
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("lista.php")
|
@POST("lista.php")
|
||||||
suspend fun postTeacherList(@Field("token") token: String): Response<List<TeacherInfoResult>>
|
suspend fun postTeacherList(@Field("token") token: String): Response<List<TeacherInfoResult>>
|
||||||
|
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("ricerca.php")
|
@POST("ottieni_prof.php")
|
||||||
suspend fun postTeacherInfo(
|
suspend fun postTeacherInfo(
|
||||||
@Field("token") token: String,
|
@Field("token") token: String,
|
||||||
@Field("profId") teacherId: Int
|
@Field("profId") teacherId: Int
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
package it.edu.cassandroferminervi.flowschool.remote.dto
|
||||||
|
|
||||||
|
import androidx.annotation.Keep
|
||||||
|
|
||||||
|
@Keep
|
||||||
|
data class PresenceResult(val success: Boolean)
|
@ -14,10 +14,11 @@ import androidx.compose.ui.platform.LocalContext
|
|||||||
import androidx.compose.ui.platform.LocalLifecycleOwner
|
import androidx.compose.ui.platform.LocalLifecycleOwner
|
||||||
import androidx.compose.ui.viewinterop.AndroidView
|
import androidx.compose.ui.viewinterop.AndroidView
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
import it.edu.cassandroferminervi.flowschool.util.QrAnalyzer
|
import it.edu.cassandroferminervi.flowschool.util.QrAnalyzer
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun CameraScreen() {
|
fun CameraScreen(navigator: DestinationsNavigator, token: String) {
|
||||||
val localContext = LocalContext.current
|
val localContext = LocalContext.current
|
||||||
val lifecycleOwner = LocalLifecycleOwner.current
|
val lifecycleOwner = LocalLifecycleOwner.current
|
||||||
val cameraProviderFuture = remember {
|
val cameraProviderFuture = remember {
|
||||||
@ -37,7 +38,7 @@ fun CameraScreen() {
|
|||||||
val imageAnalysis = ImageAnalysis.Builder().build()
|
val imageAnalysis = ImageAnalysis.Builder().build()
|
||||||
imageAnalysis.setAnalyzer(
|
imageAnalysis.setAnalyzer(
|
||||||
ContextCompat.getMainExecutor(context),
|
ContextCompat.getMainExecutor(context),
|
||||||
QrAnalyzer(context)
|
QrAnalyzer(context, navigator, token)
|
||||||
)
|
)
|
||||||
|
|
||||||
runCatching {
|
runCatching {
|
||||||
|
@ -1,12 +1,18 @@
|
|||||||
package it.edu.cassandroferminervi.flowschool.screens
|
package it.edu.cassandroferminervi.flowschool.screens
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
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.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Button
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
|
import androidx.compose.material3.ElevatedCard
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
@ -24,18 +30,79 @@ fun HomeScreen(navigator: DestinationsNavigator, token: String) {
|
|||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(horizontal = 50.dp)
|
|
||||||
) {
|
) {
|
||||||
Button(onClick = {
|
ElevatedCard(
|
||||||
navigator.navigate(PermissionScreenDestination(token))
|
elevation = CardDefaults.cardElevation(
|
||||||
}, modifier = Modifier.align(Alignment.CenterHorizontally)) {
|
defaultElevation = 6.dp
|
||||||
Text("Scannerizza codice QR")
|
),
|
||||||
|
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxHeight(0.5F)
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(25.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Scannerizza codice QR",
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"Scannerizzando il codice QR generato dinamicamente dal dispositivo situato nella scuola ti permette di segnare la presenza in modo efficiente.",
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
navigator.navigate(PermissionScreenDestination(token))
|
||||||
|
}, modifier = Modifier
|
||||||
|
.align(Alignment.BottomEnd)
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text("Prosegui")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Spacer(modifier = Modifier.height(8.dp))
|
Spacer(modifier = Modifier.height(8.dp))
|
||||||
Button(onClick = {
|
ElevatedCard(
|
||||||
navigator.navigate(SearchingScreenDestination(token))
|
elevation = CardDefaults.cardElevation(
|
||||||
}, modifier = Modifier.align(Alignment.CenterHorizontally)) {
|
defaultElevation = 6.dp
|
||||||
Text("Cerca professore")
|
),
|
||||||
|
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxHeight()
|
||||||
|
.fillMaxWidth()
|
||||||
|
.padding(25.dp)
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
"Cerca professore",
|
||||||
|
style = MaterialTheme.typography.headlineMedium,
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
Text(
|
||||||
|
"Cerca il professore sul quale vuoi ottenere informazioni come l'orario di entrata, l'orario di uscita e la classe in cui presiede attualmente.",
|
||||||
|
modifier = Modifier
|
||||||
|
.padding(16.dp)
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
|
) {
|
||||||
|
Button(
|
||||||
|
onClick = {
|
||||||
|
navigator.navigate(SearchingScreenDestination(token))
|
||||||
|
}, modifier = Modifier
|
||||||
|
.align(Alignment.BottomEnd)
|
||||||
|
.padding(16.dp)
|
||||||
|
) {
|
||||||
|
Text("Prosegui")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,15 +12,16 @@ import com.google.accompanist.permissions.isGranted
|
|||||||
import com.google.accompanist.permissions.rememberPermissionState
|
import com.google.accompanist.permissions.rememberPermissionState
|
||||||
import com.google.accompanist.permissions.shouldShowRationale
|
import com.google.accompanist.permissions.shouldShowRationale
|
||||||
import com.ramcosta.composedestinations.annotation.Destination
|
import com.ramcosta.composedestinations.annotation.Destination
|
||||||
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
|
|
||||||
@OptIn(ExperimentalPermissionsApi::class)
|
@OptIn(ExperimentalPermissionsApi::class)
|
||||||
@Destination
|
@Destination
|
||||||
@Composable
|
@Composable
|
||||||
fun PermissionScreen(token: String) {
|
fun PermissionScreen(navigator: DestinationsNavigator, token: String) {
|
||||||
val cameraPermissionState = rememberPermissionState(android.Manifest.permission.CAMERA)
|
val cameraPermissionState = rememberPermissionState(android.Manifest.permission.CAMERA)
|
||||||
|
|
||||||
if (cameraPermissionState.status.isGranted) {
|
if (cameraPermissionState.status.isGranted) {
|
||||||
CameraScreen()
|
CameraScreen(navigator, token)
|
||||||
} else {
|
} else {
|
||||||
Box(
|
Box(
|
||||||
contentAlignment = Alignment.Center,
|
contentAlignment = Alignment.Center,
|
||||||
|
@ -9,8 +9,14 @@ import com.google.mlkit.vision.barcode.BarcodeScannerOptions
|
|||||||
import com.google.mlkit.vision.barcode.BarcodeScanning
|
import com.google.mlkit.vision.barcode.BarcodeScanning
|
||||||
import com.google.mlkit.vision.barcode.common.Barcode
|
import com.google.mlkit.vision.barcode.common.Barcode
|
||||||
import com.google.mlkit.vision.common.InputImage
|
import com.google.mlkit.vision.common.InputImage
|
||||||
|
import com.ramcosta.composedestinations.HomeScreenDestination
|
||||||
|
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
|
||||||
|
import it.edu.cassandroferminervi.flowschool.remote.RetrofitInstance
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class QrAnalyzer(private val context: Context) : ImageAnalysis.Analyzer {
|
class QrAnalyzer(private val context: Context, private val navigator: DestinationsNavigator, val token: String) : ImageAnalysis.Analyzer {
|
||||||
private val options = BarcodeScannerOptions.Builder()
|
private val options = BarcodeScannerOptions.Builder()
|
||||||
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
|
.setBarcodeFormats(Barcode.FORMAT_QR_CODE)
|
||||||
.build()
|
.build()
|
||||||
@ -29,7 +35,18 @@ class QrAnalyzer(private val context: Context) : ImageAnalysis.Analyzer {
|
|||||||
barcode?.takeIf { it.isNotEmpty() }
|
barcode?.takeIf { it.isNotEmpty() }
|
||||||
?.mapNotNull { it.rawValue }
|
?.mapNotNull { it.rawValue }
|
||||||
?.joinToString(",")
|
?.joinToString(",")
|
||||||
?.let { Toast.makeText(context, it, Toast.LENGTH_SHORT).show() }
|
?.let {
|
||||||
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
|
val response = RetrofitInstance.api.postPresence(token, it)
|
||||||
|
val resBody = response.body()
|
||||||
|
|
||||||
|
if (resBody != null && resBody.success) {
|
||||||
|
navigator.navigate(HomeScreenDestination(token))
|
||||||
|
} else {
|
||||||
|
Toast.makeText(context, "Errore", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}.addOnCompleteListener {
|
}.addOnCompleteListener {
|
||||||
imageProxy.close()
|
imageProxy.close()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user