|
|
@@ -1,15 +1,24 @@
|
|
|
package com.iscs.bozzys.ui.pages.detail.task
|
|
|
|
|
|
+import android.Manifest
|
|
|
+import android.app.PendingIntent
|
|
|
import android.content.Context
|
|
|
import android.content.Intent
|
|
|
+import android.nfc.NfcAdapter
|
|
|
+import android.nfc.Tag
|
|
|
import android.os.Build
|
|
|
+import android.os.Bundle
|
|
|
+import androidx.activity.viewModels
|
|
|
import androidx.compose.foundation.background
|
|
|
+import androidx.compose.foundation.horizontalScroll
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
|
|
import androidx.compose.foundation.layout.FlowRow
|
|
|
import androidx.compose.foundation.layout.PaddingValues
|
|
|
import androidx.compose.foundation.layout.Row
|
|
|
+import androidx.compose.foundation.layout.aspectRatio
|
|
|
+import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
@@ -30,13 +39,16 @@ import androidx.compose.runtime.collectAsState
|
|
|
import androidx.compose.runtime.getValue
|
|
|
import androidx.compose.ui.Alignment
|
|
|
import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.draw.alpha
|
|
|
import androidx.compose.ui.draw.clip
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.layout.ContentScale
|
|
|
import androidx.compose.ui.res.painterResource
|
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
|
import androidx.compose.ui.unit.dp
|
|
|
import androidx.compose.ui.unit.sp
|
|
|
-import androidx.lifecycle.viewmodel.compose.viewModel
|
|
|
+import androidx.core.app.ActivityCompat
|
|
|
+import coil.compose.AsyncImage
|
|
|
import com.iscs.bozzys.R
|
|
|
import com.iscs.bozzys.api.Task
|
|
|
import com.iscs.bozzys.ui.common.PageBase
|
|
|
@@ -63,6 +75,11 @@ class PageDetailTask : PageBase() {
|
|
|
// 页面携带数据对象
|
|
|
private lateinit var task: Task
|
|
|
|
|
|
+ private lateinit var nfcAdapter: NfcAdapter
|
|
|
+ private lateinit var nfcPendingIntent: PendingIntent
|
|
|
+ private val vm: VMDetailTask by viewModels()
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取页面携带的数据
|
|
|
*/
|
|
|
@@ -76,10 +93,48 @@ class PageDetailTask : PageBase() {
|
|
|
return true
|
|
|
}
|
|
|
|
|
|
+ override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
+ super.onCreate(savedInstanceState)
|
|
|
+ nfcAdapter = NfcAdapter.getDefaultAdapter(this)
|
|
|
+ nfcPendingIntent = PendingIntent.getActivity(
|
|
|
+ this,
|
|
|
+ 0,
|
|
|
+ Intent(this, javaClass).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
|
|
|
+ PendingIntent.FLAG_MUTABLE
|
|
|
+ )
|
|
|
+ val permissions = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
|
+ arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT)
|
|
|
+ } else {
|
|
|
+ arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
|
|
|
+ }
|
|
|
+ ActivityCompat.requestPermissions(this, permissions, 12)
|
|
|
+ vm.onAddTaskListener()
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onResume() {
|
|
|
+ super.onResume()
|
|
|
+ nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, null, null)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onPause() {
|
|
|
+ super.onPause()
|
|
|
+ nfcAdapter.disableForegroundDispatch(this)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onNewIntent(intent: Intent) {
|
|
|
+ super.onNewIntent(intent)
|
|
|
+ val rfid = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG) ?: return
|
|
|
+ vm.updateRfid(rfid)
|
|
|
+ }
|
|
|
+
|
|
|
+ override fun onDestroy() {
|
|
|
+ super.onDestroy()
|
|
|
+ vm.onRemoveTaskListener()
|
|
|
+ }
|
|
|
+
|
|
|
@Composable
|
|
|
override fun GetViews(pv: PaddingValues) {
|
|
|
if (!getPageData()) return
|
|
|
- val vm: VMDetailTask = viewModel()
|
|
|
LaunchedEffect(Unit) {
|
|
|
vm.toast.initToast()
|
|
|
vm.loading.initLoading()
|
|
|
@@ -292,25 +347,166 @@ class PageDetailTask : PageBase() {
|
|
|
*/
|
|
|
@Composable
|
|
|
fun TaskDevice(vm: VMDetailTask) {
|
|
|
- CardBox(
|
|
|
- Modifier
|
|
|
- .padding(top = 10.dp)
|
|
|
- .fillMaxWidth()
|
|
|
- ) {
|
|
|
+ val state by vm.state.collectAsState()
|
|
|
+// CardBox(
|
|
|
+// Modifier
|
|
|
+// .padding(top = 10.dp)
|
|
|
+// .fillMaxWidth()
|
|
|
+// ) {
|
|
|
+// Column(
|
|
|
+// Modifier
|
|
|
+// .fillMaxWidth()
|
|
|
+// .height(120.dp),
|
|
|
+// horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
+// verticalArrangement = Arrangement.Center
|
|
|
+// ) {
|
|
|
+// Icon(
|
|
|
+// painter = painterResource(R.drawable.job_warning),
|
|
|
+// contentDescription = null,
|
|
|
+// modifier = Modifier.size(60.dp),
|
|
|
+// tint = MaterialTheme.colorScheme.primary
|
|
|
+// )
|
|
|
+// Text("请前往锁控柜进行取锁,取钥匙操作", fontSize = 14.sp, color = Text)
|
|
|
+// }
|
|
|
+// }
|
|
|
+ // 点位信息
|
|
|
+ CardBox(Modifier.padding(top = 10.dp)) {
|
|
|
+ Column(
|
|
|
+ Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(10.dp)
|
|
|
+ ) {
|
|
|
+ Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
+ Icon(
|
|
|
+ painterResource(R.drawable.location),
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 5.dp)
|
|
|
+ .size(16.dp),
|
|
|
+ tint = MaterialTheme.colorScheme.primary
|
|
|
+ )
|
|
|
+ Text("隔离点位", fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Text)
|
|
|
+ }
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 8.dp)
|
|
|
+ .height(80.dp)
|
|
|
+ .fillMaxWidth()
|
|
|
+ .horizontalScroll(rememberScrollState())
|
|
|
+ ) {
|
|
|
+ state.node.points?.forEach {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 10.dp)
|
|
|
+ .fillMaxHeight()
|
|
|
+ .aspectRatio(1f)
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .background(Color(0xFFFFF8E6)),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ AsyncImage(
|
|
|
+ it.pointIcon,
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier.size(40.dp),
|
|
|
+ contentScale = ContentScale.Fit
|
|
|
+ )
|
|
|
+ Text(it.pointName ?: "", fontSize = 12.sp, lineHeight = 12.sp, modifier = Modifier.padding(top = 10.dp), color = Text)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 所需设备
|
|
|
+ CardBox(Modifier.padding(top = 10.dp)) {
|
|
|
Column(
|
|
|
Modifier
|
|
|
.fillMaxWidth()
|
|
|
- .height(120.dp),
|
|
|
- horizontalAlignment = Alignment.CenterHorizontally,
|
|
|
- verticalArrangement = Arrangement.Center
|
|
|
+ .padding(10.dp)
|
|
|
) {
|
|
|
- Icon(
|
|
|
- painter = painterResource(R.drawable.job_warning),
|
|
|
- contentDescription = null,
|
|
|
- modifier = Modifier.size(60.dp),
|
|
|
- tint = MaterialTheme.colorScheme.primary
|
|
|
+ Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
+ Icon(
|
|
|
+ painterResource(R.drawable.return_device),
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 5.dp)
|
|
|
+ .size(16.dp),
|
|
|
+ tint = MaterialTheme.colorScheme.primary
|
|
|
+ )
|
|
|
+ Text(state.deviceInfo.first, fontSize = 16.sp, fontWeight = FontWeight.Bold, color = Text)
|
|
|
+ }
|
|
|
+ if (state.deviceInfo.second.isNotEmpty()) Text(
|
|
|
+ state.deviceInfo.second,
|
|
|
+ fontSize = 14.sp,
|
|
|
+ color = Text.copy(alpha = 0.5f),
|
|
|
+ modifier = Modifier.padding(start = 21.dp)
|
|
|
)
|
|
|
- Text("请前往锁控柜进行取锁,取钥匙操作", fontSize = 14.sp, color = Text)
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 8.dp)
|
|
|
+ .height(80.dp)
|
|
|
+ .fillMaxWidth()
|
|
|
+ .horizontalScroll(rememberScrollState())
|
|
|
+ ) {
|
|
|
+ state.keys.forEach {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 10.dp)
|
|
|
+ .fillMaxHeight()
|
|
|
+ .aspectRatio(1f)
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .background(Color(0xFFFFF8E6)),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(R.drawable.key),
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier
|
|
|
+ .size(40.dp)
|
|
|
+ .alpha(if (it.keyNfc.isEmpty()) 0.5f else 1f),
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ it.keyNfc.ifEmpty { "--" },
|
|
|
+ fontSize = 12.sp,
|
|
|
+ lineHeight = 12.sp,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 10.dp)
|
|
|
+ .alpha(if (it.keyNfc.isEmpty()) 0.5f else 1f),
|
|
|
+ color = Text
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ state.locks.forEach {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 10.dp)
|
|
|
+ .fillMaxHeight()
|
|
|
+ .aspectRatio(1f)
|
|
|
+ .clip(RoundedCornerShape(6.dp))
|
|
|
+ .background(Color(0xFFFFF8E6)),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(R.drawable.lock),
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier
|
|
|
+ .size(40.dp)
|
|
|
+ .alpha(if (it.lockNfc.isEmpty()) 0.5f else 1f),
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ it.lockNfc.ifEmpty { "--" },
|
|
|
+ fontSize = 12.sp,
|
|
|
+ lineHeight = 12.sp,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(top = 10.dp)
|
|
|
+ .alpha(if (it.lockNfc.isEmpty()) 0.5f else 1f),
|
|
|
+ color = Text
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -322,6 +518,7 @@ class PageDetailTask : PageBase() {
|
|
|
fun TaskOptions(pv: PaddingValues, vm: VMDetailTask) {
|
|
|
val pb = pv.calculateBottomPadding()
|
|
|
val state by vm.state.collectAsState()
|
|
|
+ if (state.node.id <= 0) return
|
|
|
Column(
|
|
|
Modifier
|
|
|
.padding(bottom = if (pb.value <= 0) 10.dp else pb)
|
|
|
@@ -439,6 +636,35 @@ class PageDetailTask : PageBase() {
|
|
|
Text("审核通过", fontSize = 16.sp, lineHeight = 16.sp, fontWeight = FontWeight.Bold, color = Color.White)
|
|
|
}
|
|
|
}
|
|
|
+ } else if (listOf("isolation", "releaseIsolation").contains(state.node.type) && state.btn.first.isNotEmpty()) {
|
|
|
+ Button(
|
|
|
+ { vm.sendTicket2Key() },
|
|
|
+ enabled = state.node.approvalStatus != "approved" && state.btn.second,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(horizontal = 8.dp)
|
|
|
+ .weight(1f)
|
|
|
+ .height(50.dp)
|
|
|
+ .clip(RoundedCornerShape(12.dp)),
|
|
|
+ shape = RoundedCornerShape(12.dp)
|
|
|
+ ) {
|
|
|
+ Row(verticalAlignment = Alignment.CenterVertically) {
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(R.drawable.job_finish),
|
|
|
+ contentDescription = null,
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(end = 8.dp)
|
|
|
+ .size(18.dp),
|
|
|
+ tint = Color.White
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ state.btn.first,
|
|
|
+ fontSize = 16.sp,
|
|
|
+ lineHeight = 16.sp,
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ color = Color.White
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|