cards #8
5 changed files with 61 additions and 5 deletions
|
@ -66,6 +66,8 @@ dependencies {
|
|||
implementation("org.nanohttpd:nanohttpd:2.3.1")
|
||||
implementation("com.google.code.gson:gson:2.10.1")
|
||||
implementation("com.squareup.okhttp3:okhttp-android:5.0.0-alpha.14")
|
||||
implementation("com.journeyapps:zxing-android-embedded:4.3.0")
|
||||
implementation("com.google.zxing:core:3.5.3")
|
||||
testImplementation("junit:junit:4.13.2")
|
||||
androidTestImplementation("androidx.test.ext:junit:1.1.5")
|
||||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
<!-- Permissions -->
|
||||
|
||||
<!-- Internet -->
|
||||
<!-- Permissions: Internet -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||
|
@ -26,6 +26,10 @@
|
|||
android:usesPermissionFlags="neverForLocation"
|
||||
tools:targetApi="s" />
|
||||
|
||||
<!-- Permissions: Scan -->
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false"/>
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
|
||||
<!-- Applications -->
|
||||
|
||||
<!-- NOTE: usesCleartextTraffic is enabled because of the API system using simple HTTP -->
|
||||
|
@ -47,9 +51,12 @@
|
|||
android:theme="@style/Theme.Tasksvalider">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="com.google.zxing.client.android.SCAN"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
|
|
@ -6,9 +6,14 @@ import android.os.Bundle
|
|||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import com.faraphel.tasks_valider.connectivity.bwf.BwfManager
|
||||
import com.faraphel.tasks_valider.database.TaskDatabase
|
||||
import com.faraphel.tasks_valider.ui.screen.communication.CommunicationScreen
|
||||
import com.faraphel.tasks_valider.ui.screen.scan.qr.ScanBarcodeScreen
|
||||
import com.journeyapps.barcodescanner.BarcodeResult
|
||||
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
@ -22,9 +27,22 @@ class MainActivity : ComponentActivity() {
|
|||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
this.setContent {
|
||||
@Composable
|
||||
fun example() {
|
||||
val barcode = remember { mutableStateOf<BarcodeResult?>(null) }
|
||||
if (barcode.value == null) ScanBarcodeScreen(this, barcode)
|
||||
else Text("code: ${barcode.value!!.text}")
|
||||
}
|
||||
|
||||
example()
|
||||
}
|
||||
|
||||
/*
|
||||
this.setContent {
|
||||
CommunicationScreen(this)
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedRegisterReceiverFlag")
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.faraphel.tasks_valider.database.dao
|
|||
import androidx.room.Dao
|
||||
import androidx.room.Query
|
||||
import com.faraphel.tasks_valider.database.dao.base.BaseDao
|
||||
import com.faraphel.tasks_valider.database.entities.SessionEntity
|
||||
import com.faraphel.tasks_valider.database.entities.SubjectEntity
|
||||
import com.faraphel.tasks_valider.database.entities.TaskEntity
|
||||
|
||||
|
@ -23,5 +22,5 @@ interface SubjectDao : BaseDao<SubjectEntity> {
|
|||
* @param id the id of the subject
|
||||
*/
|
||||
@Query("SELECT * FROM ${TaskEntity.TABLE_NAME} WHERE subject_id = :id")
|
||||
fun getSessions(id: Long): List<SessionEntity>
|
||||
fun getTasks(id: Long): List<TaskEntity>
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package com.faraphel.tasks_valider.ui.screen.scan.qr
|
||||
|
||||
import android.app.Activity
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.google.zxing.BarcodeFormat
|
||||
import com.journeyapps.barcodescanner.BarcodeResult
|
||||
import com.journeyapps.barcodescanner.DecoratedBarcodeView
|
||||
import com.journeyapps.barcodescanner.DefaultDecoderFactory
|
||||
|
||||
/**
|
||||
* Screen to scan a Barcode / QR Code
|
||||
*/
|
||||
@Composable
|
||||
fun ScanBarcodeScreen(activity: Activity, barcode: MutableState<BarcodeResult?>) {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
// AndroidView is used because "DecoratedBarcodeView" only support the legacy view system
|
||||
AndroidView(factory = {
|
||||
DecoratedBarcodeView(activity).apply {
|
||||
this.decoderFactory = DefaultDecoderFactory(listOf(BarcodeFormat.QR_CODE))
|
||||
this.initializeFromIntent(activity.intent)
|
||||
this.decodeContinuous { result -> barcode.value = result }
|
||||
this.resume()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue