初始代码提交
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
package com.sw.inbound
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.WindowManager
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.expandIn
|
||||
import androidx.compose.animation.shrinkOut
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.navigationBars
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.layout.windowInsetsBottomHeight
|
||||
import androidx.compose.foundation.layout.wrapContentWidth
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.ButtonDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.asImageBitmap
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import com.sw.inbound.utils.AppUtil
|
||||
import com.sw.inbound.utils.QRCodeUtil
|
||||
import com.sw.inbound.viewmodel.DeviceViewModel
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
/**
|
||||
* 设备初始化界面
|
||||
*/
|
||||
@AndroidEntryPoint
|
||||
class InitActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
||||
)
|
||||
setContent {
|
||||
InitScreen()
|
||||
}
|
||||
}
|
||||
|
||||
private var scale = 0.8F
|
||||
|
||||
private val qrCodeBmp by lazy {
|
||||
QRCodeUtil.generateQRCode(
|
||||
content = GlobalData.deviceId,
|
||||
size = (scale * 150).toInt()
|
||||
)
|
||||
}
|
||||
|
||||
@Preview(widthDp = 1920, heightDp = 1080)
|
||||
@Composable
|
||||
fun InitScreen(
|
||||
viewModel: DeviceViewModel = hiltViewModel<DeviceViewModel>()
|
||||
) {
|
||||
// val context = LocalContext.current
|
||||
val hasDeviceData = viewModel.checkEquipmentInfo()
|
||||
val deviceInfoResult = viewModel.deviceInfoResult.collectAsState()
|
||||
|
||||
if (hasDeviceData) {
|
||||
LaunchedEffect(this) {
|
||||
delay(1500)
|
||||
goLoginActivity()
|
||||
}
|
||||
} else {
|
||||
FirstPage(viewModel)
|
||||
}
|
||||
if (deviceInfoResult.value == true) {
|
||||
goLoginActivity()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Composable
|
||||
fun FirstPage(viewModel: DeviceViewModel) {
|
||||
Column(
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
modifier = Modifier.size(
|
||||
1920.dp, 1080.dp
|
||||
)
|
||||
) {
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.padding(top = (scale * 112).dp)
|
||||
.background(Color.White.copy(alpha = 0.0F))
|
||||
.size((scale * 337).dp, (scale * 322).dp)
|
||||
)
|
||||
|
||||
Button(
|
||||
onClick = {
|
||||
viewModel.getDeviceToken()
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
contentColor = Color.Transparent,
|
||||
containerColor = Color(0xFF08C6DC)
|
||||
),
|
||||
shape = RoundedCornerShape((scale * 8).dp),
|
||||
modifier = Modifier
|
||||
.width((scale * 225).dp)
|
||||
.padding(top = (scale * 75).dp)
|
||||
.padding((scale * 10).dp)
|
||||
) {
|
||||
Text(
|
||||
text = "设备初始化",
|
||||
color = Color.White,
|
||||
fontSize = (scale * 22).sp,
|
||||
fontWeight = FontWeight.Bold,
|
||||
)
|
||||
}
|
||||
Spacer(
|
||||
modifier = Modifier
|
||||
.wrapContentWidth()
|
||||
.weight(1F)
|
||||
)
|
||||
Image(
|
||||
bitmap = qrCodeBmp!!.asImageBitmap(),
|
||||
contentDescription = "",
|
||||
modifier = Modifier
|
||||
.padding(bottom = 10.dp)
|
||||
.size((scale * 150).dp, (scale * 150).dp)
|
||||
)
|
||||
Spacer(Modifier.windowInsetsBottomHeight(WindowInsets.navigationBars))
|
||||
}
|
||||
}
|
||||
// AnimatedVisibility(
|
||||
// visible = isSuccess.not(),
|
||||
// enter = expandIn(clip = false),
|
||||
// exit = shrinkOut(clip = false)
|
||||
// ) {}
|
||||
// fun initialize() {
|
||||
// var deviceId = AppUtil.getUDID(this)
|
||||
// deviceId = "6ce7cd59-b875-38b2-b73d-88a570be3212"
|
||||
// GlobalData.deviceId = deviceId
|
||||
// val isSuccess = deviceViewModel.checkEquipmentInfo()
|
||||
// if (isSuccess) {
|
||||
// goLoginActivity()
|
||||
// return
|
||||
// }
|
||||
// binding.ivQrCode.setImageBitmap(
|
||||
// QRCodeUtil.generateQRCode(
|
||||
// content = GlobalData.deviceId,
|
||||
// size = 200
|
||||
// )
|
||||
// )
|
||||
// binding.btnInit.setOnClickListener {
|
||||
// deviceViewModel.getDeviceToken()
|
||||
// }
|
||||
// }
|
||||
|
||||
private fun goLoginActivity() {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user