refactor: 注释移除 Compose 相关代码,统一入口替换为 HomeActivity

- 注释掉全部 Compose UI 代码(ui/、theme/、NavController、MainActivity、InitActivity 等)
- BorderExt、TextExt、ToastUtils、LoadingState 中的 Compose 逻辑全部注释
- LoadingState 保留 show()/hide() 空方法避免编译报错
- 注释 SensorScaleUtils、BaseViewModel、DeviceViewModel 中的 ToastUtils 调用
- BootReceiver、CrashHandler 中 MainActivity 替换为 HomeActivity
- UserViewModel、PurchaseOrderActivity 删除残余 Compose import
- build.gradle.kts 替换为非 Compose 的 activity-ktx 和 coil 依赖

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-06 09:28:55 +08:00
co-authored by Claude Sonnet 4.6
parent b6c7570efd
commit 2c3ebd86f9
34 changed files with 2691 additions and 2692 deletions
+19 -19
View File
@@ -11,7 +11,7 @@ plugins {
id("kotlin-parcelize")
// id("compose.compiler")
kotlin("kapt")
alias(libs.plugins.kotlin.compose)
// alias(libs.plugins.kotlin.compose)
}
android {
signingConfigs {
@@ -63,7 +63,7 @@ android {
jvmTarget = "11"
}
buildFeatures {
compose = true
// compose = true
viewBinding = true
buildConfig = true
}
@@ -83,12 +83,12 @@ dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation("androidx.activity:activity-ktx:1.8.0")
// implementation(platform(libs.androidx.compose.bom))
// implementation(libs.androidx.ui)
// implementation(libs.androidx.ui.graphics)
// implementation(libs.androidx.ui.tooling.preview)
// implementation(libs.androidx.material3)
implementation(
fileTree(
mapOf(
@@ -100,11 +100,11 @@ dependencies {
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
implementation(libs.androidx.navigation.compose)
// androidTestImplementation(platform(libs.androidx.compose.bom))
// androidTestImplementation(libs.androidx.ui.test.junit4)
// debugImplementation(libs.androidx.ui.tooling)
// debugImplementation(libs.androidx.ui.test.manifest)
// implementation(libs.androidx.navigation.compose)
// camerax
implementation(libs.androidx.camera.core)
@@ -114,12 +114,12 @@ dependencies {
implementation(libs.androidx.camera.extensions)
// 权限申请
implementation(libs.accompanist.permissions)
// implementation(libs.accompanist.permissions)
// hilt注入
implementation(libs.hilt.android)
ksp(libs.hilt.android.compiler)
implementation(libs.androidx.hilt.navigation.compose)
// implementation(libs.androidx.hilt.navigation.compose)
// retrofit网络请求
implementation(libs.retrofit)
@@ -131,8 +131,8 @@ dependencies {
implementation(libs.gson)
// 日志打印
implementation(libs.timber)
// 图片显示
implementation("io.coil-kt:coil-compose:2.4.0")
// 图片显示(非Compose标准版)
implementation("io.coil-kt:coil:2.4.0")
implementation(libs.core)
implementation(libs.android.core)
@@ -140,8 +140,8 @@ dependencies {
implementation("androidx.recyclerview:recyclerview:1.4.0")
implementation("androidx.compose.foundation:foundation:1.7.0")
implementation("androidx.compose.foundation:foundation-layout:1.7.0")
// implementation("androidx.compose.foundation:foundation:1.7.0")
// implementation("androidx.compose.foundation:foundation-layout:1.7.0")
implementation (libs.pytorch.android)
implementation (libs.pytorch.android.torchvision)
+181 -181
View File
@@ -1,183 +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
// )
//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
// )
// binding.btnInit.setOnClickListener {
// deviceViewModel.getDeviceToken()
// }
//// setContent {
//// InitScreen()
//// }
// }
private fun goLoginActivity() {
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
finish()
}
}
//
//// 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()
// }
//
//
//}
@@ -1,50 +1,50 @@
package com.sw.inbound
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.lifecycle.lifecycleScope
import com.sw.inbound.objbox.FoodModule
import com.sw.inbound.sdk.SensorScaleUtils
import com.sw.inbound.ui.AppScreen
import com.sw.inbound.utils.ThreadUtils
import com.sw.inbound.viewmodel.ReceiptViewModel
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.launch
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
val viewModel: ReceiptViewModel by viewModels()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
window.setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN
)
setContent {
AppScreen(onBackRequest = {
finish()
})
}
SensorScaleUtils.startScale(autoScale = true)
lifecycleScope.launch {
FoodModule.init(this@MainActivity)
}
}
override fun onDestroy() {
SensorScaleUtils.closeScale()
ThreadUtils.release()
super.onDestroy()
}
}
//package com.sw.inbound
//
//import android.os.Bundle
//import android.view.WindowManager
//import androidx.activity.ComponentActivity
////import androidx.activity.compose.setContent
//import androidx.activity.enableEdgeToEdge
//import androidx.activity.viewModels
//import androidx.lifecycle.lifecycleScope
//import com.sw.inbound.objbox.FoodModule
//import com.sw.inbound.sdk.SensorScaleUtils
////import com.sw.inbound.ui.AppScreen
//import com.sw.inbound.utils.ThreadUtils
//import com.sw.inbound.viewmodel.ReceiptViewModel
//import dagger.hilt.android.AndroidEntryPoint
//import kotlinx.coroutines.launch
//
//@AndroidEntryPoint
//class MainActivity : ComponentActivity() {
//
// val viewModel: ReceiptViewModel by viewModels()
//
// override fun onCreate(savedInstanceState: Bundle?) {
// super.onCreate(savedInstanceState)
// enableEdgeToEdge()
//
// window.setFlags(
// WindowManager.LayoutParams.FLAG_FULLSCREEN,
// WindowManager.LayoutParams.FLAG_FULLSCREEN
// )
//// setContent {
//// AppScreen(onBackRequest = {
//// finish()
//// })
//// }
// SensorScaleUtils.startScale(autoScale = true)
// lifecycleScope.launch {
// FoodModule.init(this@MainActivity)
// }
// }
//
// override fun onDestroy() {
// SensorScaleUtils.closeScale()
// ThreadUtils.release()
// super.onDestroy()
// }
//}
//
//
//
@@ -4,7 +4,6 @@ import android.annotation.SuppressLint
import android.os.Bundle
import com.sw.inbound.base.BaseActivity
import androidx.activity.viewModels
import androidx.compose.runtime.collectAsState
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.sw.inbound.R
@@ -1,44 +1,44 @@
package com.sw.inbound.ext
import androidx.compose.ui.Modifier
import androidx.compose.ui.composed
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.geometry.CornerRadius
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.PathEffect
import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
/**
* 虚线边框
*/
fun Modifier.dashedBorder(
strokeWidth: Dp = 2.dp,
color: Color = Color(0xFFDCDCF0),
cornerRadiusDp: Dp = 10.dp
) = composed(
factory = {
val density = LocalDensity.current
val strokeWidthPx = density.run { strokeWidth.toPx() }
val cornerRadiusPx = density.run { cornerRadiusDp.toPx() }
this.then(
Modifier.drawWithCache {
onDrawBehind {
val stroke = Stroke(
width = strokeWidthPx,
pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f)
)
drawRoundRect(
color = color,
style = stroke,
cornerRadius = CornerRadius(cornerRadiusPx)
)
}
}
)
}
)
//package com.sw.inbound.ext
//
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.composed
//import androidx.compose.ui.draw.drawWithCache
//import androidx.compose.ui.geometry.CornerRadius
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.graphics.PathEffect
//import androidx.compose.ui.graphics.drawscope.Stroke
//import androidx.compose.ui.platform.LocalDensity
//import androidx.compose.ui.unit.Dp
//import androidx.compose.ui.unit.dp
//
///**
// * 虚线边框
// */
//fun Modifier.dashedBorder(
// strokeWidth: Dp = 2.dp,
// color: Color = Color(0xFFDCDCF0),
// cornerRadiusDp: Dp = 10.dp
//) = composed(
// factory = {
// val density = LocalDensity.current
// val strokeWidthPx = density.run { strokeWidth.toPx() }
// val cornerRadiusPx = density.run { cornerRadiusDp.toPx() }
//
// this.then(
// Modifier.drawWithCache {
// onDrawBehind {
// val stroke = Stroke(
// width = strokeWidthPx,
// pathEffect = PathEffect.dashPathEffect(floatArrayOf(10f, 10f), 0f)
// )
//
// drawRoundRect(
// color = color,
// style = stroke,
// cornerRadius = CornerRadius(cornerRadiusPx)
// )
// }
// }
// )
// }
//)
+33 -33
View File
@@ -1,33 +1,33 @@
package com.sw.inbound.ext
import androidx.annotation.ColorRes
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.sp
// 快速修改颜色
fun TextStyle.withColor(color: Color): TextStyle = this.copy(color = color)
@Composable
fun TextStyle.withColorRes(@ColorRes colorRes: Int): TextStyle {
return this.copy(color = colorResource(id = colorRes))
}
// 快速修改字体大小
fun TextStyle.withSize(size: TextUnit): TextStyle = this.copy(fontSize = size)
fun TextStyle.withSizeSp(sp: Float): TextStyle = this.copy(fontSize = sp.sp)
// 快速修改字体粗细
fun TextStyle.withWeight(weight: FontWeight): TextStyle = this.copy(fontWeight = weight)
fun TextStyle.bold(): TextStyle = this.copy(fontWeight = FontWeight.Bold)
fun TextStyle.medium(): TextStyle = this.copy(fontWeight = FontWeight.Medium)
fun TextStyle.light(): TextStyle = this.copy(fontWeight = FontWeight.Light)
fun TextStyle.textAlign(textAlign: TextAlign): TextStyle = this.copy(textAlign = textAlign)
//package com.sw.inbound.ext
//
//import androidx.annotation.ColorRes
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.text.style.TextAlign
//import androidx.compose.ui.unit.TextUnit
//import androidx.compose.ui.unit.sp
//
//// 快速修改颜色
//fun TextStyle.withColor(color: Color): TextStyle = this.copy(color = color)
//
//@Composable
//fun TextStyle.withColorRes(@ColorRes colorRes: Int): TextStyle {
// return this.copy(color = colorResource(id = colorRes))
//}
//
//// 快速修改字体大小
//fun TextStyle.withSize(size: TextUnit): TextStyle = this.copy(fontSize = size)
//
//fun TextStyle.withSizeSp(sp: Float): TextStyle = this.copy(fontSize = sp.sp)
//
//// 快速修改字体粗细
//fun TextStyle.withWeight(weight: FontWeight): TextStyle = this.copy(fontWeight = weight)
//
//fun TextStyle.bold(): TextStyle = this.copy(fontWeight = FontWeight.Bold)
//fun TextStyle.medium(): TextStyle = this.copy(fontWeight = FontWeight.Medium)
//fun TextStyle.light(): TextStyle = this.copy(fontWeight = FontWeight.Light)
//
//fun TextStyle.textAlign(textAlign: TextAlign): TextStyle = this.copy(textAlign = textAlign)
@@ -1,19 +1,22 @@
package com.sw.inbound.network
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import java.util.concurrent.atomic.AtomicInteger
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.setValue
//import java.util.concurrent.atomic.AtomicInteger
/**
* 进度条状态
* 进度条状态Compose 相关逻辑已注释,show/hide 保留为空方法供外部调用)
*/
object LoadingState {
private var _isLoading by mutableStateOf(false)
val isLoading: Boolean get() = _isLoading
// private var _isLoading by mutableStateOf(false)
// val isLoading: Boolean get() = _isLoading
//
// private val counter = AtomicInteger(0)
//
// fun show() = counter.incrementAndGet().let { if (it == 1) _isLoading = true }
// fun hide() = counter.decrementAndGet().let { if (it <= 0) _isLoading = false }
private val counter = AtomicInteger(0)
fun show() = counter.incrementAndGet().let { if (it == 1) _isLoading = true }
fun hide() = counter.decrementAndGet().let { if (it <= 0) _isLoading = false }
fun show() = Unit
fun hide() = Unit
}
@@ -3,7 +3,7 @@ package com.sw.inbound.receiver
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import com.sw.inbound.MainActivity
import com.sw.inbound.activity.HomeActivity
import timber.log.Timber
/**
@@ -14,7 +14,7 @@ class BootReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (Intent.ACTION_BOOT_COMPLETED == intent.action) {
Timber.d("设备启动完成,开始执行自启动逻辑")
val intent = Intent(context, MainActivity::class.java)
val intent = Intent(context, HomeActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(intent)
}
@@ -3,7 +3,7 @@ package com.sw.inbound.sdk
import android.os.Handler
import android.os.Looper
import com.sw.inbound.utils.ThreadUtils
import com.sw.inbound.utils.ToastUtils
//import com.sw.inbound.utils.ToastUtils
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
import com.wabon.wbintelligenthardwaresdk.api.SensorScale.OnScaleResult
import kotlinx.coroutines.delay
@@ -52,7 +52,7 @@ object SensorScaleUtils {
isValidWeight = false
Timber.e("fail code = $errCode")
Handler(Looper.getMainLooper()).post {
ToastUtils.showToast("秤读取数据异常")
//ToastUtils.showToast("秤读取数据异常")
startScale()
}
}
@@ -115,7 +115,7 @@ object SensorScaleUtils {
fun tare() {
mSensorScale?.tare {
Timber.d("去皮置零操作成功")
ToastUtils.showToast("去皮置零操作成功")
//ToastUtils.showToast("去皮置零操作成功")
}
}
@@ -1,174 +1,174 @@
package com.sw.inbound.ui
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import com.sw.inbound.GlobalKey
import com.sw.inbound.R
import com.sw.inbound.ui.page.HomeScreen
import com.sw.inbound.ui.page.PurchaseOrderScreen
import com.sw.inbound.utils.SPUtil
import com.sw.inbound.utils.ToastUtils
@Composable
fun AppScreen(
onBackRequest: () -> Unit
) {
val navController = rememberNavController()
val currentBackStackEntry by navController.currentBackStackEntryAsState()
var canBack by remember { mutableStateOf(false) }
// 拦截物理返回键
// BackHandler(
// onBack = {
// val currentRoute = currentBackStackEntry?.destination?.route
// Timber.d("BackHandler currentRouter = ${currentRoute}")
// if (currentRoute == Screen.Home.route && !canBack) {
// ToastUtils.showToast("再次点击退出")
// canBack = true
// } else if (currentRoute == Screen.Login.route) {
// onBackRequest()
// } else {
// navController.popBackStack()
//package com.sw.inbound.ui
//
//import androidx.compose.animation.core.tween
//import androidx.compose.animation.fadeIn
//import androidx.compose.animation.fadeOut
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.PaddingValues
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.padding
//import androidx.compose.material3.Scaffold
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.layout.ContentScale
//import androidx.compose.ui.res.painterResource
//import androidx.navigation.NavHostController
//import androidx.navigation.compose.NavHost
//import androidx.navigation.compose.composable
//import androidx.navigation.compose.currentBackStackEntryAsState
//import androidx.navigation.compose.rememberNavController
//import com.sw.inbound.GlobalKey
//import com.sw.inbound.R
//import com.sw.inbound.ui.page.HomeScreen
//import com.sw.inbound.ui.page.PurchaseOrderScreen
//import com.sw.inbound.utils.SPUtil
//import com.sw.inbound.utils.ToastUtils
//
//@Composable
//fun AppScreen(
// onBackRequest: () -> Unit
//) {
// val navController = rememberNavController()
// val currentBackStackEntry by navController.currentBackStackEntryAsState()
// var canBack by remember { mutableStateOf(false) }
//
// // 拦截物理返回键
//// BackHandler(
//// onBack = {
//// val currentRoute = currentBackStackEntry?.destination?.route
//// Timber.d("BackHandler currentRouter = ${currentRoute}")
//// if (currentRoute == Screen.Home.route && !canBack) {
//// ToastUtils.showToast("再次点击退出")
//// canBack = true
//// } else if (currentRoute == Screen.Login.route) {
//// onBackRequest()
//// } else {
//// navController.popBackStack()
//// }
//// }
//// )
////
//// BackHandler(canBack) {
//// Timber.d("canBack = $canBack")
//// if (canBack) {
//// onBackRequest()
//// }
//// }
//
// Scaffold(
// modifier = Modifier
// .fillMaxSize()
// //.paint(painter = painterResource(R.mipmap.bg)),
// ,containerColor = Color.Transparent,
// content = { padding ->
// Box {
//// Image(
//// painter = painterResource(R.mipmap.bg),
//// contentDescription = null,
//// modifier = Modifier.fillMaxSize(),
//// contentScale = ContentScale.Crop
//// )
// Image(
// painter = painterResource(id = R.mipmap.bg),
// contentDescription = "背景图片",
// modifier = Modifier.fillMaxSize(),
// contentScale = ContentScale.Crop
// )
// NavHost(padding, navController, onBackRequest)
// }
// }
// )
// ToastUtils.ToastComposable()
// //GlobalLoading() // 全局Loading
//
// BackHandler(canBack) {
// Timber.d("canBack = $canBack")
// if (canBack) {
// onBackRequest()
//}
//
///**
// * 导航
// */
//@Composable
//private fun NavHost(
// padding: PaddingValues,
// navController: NavHostController,
// onBackRequest: () -> Unit = {}
//) {
// val spUtil = SPUtil.getInstance()
// val token = spUtil.get(GlobalKey.KEY_TOKEN, "")!!
// NavHost(
// modifier = Modifier
// .fillMaxSize()
// .padding(padding),
// navController = navController,
// //startDestination = if (token.isEmpty()) Screen.Login.route else Screen.Home.route
// startDestination = Screen.Home.route
// ) {
//// composable(Screen.Test.route) {
//// TestScreen(modifier = Modifier, navController)
//// }
// // 首页
// composable(Screen.Home.route) {
// HomeScreen(modifier = Modifier, navController, onBackRequest = onBackRequest)
// }
// }
Scaffold(
modifier = Modifier
.fillMaxSize()
//.paint(painter = painterResource(R.mipmap.bg)),
,containerColor = Color.Transparent,
content = { padding ->
Box {
// Image(
// painter = painterResource(R.mipmap.bg),
// contentDescription = null,
// modifier = Modifier.fillMaxSize(),
// contentScale = ContentScale.Crop
// )
Image(
painter = painterResource(id = R.mipmap.bg),
contentDescription = "背景图片",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.Crop
)
NavHost(padding, navController, onBackRequest)
}
}
)
ToastUtils.ToastComposable()
//GlobalLoading() // 全局Loading
}
/**
* 导航
*/
@Composable
private fun NavHost(
padding: PaddingValues,
navController: NavHostController,
onBackRequest: () -> Unit = {}
) {
val spUtil = SPUtil.getInstance()
val token = spUtil.get(GlobalKey.KEY_TOKEN, "")!!
NavHost(
modifier = Modifier
.fillMaxSize()
.padding(padding),
navController = navController,
//startDestination = if (token.isEmpty()) Screen.Login.route else Screen.Home.route
startDestination = Screen.Home.route
) {
// composable(Screen.Test.route) {
// TestScreen(modifier = Modifier, navController)
// }
// 首页
composable(Screen.Home.route) {
HomeScreen(modifier = Modifier, navController, onBackRequest = onBackRequest)
}
// 登录
// composable(Screen.Login.route) {
// LoginScreen(modifier = Modifier, navController)
// }
// 采购单入库
composable(
Screen.PurchaseOrder.route,
enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
exitTransition = { fadeOut(animationSpec = tween(0)) } // 无退出动画
) {
PurchaseOrderScreen(modifier = Modifier.fillMaxSize(), navController)
}
// // 自采单
// // 登录
//// composable(Screen.Login.route) {
//// LoginScreen(modifier = Modifier, navController)
//// }
// // 采购单入库
// composable(
// Screen.SelfProcurement.route,
// Screen.PurchaseOrder.route,
// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
// exitTransition = { fadeOut(animationSpec = tween(0)) } // 无退出动画
// ) {
// SelfProcurementScreen(modifier = Modifier, navController)
// PurchaseOrderScreen(modifier = Modifier.fillMaxSize(), navController)
// }
// // 收货
// composable(
// Screen.ReceiptProduct.route,
// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
// exitTransition = { fadeOut(animationSpec = tween(0)) }, // 无退出动画
// arguments = listOf(
// navArgument(name = "id", builder = { type = NavType.IntType }),
// navArgument(name = "supplierId", builder = { type = NavType.IntType })
// )
// ) { backStackEntry ->
// val id = backStackEntry.arguments?.getString("id") ?: ""
// val supplierId = backStackEntry.arguments?.getString("supplierId") ?: ""
// ReceiptProductScreen(modifier = Modifier, navController, id, supplierId)
// }
}
}
sealed class Screen(val route: String) {
data object Home : Screen("home")
// data object Login : Screen("login")
// 采购单入库
data object PurchaseOrder : Screen("purchase_order")
// 自采单入库
// data object SelfProcurement : Screen("self_procurement")
// 收货
// data object ReceiptProduct : Screen("receipt_product?id={id}&supplierId={supplierId}") {
// fun createRoute(id: Int, supplierId: Int) =
// "receipt_product?id=${id}&supplierId=${supplierId}"
//// // 自采单
//// composable(
//// Screen.SelfProcurement.route,
//// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
//// exitTransition = { fadeOut(animationSpec = tween(0)) } // 无退出动画
//// ) {
//// SelfProcurementScreen(modifier = Modifier, navController)
//// }
//// // 收货
//// composable(
//// Screen.ReceiptProduct.route,
//// enterTransition = { fadeIn(animationSpec = tween(0)) }, // 无进入动画
//// exitTransition = { fadeOut(animationSpec = tween(0)) }, // 无退出动画
//// arguments = listOf(
//// navArgument(name = "id", builder = { type = NavType.IntType }),
//// navArgument(name = "supplierId", builder = { type = NavType.IntType })
//// )
//// ) { backStackEntry ->
//// val id = backStackEntry.arguments?.getString("id") ?: ""
//// val supplierId = backStackEntry.arguments?.getString("supplierId") ?: ""
//// ReceiptProductScreen(modifier = Modifier, navController, id, supplierId)
//// }
// }
// 添加物品
// data object AddProduct : Screen("addProduct")
// data object Test : Screen("Test")
}
//}
//
//sealed class Screen(val route: String) {
// data object Home : Screen("home")
//// data object Login : Screen("login")
//
// // 采购单入库
// data object PurchaseOrder : Screen("purchase_order")
//
// // 自采单入库
//// data object SelfProcurement : Screen("self_procurement")
//
// // 收货
//// data object ReceiptProduct : Screen("receipt_product?id={id}&supplierId={supplierId}") {
//// fun createRoute(id: Int, supplierId: Int) =
//// "receipt_product?id=${id}&supplierId=${supplierId}"
//// }
//
// // 添加物品
//// data object AddProduct : Screen("addProduct")
//// data object Test : Screen("Test")
//}
@@ -1,120 +1,120 @@
package com.sw.inbound.ui.page
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.sw.inbound.R
import com.sw.inbound.activity.GoodsListActivity
import com.sw.inbound.activity.PurchaseOrderActivity
import com.sw.inbound.activity.SelfProcurementActivity
import com.sw.inbound.ui.Screen
import com.sw.inbound.ui.weight.TopTitleBar
import com.sw.inbound.utils.ext.startActivity
import com.sw.inbound.viewmodel.UserViewModel
import timber.log.Timber
/**
* 首页
*/
@Composable
fun HomeScreen(
modifier: Modifier = Modifier,
navController: NavHostController = rememberNavController(),
viewModel: UserViewModel = hiltViewModel<UserViewModel>(),
onBackRequest: () -> Unit = {}
) {
val user by viewModel.user.collectAsState()
// 避免每次进入都获取字典类型
LaunchedEffect(Unit) {
Timber.d("LaunchedEffect(Unit)")
// viewModel.getInitInfo()
}
BackHandler {
onBackRequest()
}
Column(modifier = Modifier.fillMaxSize()) {
TopTitleBar(user = user, onLogoutClick = {
// viewModel.logout()
// navController.navigate(Screen.Login.route) {
// popUpTo(Screen.Home.route) {
// inclusive = true
// }
// }
})
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.weight(1f)
.fillMaxWidth()
) {
Image(
modifier = Modifier
.width(595.dp)
.height(477.dp)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
// navController.navigate(Screen.PurchaseOrder.route)
//navController.context.startActivity<ReceiptActivity> {
// putExtra(GoodsListActivity.ID, "123123")
// putExtra(GoodsListActivity.SUPPLIER_ID, "123123123123")
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
//}
navController.context.startActivity<PurchaseOrderActivity>()
},
painter = painterResource(R.mipmap.ic_order_purchase),
contentDescription = "采购单入库"
)
Spacer(modifier = Modifier.width(15.dp))
Image(
modifier = Modifier
.width(595.dp)
.height(477.dp)
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
// navController.navigate(
// Screen.SelfProcurement.route, navOptions = NavOptions.Builder()
// .setEnterAnim(0)
// .setExitAnim(0)
// .setPopEnterAnim(0)
// .setPopExitAnim(0)
// .build()
// )
navController.context.startActivity<SelfProcurementActivity> {
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
}
},
painter = painterResource(R.mipmap.ic_order_self_procurement),
contentDescription = "自采入库"
)
}
}
}
//package com.sw.inbound.ui.page
//
//import androidx.activity.compose.BackHandler
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.interaction.MutableInteractionSource
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.width
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.LaunchedEffect
//import androidx.compose.runtime.collectAsState
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.remember
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.unit.dp
//import androidx.hilt.navigation.compose.hiltViewModel
//import androidx.navigation.NavHostController
//import androidx.navigation.compose.rememberNavController
//import com.sw.inbound.R
//import com.sw.inbound.activity.GoodsListActivity
//import com.sw.inbound.activity.PurchaseOrderActivity
//import com.sw.inbound.activity.SelfProcurementActivity
//import com.sw.inbound.ui.Screen
//import com.sw.inbound.ui.weight.TopTitleBar
//import com.sw.inbound.utils.ext.startActivity
//import com.sw.inbound.viewmodel.UserViewModel
//import timber.log.Timber
//
///**
// * 首页
// */
//@Composable
//fun HomeScreen(
// modifier: Modifier = Modifier,
// navController: NavHostController = rememberNavController(),
// viewModel: UserViewModel = hiltViewModel<UserViewModel>(),
// onBackRequest: () -> Unit = {}
//) {
// val user by viewModel.user.collectAsState()
//
// // 避免每次进入都获取字典类型
// LaunchedEffect(Unit) {
// Timber.d("LaunchedEffect(Unit)")
//// viewModel.getInitInfo()
// }
//
// BackHandler {
// onBackRequest()
// }
//
// Column(modifier = Modifier.fillMaxSize()) {
// TopTitleBar(user = user, onLogoutClick = {
//// viewModel.logout()
//// navController.navigate(Screen.Login.route) {
//// popUpTo(Screen.Home.route) {
//// inclusive = true
//// }
//// }
// })
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .weight(1f)
// .fillMaxWidth()
// ) {
// Image(
// modifier = Modifier
// .width(595.dp)
// .height(477.dp)
// .clickable(
// interactionSource = remember { MutableInteractionSource() },
// indication = null
// ) {
//// navController.navigate(Screen.PurchaseOrder.route)
// //navController.context.startActivity<ReceiptActivity> {
// // putExtra(GoodsListActivity.ID, "123123")
// // putExtra(GoodsListActivity.SUPPLIER_ID, "123123123123")
// // putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
// //}
// navController.context.startActivity<PurchaseOrderActivity>()
// },
// painter = painterResource(R.mipmap.ic_order_purchase),
// contentDescription = "采购单入库"
// )
// Spacer(modifier = Modifier.width(15.dp))
// Image(
// modifier = Modifier
// .width(595.dp)
// .height(477.dp)
// .clickable(
// interactionSource = remember { MutableInteractionSource() },
// indication = null
// ) {
//// navController.navigate(
//// Screen.SelfProcurement.route, navOptions = NavOptions.Builder()
//// .setEnterAnim(0)
//// .setExitAnim(0)
//// .setPopEnterAnim(0)
//// .setPopExitAnim(0)
//// .build()
//// )
// navController.context.startActivity<SelfProcurementActivity> {
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
// }
// },
// painter = painterResource(R.mipmap.ic_order_self_procurement),
// contentDescription = "自采入库"
// )
// }
// }
//}
@@ -1,351 +1,351 @@
package com.sw.inbound.ui.page
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
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 androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.sw.inbound.R
import com.sw.inbound.activity.GoodsListActivity
import com.sw.inbound.activity.ReceiptActivity
import com.sw.inbound.activity.SelfProcurementActivity
import com.sw.inbound.ext.dashedBorder
import com.sw.inbound.ext.toFormattedString
import com.sw.inbound.model.response.SupplierInfo
import com.sw.inbound.ui.theme.AppTypography.blackTextStyle
import com.sw.inbound.ui.theme.AppTypography.grayTextStyle
import com.sw.inbound.ui.weight.BottomActionBar
import com.sw.inbound.ui.weight.TopTitleBar
import com.sw.inbound.utils.ext.startActivity
import com.sw.inbound.viewmodel.PurchaseOrderViewModel
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import timber.log.Timber
@Preview(
widthDp = 1920, heightDp = 1080, showBackground = true
)
/**
* 采购订单-供应商列表
*/
@Composable
fun PurchaseOrderScreen(
modifier: Modifier = Modifier,
navController: NavHostController = rememberNavController(),
viewModel: PurchaseOrderViewModel = hiltViewModel<PurchaseOrderViewModel>()
) {
val products by viewModel.supplierList.collectAsState()
val lazyListState = rememberLazyListState()
val canLoadMore by viewModel.canLoadMore.collectAsState()
val isMoreLoading by viewModel.isMoreLoading.collectAsState()
var pageNum by remember { mutableIntStateOf(1) }
val lifecycleOwner = LocalLifecycleOwner.current
val first = viewModel.firstOperate.collectAsState()
DisposableEffect(lifecycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) {
Timber.d("ON_RESUME 触发")
pageNum = 0
viewModel.getOrderList()
}
}
lifecycleOwner.lifecycle.addObserver(observer)
onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
}
// 检测是否滚动到底部
LaunchedEffect(lazyListState) {
snapshotFlow { lazyListState.layoutInfo }.map { layoutInfo ->
val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull()
lastVisibleItem?.index == layoutInfo.totalItemsCount - 1
}.distinctUntilChanged().collect { reachedEnd ->
Timber.d("加载更多 reachedEnd = $reachedEnd, isMoreLoading = $isMoreLoading, canLoadMore = $canLoadMore")
if (reachedEnd && !isMoreLoading && canLoadMore) {
pageNum++
viewModel.getOrderList(pageNum = pageNum)
}
}
}
Column {
TopTitleBar()
Box(
modifier = Modifier
.weight(1f)
.padding(horizontal = 10.dp)
) {
Image(
painter = painterResource(id = R.mipmap.bg_listview),
contentDescription = "背景",
modifier = Modifier.fillMaxSize(),
contentScale = ContentScale.FillBounds
)
Box(
modifier = Modifier.padding(
start = 30.dp, end = 30.dp, top = 30.dp, bottom = 90.dp
)
) {
if (first.value) {
return@Box
}
if (products.isNullOrEmpty()) {
PurchaseEmptyItem()
} else {
LazyRow(
modifier = modifier.padding(10.dp),
state = lazyListState,
contentPadding = PaddingValues(16.dp),
horizontalArrangement = Arrangement.spacedBy(30.dp)
) {
items(items = products!!, key = { it!!.id ?: "" }) { product ->
PurchaseOrderItem(product!!) {
// navController.navigate(
// Screen.ReceiptProduct.createRoute(
// it.id,
// it.supplierId
// )
// )
navController.context.startActivity<ReceiptActivity> {
putExtra(GoodsListActivity.ID, product!!.id)
putExtra(GoodsListActivity.SUPPLIER_ID, product.supplierId)
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
//putExtra(GoodsListActivity.IS_NEW_RECEIPT, false)
}
}
}
if (isMoreLoading) {
item {
Box(
modifier = Modifier
.fillParentMaxHeight()
.padding(16.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator()
}
}
}
}
}
}
}
BottomActionBar(modifier = Modifier, onLeftButtonClick = {
navController.popBackStack()
}, onRight2ButtonClick = {
//navController.navigate(Screen.SelfProcurement.route)
navController.context.startActivity<SelfProcurementActivity> {
putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
}
//navController.context.startActivity<ReceiptActivity> {
// //xtra(GoodsListActivity.ID,it!!.id)
// //xtra(GoodsListActivity.SUPPLIER_ID,it.supplierId)
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE,true)
// putExtra(GoodsListActivity.IS_NEW_RECEIPT,true)
//}
})
}
}
/**
* 采购单缺省
*/
@Composable
fun PurchaseEmptyItem() {
Column(
modifier = Modifier.fillMaxSize(),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Image(painter = painterResource(R.mipmap.ic_empty), contentDescription = "暂无数据")
Spacer(modifier = Modifier.height(30.dp))
Text(
text = "暂无数据", style = TextStyle(
fontSize = 30.sp, fontWeight = FontWeight.Bold, color = colorResource(R.color.title)
)
)
}
}
/**
* 列表item
*/
@Composable
fun PurchaseOrderItem(product: SupplierInfo, onItemClick: (SupplierInfo) -> Unit) {
val (receiptStatusStyle, statusLabel) = when (product.receiveStatus) {
// 1 -> blackTextStyle to "已关闭"
// 2 -> blackTextStyle to "已完成"
// 3 -> blackTextStyle.copy(
// color = colorResource(R.color.red)
// ) to "未收货"
//package com.sw.inbound.ui.page
//
// 4 -> blackTextStyle.copy(
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.layout.PaddingValues
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.lazy.LazyRow
//import androidx.compose.foundation.lazy.items
//import androidx.compose.foundation.lazy.rememberLazyListState
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material3.Button
//import androidx.compose.material3.ButtonDefaults
//import androidx.compose.material3.CircularProgressIndicator
//import androidx.compose.material3.HorizontalDivider
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.DisposableEffect
//import androidx.compose.runtime.LaunchedEffect
//import androidx.compose.runtime.collectAsState
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableIntStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.runtime.snapshotFlow
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.layout.ContentScale
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.text.style.TextOverflow
//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 androidx.lifecycle.Lifecycle
//import androidx.lifecycle.LifecycleEventObserver
//import androidx.lifecycle.compose.LocalLifecycleOwner
//import androidx.navigation.NavHostController
//import androidx.navigation.compose.rememberNavController
//import com.sw.inbound.R
//import com.sw.inbound.activity.GoodsListActivity
//import com.sw.inbound.activity.ReceiptActivity
//import com.sw.inbound.activity.SelfProcurementActivity
//import com.sw.inbound.ext.dashedBorder
//import com.sw.inbound.ext.toFormattedString
//import com.sw.inbound.model.response.SupplierInfo
//import com.sw.inbound.ui.theme.AppTypography.blackTextStyle
//import com.sw.inbound.ui.theme.AppTypography.grayTextStyle
//import com.sw.inbound.ui.weight.BottomActionBar
//import com.sw.inbound.ui.weight.TopTitleBar
//import com.sw.inbound.utils.ext.startActivity
//import com.sw.inbound.viewmodel.PurchaseOrderViewModel
//import kotlinx.coroutines.flow.distinctUntilChanged
//import kotlinx.coroutines.flow.map
//import timber.log.Timber
//
//@Preview(
// widthDp = 1920, heightDp = 1080, showBackground = true
//)
///**
// * 采购订单-供应商列表
// */
//@Composable
//fun PurchaseOrderScreen(
// modifier: Modifier = Modifier,
// navController: NavHostController = rememberNavController(),
// viewModel: PurchaseOrderViewModel = hiltViewModel<PurchaseOrderViewModel>()
//) {
// val products by viewModel.supplierList.collectAsState()
// val lazyListState = rememberLazyListState()
// val canLoadMore by viewModel.canLoadMore.collectAsState()
// val isMoreLoading by viewModel.isMoreLoading.collectAsState()
// var pageNum by remember { mutableIntStateOf(1) }
// val lifecycleOwner = LocalLifecycleOwner.current
// val first = viewModel.firstOperate.collectAsState()
//
// DisposableEffect(lifecycleOwner) {
// val observer = LifecycleEventObserver { _, event ->
// if (event == Lifecycle.Event.ON_RESUME) {
// Timber.d("ON_RESUME 触发")
// pageNum = 0
// viewModel.getOrderList()
// }
// }
// lifecycleOwner.lifecycle.addObserver(observer)
// onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
// }
//
// // 检测是否滚动到底部
// LaunchedEffect(lazyListState) {
// snapshotFlow { lazyListState.layoutInfo }.map { layoutInfo ->
// val lastVisibleItem = layoutInfo.visibleItemsInfo.lastOrNull()
// lastVisibleItem?.index == layoutInfo.totalItemsCount - 1
// }.distinctUntilChanged().collect { reachedEnd ->
// Timber.d("加载更多 reachedEnd = $reachedEnd, isMoreLoading = $isMoreLoading, canLoadMore = $canLoadMore")
// if (reachedEnd && !isMoreLoading && canLoadMore) {
// pageNum++
// viewModel.getOrderList(pageNum = pageNum)
// }
// }
// }
//
// Column {
// TopTitleBar()
// Box(
// modifier = Modifier
// .weight(1f)
// .padding(horizontal = 10.dp)
// ) {
// Image(
// painter = painterResource(id = R.mipmap.bg_listview),
// contentDescription = "背景",
// modifier = Modifier.fillMaxSize(),
// contentScale = ContentScale.FillBounds
// )
//
// Box(
// modifier = Modifier.padding(
// start = 30.dp, end = 30.dp, top = 30.dp, bottom = 90.dp
// )
// ) {
// if (first.value) {
// return@Box
// }
// if (products.isNullOrEmpty()) {
// PurchaseEmptyItem()
// } else {
// LazyRow(
// modifier = modifier.padding(10.dp),
// state = lazyListState,
// contentPadding = PaddingValues(16.dp),
// horizontalArrangement = Arrangement.spacedBy(30.dp)
// ) {
// items(items = products!!, key = { it!!.id ?: "" }) { product ->
// PurchaseOrderItem(product!!) {
//// navController.navigate(
//// Screen.ReceiptProduct.createRoute(
//// it.id,
//// it.supplierId
//// )
//// )
// navController.context.startActivity<ReceiptActivity> {
// putExtra(GoodsListActivity.ID, product!!.id)
// putExtra(GoodsListActivity.SUPPLIER_ID, product.supplierId)
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE, true)
// //putExtra(GoodsListActivity.IS_NEW_RECEIPT, false)
// }
// }
// }
//
// if (isMoreLoading) {
// item {
// Box(
// modifier = Modifier
// .fillParentMaxHeight()
// .padding(16.dp),
// contentAlignment = Alignment.Center
// ) {
// CircularProgressIndicator()
// }
// }
// }
// }
// }
// }
// }
//
// BottomActionBar(modifier = Modifier, onLeftButtonClick = {
// navController.popBackStack()
// }, onRight2ButtonClick = {
// //navController.navigate(Screen.SelfProcurement.route)
// navController.context.startActivity<SelfProcurementActivity> {
// putExtra(GoodsListActivity.IS_RECEIPT_PAGE, false)
// }
// //navController.context.startActivity<ReceiptActivity> {
// // //xtra(GoodsListActivity.ID,it!!.id)
// // //xtra(GoodsListActivity.SUPPLIER_ID,it.supplierId)
// // putExtra(GoodsListActivity.IS_RECEIPT_PAGE,true)
// // putExtra(GoodsListActivity.IS_NEW_RECEIPT,true)
// //}
// })
// }
//}
//
///**
// * 采购单缺省
// */
//@Composable
//fun PurchaseEmptyItem() {
// Column(
// modifier = Modifier.fillMaxSize(),
// horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.Center
// ) {
// Image(painter = painterResource(R.mipmap.ic_empty), contentDescription = "暂无数据")
// Spacer(modifier = Modifier.height(30.dp))
// Text(
// text = "暂无数据", style = TextStyle(
// fontSize = 30.sp, fontWeight = FontWeight.Bold, color = colorResource(R.color.title)
// )
// )
// }
//}
//
///**
// * 列表item
// */
//@Composable
//fun PurchaseOrderItem(product: SupplierInfo, onItemClick: (SupplierInfo) -> Unit) {
//
// val (receiptStatusStyle, statusLabel) = when (product.receiveStatus) {
//// 1 -> blackTextStyle to "已关闭"
//// 2 -> blackTextStyle to "已完成"
//// 3 -> blackTextStyle.copy(
//// color = colorResource(R.color.red)
//// ) to "未收货"
////
//// 4 -> blackTextStyle.copy(
//// color = colorResource(R.color.origin)
//// ) to "部分收货"
// 1 -> blackTextStyle.copy(
// color = colorResource(R.color.red)
// ) to "待收货"
//
// 2 -> blackTextStyle.copy(
// color = colorResource(R.color.origin)
// ) to "部分收货"
1 -> blackTextStyle.copy(
color = colorResource(R.color.red)
) to "待收货"
2 -> blackTextStyle.copy(
color = colorResource(R.color.origin)
) to "已收货"
3 -> blackTextStyle to "已关闭"
else -> blackTextStyle to "未知状态"
}
val itemSpace = 29.dp
Box(
modifier = Modifier
.background(
color = Color.White.copy(alpha = 0.37f), shape = RoundedCornerShape(10.dp) // 圆角背景
)
.clickable {
onItemClick(product)
}) {
Column(
modifier = Modifier
.width(580.dp)
.padding(horizontal = 30.dp, vertical = 30.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(0.dp)
) {
Text(
text = product.supplierName ?: "-",
modifier = Modifier.padding(top = 25.dp),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
style = TextStyle(
fontWeight = FontWeight.Bold,
fontSize = 30.sp,
color = colorResource(R.color.black)
)
)
Spacer(modifier = Modifier.height(itemSpace))
Text(
text = "单号 ${product.purCode ?: "-"}", maxLines = 1, style = grayTextStyle
)
Spacer(modifier = Modifier.height(itemSpace))
HorizontalDivider(
thickness = 1.dp, color = colorResource(R.color.divider)
)
Spacer(modifier = Modifier.height(40.dp))
Text(
text = "物品(项)", style = grayTextStyle
)
Spacer(modifier = Modifier.height(22.dp))
Text(
text = product.goodCount.toFormattedString(), style = TextStyle(
color = colorResource(R.color.black),
fontSize = 90.sp,
fontWeight = FontWeight.Bold
)
)
Spacer(modifier = Modifier.height(22.dp))
Row(
modifier = Modifier
.fillMaxWidth()
.dashedBorder(
strokeWidth = 2.dp, color = Color(0xFFBDC5CE), cornerRadiusDp = 10.dp
)
.padding(horizontal = 72.dp, vertical = 27.dp),
horizontalArrangement = Arrangement.SpaceBetween
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "采购日期", style = grayTextStyle)
Spacer(modifier = Modifier.height(8.dp))
Text(text = product.purchaseDate ?: "-", style = blackTextStyle)
}
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = "到货日期", style = grayTextStyle)
Spacer(modifier = Modifier.height(8.dp))
Text(text = product.receiveDate ?: "-", style = blackTextStyle)
}
}
Spacer(modifier = Modifier.height(28.dp))
Row(
modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween
) {
Row {
Text("收货状态:", style = grayTextStyle)
Spacer(Modifier.width(8.dp))
Text(statusLabel, style = receiptStatusStyle)
}
Row {
Text("采购人:", style = grayTextStyle)
Spacer(Modifier.width(8.dp))
Text(product.receiveUser, style = blackTextStyle)
}
}
Spacer(modifier = Modifier.height(itemSpace))
Button(
modifier = Modifier
.fillMaxWidth()
.height(80.dp),
shape = RoundedCornerShape(10.dp),
colors = ButtonDefaults.buttonColors(
containerColor = Color(0xFF009632).copy(alpha = 1f),
contentColor = colorResource(R.color.white)
),
onClick = {
onItemClick(product)
}) {
Text(
if (product.receiveStatus == 4) "部分收货" else "收货",
style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 26.sp)
)
}
}
}
}
// ) to "收货"
//
// 3 -> blackTextStyle to "已关闭"
// else -> blackTextStyle to "未知状态"
// }
//
// val itemSpace = 29.dp
// Box(
// modifier = Modifier
// .background(
// color = Color.White.copy(alpha = 0.37f), shape = RoundedCornerShape(10.dp) // 圆角背景
// )
// .clickable {
// onItemClick(product)
// }) {
// Column(
// modifier = Modifier
// .width(580.dp)
// .padding(horizontal = 30.dp, vertical = 30.dp),
// horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.spacedBy(0.dp)
// ) {
// Text(
// text = product.supplierName ?: "-",
// modifier = Modifier.padding(top = 25.dp),
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// style = TextStyle(
// fontWeight = FontWeight.Bold,
// fontSize = 30.sp,
// color = colorResource(R.color.black)
// )
// )
// Spacer(modifier = Modifier.height(itemSpace))
// Text(
// text = "单号 ${product.purCode ?: "-"}", maxLines = 1, style = grayTextStyle
// )
// Spacer(modifier = Modifier.height(itemSpace))
// HorizontalDivider(
// thickness = 1.dp, color = colorResource(R.color.divider)
// )
// Spacer(modifier = Modifier.height(40.dp))
// Text(
// text = "物品(项)", style = grayTextStyle
// )
// Spacer(modifier = Modifier.height(22.dp))
// Text(
// text = product.goodCount.toFormattedString(), style = TextStyle(
// color = colorResource(R.color.black),
// fontSize = 90.sp,
// fontWeight = FontWeight.Bold
// )
// )
// Spacer(modifier = Modifier.height(22.dp))
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .dashedBorder(
// strokeWidth = 2.dp, color = Color(0xFFBDC5CE), cornerRadiusDp = 10.dp
// )
// .padding(horizontal = 72.dp, vertical = 27.dp),
// horizontalArrangement = Arrangement.SpaceBetween
// ) {
// Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Text(text = "采购日期", style = grayTextStyle)
// Spacer(modifier = Modifier.height(8.dp))
// Text(text = product.purchaseDate ?: "-", style = blackTextStyle)
// }
// Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Text(text = "到货日期", style = grayTextStyle)
// Spacer(modifier = Modifier.height(8.dp))
// Text(text = product.receiveDate ?: "-", style = blackTextStyle)
// }
// }
// Spacer(modifier = Modifier.height(28.dp))
// Row(
// modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween
// ) {
// Row {
// Text("收货状态:", style = grayTextStyle)
// Spacer(Modifier.width(8.dp))
// Text(statusLabel, style = receiptStatusStyle)
// }
//
// Row {
// Text("采购人:", style = grayTextStyle)
// Spacer(Modifier.width(8.dp))
//
// Text(product.receiveUser, style = blackTextStyle)
// }
// }
// Spacer(modifier = Modifier.height(itemSpace))
// Button(
// modifier = Modifier
// .fillMaxWidth()
// .height(80.dp),
// shape = RoundedCornerShape(10.dp),
// colors = ButtonDefaults.buttonColors(
// containerColor = Color(0xFF009632).copy(alpha = 1f),
// contentColor = colorResource(R.color.white)
// ),
// onClick = {
// onItemClick(product)
// }) {
// Text(
// if (product.receiveStatus == 4) "部分收货" else "收货",
// style = TextStyle(fontWeight = FontWeight.Bold, fontSize = 26.sp)
// )
// }
// }
// }
//}
@@ -1,64 +1,64 @@
package com.sw.inbound.ui.theme
import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import com.sw.inbound.R
object AppTypography {
val gray96a0aaTextStyle: TextStyle
@Composable get() = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
color = Color(0xFF96A0AA)
)
val gray999999TextStyle: TextStyle
@Composable get() = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
color = Color(0xFF999999)
)
val black141428TextStyle: TextStyle
@Composable get() = TextStyle(
fontSize = 24.sp,
fontWeight = FontWeight.Medium,
color = Black_141428
)
val grayTextStyle: TextStyle
@Composable
get() = TextStyle(
color = colorResource(R.color.gray),
fontSize = 24.sp,
fontWeight = FontWeight.Medium
)
val blackTextStyle: TextStyle
@Composable
get() = TextStyle(
color = colorResource(R.color.black),
fontSize = 24.sp,
fontWeight = FontWeight.Bold
)
val blackMediumTextStyle: TextStyle
@Composable
get() = TextStyle(
color = colorResource(R.color.black),
fontSize = 24.sp,
fontWeight = FontWeight.Medium
)
val BlueTextStyle: TextStyle
@Composable
get() = TextStyle(
color = colorResource(R.color.blue),
fontSize = 24.sp,
fontWeight = FontWeight.Bold
)
}
//package com.sw.inbound.ui.theme
//
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.unit.sp
//import com.sw.inbound.R
//
//object AppTypography {
// val gray96a0aaTextStyle: TextStyle
// @Composable get() = TextStyle(
// fontSize = 24.sp,
// fontWeight = FontWeight.Medium,
// color = Color(0xFF96A0AA)
// )
//
// val gray999999TextStyle: TextStyle
// @Composable get() = TextStyle(
// fontSize = 24.sp,
// fontWeight = FontWeight.Medium,
// color = Color(0xFF999999)
// )
//
// val black141428TextStyle: TextStyle
// @Composable get() = TextStyle(
// fontSize = 24.sp,
// fontWeight = FontWeight.Medium,
// color = Black_141428
// )
//
// val grayTextStyle: TextStyle
// @Composable
// get() = TextStyle(
// color = colorResource(R.color.gray),
// fontSize = 24.sp,
// fontWeight = FontWeight.Medium
// )
// val blackTextStyle: TextStyle
// @Composable
// get() = TextStyle(
// color = colorResource(R.color.black),
// fontSize = 24.sp,
// fontWeight = FontWeight.Bold
// )
//
// val blackMediumTextStyle: TextStyle
// @Composable
// get() = TextStyle(
// color = colorResource(R.color.black),
// fontSize = 24.sp,
// fontWeight = FontWeight.Medium
// )
//
// val BlueTextStyle: TextStyle
// @Composable
// get() = TextStyle(
// color = colorResource(R.color.blue),
// fontSize = 24.sp,
// fontWeight = FontWeight.Bold
// )
//
//}
@@ -1,22 +1,22 @@
package com.sw.inbound.ui.theme
import androidx.compose.ui.graphics.Color
val Purple80 = Color(0xFFD0BCFF)
val PurpleGrey80 = Color(0xFFCCC2DC)
val Pink80 = Color(0xFFEFB8C8)
val Purple40 = Color(0xFF6650a4)
val PurpleGrey40 = Color(0xFF625b71)
val Pink40 = Color(0xFF7D5260)
val Black_141428 = Color(0xFF141428)
val Gray_A0A0B4 = Color(0XffA0A0B4)
val Gray_DCDCF0 = Color(0xFFDCDCF0)
val Gray_96A0AA = Color(0xFF96A0AA)
val GrayDivider = Color(0XFFDCDCF0)
val Green_009632 = Color(0xFF009632)
val Blue_0032C8 = Color(0xFF0032C8)
val Red_FF3232 = Color(0xFFFF3232)
//package com.sw.inbound.ui.theme
//
//import androidx.compose.ui.graphics.Color
//
//val Purple80 = Color(0xFFD0BCFF)
//val PurpleGrey80 = Color(0xFFCCC2DC)
//val Pink80 = Color(0xFFEFB8C8)
//
//val Purple40 = Color(0xFF6650a4)
//val PurpleGrey40 = Color(0xFF625b71)
//val Pink40 = Color(0xFF7D5260)
//
//val Black_141428 = Color(0xFF141428)
//val Gray_A0A0B4 = Color(0XffA0A0B4)
//val Gray_DCDCF0 = Color(0xFFDCDCF0)
//val Gray_96A0AA = Color(0xFF96A0AA)
//val GrayDivider = Color(0XFFDCDCF0)
//
//val Green_009632 = Color(0xFF009632)
//val Blue_0032C8 = Color(0xFF0032C8)
//val Red_FF3232 = Color(0xFFFF3232)
//
@@ -1,57 +1,57 @@
package com.sw.inbound.ui.theme
import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
private val DarkColorScheme = darkColorScheme(
primary = Purple80,
secondary = PurpleGrey80,
tertiary = Pink80
)
private val LightColorScheme = lightColorScheme(
primary = Purple40,
secondary = PurpleGrey40,
tertiary = Pink40
/* Other default colors to override
background = Color(0xFFFFFBFE),
surface = Color(0xFFFFFBFE),
onPrimary = Color.White,
onSecondary = Color.White,
onTertiary = Color.White,
onBackground = Color(0xFF1C1B1F),
onSurface = Color(0xFF1C1B1F),
*/
)
@Composable
fun InboundTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
content: @Composable () -> Unit
) {
val colorScheme = when {
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
val context = LocalContext.current
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
}
darkTheme -> DarkColorScheme
else -> LightColorScheme
}
MaterialTheme(
colorScheme = colorScheme,
typography = Typography,
content = content,
)
}
//package com.sw.inbound.ui.theme
//
//import android.os.Build
//import androidx.compose.foundation.isSystemInDarkTheme
//import androidx.compose.material3.MaterialTheme
//import androidx.compose.material3.darkColorScheme
//import androidx.compose.material3.dynamicDarkColorScheme
//import androidx.compose.material3.dynamicLightColorScheme
//import androidx.compose.material3.lightColorScheme
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.platform.LocalContext
//
//private val DarkColorScheme = darkColorScheme(
// primary = Purple80,
// secondary = PurpleGrey80,
// tertiary = Pink80
//)
//
//private val LightColorScheme = lightColorScheme(
// primary = Purple40,
// secondary = PurpleGrey40,
// tertiary = Pink40
//
// /* Other default colors to override
// background = Color(0xFFFFFBFE),
// surface = Color(0xFFFFFBFE),
// onPrimary = Color.White,
// onSecondary = Color.White,
// onTertiary = Color.White,
// onBackground = Color(0xFF1C1B1F),
// onSurface = Color(0xFF1C1B1F),
// */
//)
//
//@Composable
//fun InboundTheme(
// darkTheme: Boolean = isSystemInDarkTheme(),
// // Dynamic color is available on Android 12+
// dynamicColor: Boolean = true,
// content: @Composable () -> Unit
//) {
// val colorScheme = when {
// dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
// val context = LocalContext.current
// if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
// }
//
// darkTheme -> DarkColorScheme
// else -> LightColorScheme
// }
//
// MaterialTheme(
// colorScheme = colorScheme,
// typography = Typography,
// content = content,
// )
//}
@@ -1,34 +1,34 @@
package com.sw.inbound.ui.theme
import androidx.compose.material3.Typography
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
// Set of Material typography styles to start with
val Typography = Typography(
bodyLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 16.sp,
lineHeight = 24.sp,
letterSpacing = 0.5.sp
)
/* Other default text styles to override
titleLarge = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Normal,
fontSize = 22.sp,
lineHeight = 28.sp,
letterSpacing = 0.sp
),
labelSmall = TextStyle(
fontFamily = FontFamily.Default,
fontWeight = FontWeight.Medium,
fontSize = 11.sp,
lineHeight = 16.sp,
letterSpacing = 0.5.sp
)
*/
)
//package com.sw.inbound.ui.theme
//
//import androidx.compose.material3.Typography
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontFamily
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.unit.sp
//
//// Set of Material typography styles to start with
//val Typography = Typography(
// bodyLarge = TextStyle(
// fontFamily = FontFamily.Default,
// fontWeight = FontWeight.Normal,
// fontSize = 16.sp,
// lineHeight = 24.sp,
// letterSpacing = 0.5.sp
// )
// /* Other default text styles to override
// titleLarge = TextStyle(
// fontFamily = FontFamily.Default,
// fontWeight = FontWeight.Normal,
// fontSize = 22.sp,
// lineHeight = 28.sp,
// letterSpacing = 0.sp
// ),
// labelSmall = TextStyle(
// fontFamily = FontFamily.Default,
// fontWeight = FontWeight.Medium,
// fontSize = 11.sp,
// lineHeight = 16.sp,
// letterSpacing = 0.5.sp
// )
// */
//)
@@ -1,105 +1,105 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sw.inbound.R
/**
* 底部按钮
*/
@Composable
fun BottomActionBar(
leftText: String = "返回",
right1ButtonText: String = "清空物品",
right2ButtonText: String = "新增收货",
showRight1Button: Boolean = false,
onLeftButtonClick: () -> Unit,
onRight1ButtonClick: () -> Unit = {},
onRight2ButtonClick: () -> Unit,
modifier: Modifier = Modifier,
) {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 30.dp, end = 30.dp, bottom = 20.dp)
.height(100.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
// 左侧图标+文字
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.width(220.dp)
.height(100.dp)
.background(
color = colorResource(R.color.blue),
shape = RoundedCornerShape(10.dp)
)
.clickable {
onLeftButtonClick()
}
) {
Image(
painter = painterResource(R.mipmap.ic_back_white),
contentDescription = "返回",
modifier = Modifier.size(40.dp)
)
Spacer(modifier = Modifier.width(21.dp))
Text(
text = leftText,
style = TextStyle(
color = colorResource(R.color.white),
fontWeight = FontWeight.Bold,
fontSize = 36.sp
)
)
}
Row {
if (showRight1Button) {
CustomOutlinedButton(
modifier = modifier
.width(300.dp)
.height(100.dp),
text = right1ButtonText,
fontSize = 36.sp,
onClick = onRight1ButtonClick
)
Spacer(modifier = Modifier.width(20.dp))
}
CustomButton(
modifier = modifier
.width(300.dp)
.height(100.dp),
text = right2ButtonText,
onClick = onRight2ButtonClick,
borderColor = colorResource(R.color.blue),
textColor = colorResource(R.color.white),
fontSize = 36.sp
)
}
}
}
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.size
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import com.sw.inbound.R
//
///**
// * 底部按钮
// */
//@Composable
//fun BottomActionBar(
// leftText: String = "返回",
// right1ButtonText: String = "清空物品",
// right2ButtonText: String = "新增收货",
// showRight1Button: Boolean = false,
// onLeftButtonClick: () -> Unit,
// onRight1ButtonClick: () -> Unit = {},
// onRight2ButtonClick: () -> Unit,
// modifier: Modifier = Modifier,
//) {
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .padding(start = 30.dp, end = 30.dp, bottom = 20.dp)
// .height(100.dp),
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.SpaceBetween
// ) {
// // 左侧图标+文字
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .width(220.dp)
// .height(100.dp)
// .background(
// color = colorResource(R.color.blue),
// shape = RoundedCornerShape(10.dp)
// )
// .clickable {
// onLeftButtonClick()
// }
// ) {
// Image(
// painter = painterResource(R.mipmap.ic_back_white),
// contentDescription = "返回",
// modifier = Modifier.size(40.dp)
// )
// Spacer(modifier = Modifier.width(21.dp))
// Text(
// text = leftText,
// style = TextStyle(
// color = colorResource(R.color.white),
// fontWeight = FontWeight.Bold,
// fontSize = 36.sp
// )
// )
// }
//
// Row {
// if (showRight1Button) {
// CustomOutlinedButton(
// modifier = modifier
// .width(300.dp)
// .height(100.dp),
// text = right1ButtonText,
// fontSize = 36.sp,
// onClick = onRight1ButtonClick
// )
// Spacer(modifier = Modifier.width(20.dp))
// }
// CustomButton(
// modifier = modifier
// .width(300.dp)
// .height(100.dp),
// text = right2ButtonText,
// onClick = onRight2ButtonClick,
// borderColor = colorResource(R.color.blue),
// textColor = colorResource(R.color.white),
// fontSize = 36.sp
// )
// }
// }
//
//}
@@ -1,193 +1,193 @@
package com.sw.inbound.ui.weight
import android.net.Uri
import android.widget.Toast
import androidx.camera.view.CameraController
import androidx.camera.view.LifecycleCameraController
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.LocalLifecycleOwner
import coil.compose.AsyncImage
import com.sw.inbound.GlobalData
import com.sw.inbound.R
import com.sw.inbound.ext.dashedBorder
import com.sw.inbound.ui.theme.AppTypography
import com.sw.inbound.utils.FileUtils
import com.sw.inbound.utils.ToastUtils
import com.sw.inbound.utils.rememberPhotoCapture
import timber.log.Timber
/**
* 相机预览 -默认不预览,支持拍照
*/
@Composable
fun CameraCaptureLayout(
modifier: Modifier = Modifier
) {
val context = LocalContext.current
var showCamera by remember { mutableStateOf(false) }
val lifecycleOwner = LocalLifecycleOwner.current
var photoUri by remember { mutableStateOf<Uri?>(null) }
// CameraX 控制器
val cameraController = remember {
LifecycleCameraController(context).apply {
setEnabledUseCases(
CameraController.IMAGE_CAPTURE or
CameraController.VIDEO_CAPTURE
)
}
}
// 创建拍照工具实例
val (photoCaptureHelper, takePhoto) = rememberPhotoCapture(
cameraController = cameraController,
onSuccess = { savedUri ->
// 处理拍照成功的逻辑
photoUri = savedUri
Timber.d("photoUri = $photoUri")
Toast.makeText(context, "图片已保存", Toast.LENGTH_SHORT).show()
showCamera = false
GlobalData.imageUri = photoUri
},
onError = { error ->
// 处理拍照失败的逻辑
Toast.makeText(context, error, Toast.LENGTH_SHORT).show()
GlobalData.imageUri = null
}
)
Column(
modifier = modifier
.width(428.dp)
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(24.dp)
) {
if (showCamera) {
// 摄像头预览
CameraPreview(
modifier = Modifier
.width(428.dp)
.height(321.dp), controller = cameraController
)
} else {
if (photoUri == null) {
// 图片预览区域
Column(
modifier = Modifier
.fillMaxWidth()
.height(321.dp)
.dashedBorder(strokeWidth = 2.dp, cornerRadiusDp = 15.dp)
.clickable {
showCamera = true
},
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Image(
painter = painterResource(R.mipmap.ic_camera),
contentDescription = "默认图片",
modifier = Modifier
.width(96.dp)
.height(76.dp)
)
Spacer(modifier = Modifier.height(24.dp))
Text(
"图片采集",
style = AppTypography.grayTextStyle.copy(color = Color(0xFFB4B4C8))
)
}
} else {
Column(
modifier = Modifier
.fillMaxWidth()
.height(321.dp)
.dashedBorder(strokeWidth = 2.dp, cornerRadiusDp = 15.dp),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
AsyncImage(
model = photoUri,
contentDescription = "照片",
modifier = Modifier.fillMaxSize()
)
}
}
}
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.End
) {
CustomOutlinedButton(
modifier = Modifier
.weight(1f)
.height(80.dp),
text = "取消",
fontSize = 30.sp,
borderColor = colorResource(R.color.green),
textColor = colorResource(R.color.green),
onClick = {
Timber.d("点击取消")
showCamera = true
photoUri?.let {
FileUtils.deleteFileWithUri(context, photoUri!!)
}
photoUri = null
}
)
Spacer(modifier = Modifier.width(20.dp))
CustomButton(
modifier = Modifier
.weight(1f)
.height(80.dp),
text = "采集",
onClick = {
Timber.d("点击采集")
if (!showCamera) {
ToastUtils.showToast("请先开启图片预览")
return@CustomButton
}
takePhoto()
},
borderColor = colorResource(R.color.green),
textColor = colorResource(R.color.white),
fontSize = 30.sp,
showButtonIcon = true
)
}
}
// 生命周期管理
DisposableEffect(lifecycleOwner) {
Timber.d("cameraController")
cameraController.bindToLifecycle(lifecycleOwner)
onDispose { }
}
}
//package com.sw.inbound.ui.weight
//
//import android.net.Uri
//import android.widget.Toast
//import androidx.camera.view.CameraController
//import androidx.camera.view.LifecycleCameraController
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.width
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.DisposableEffect
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.platform.LocalContext
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import androidx.lifecycle.compose.LocalLifecycleOwner
//import coil.compose.AsyncImage
//import com.sw.inbound.GlobalData
//import com.sw.inbound.R
//import com.sw.inbound.ext.dashedBorder
//import com.sw.inbound.ui.theme.AppTypography
//import com.sw.inbound.utils.FileUtils
//import com.sw.inbound.utils.ToastUtils
//import com.sw.inbound.utils.rememberPhotoCapture
//import timber.log.Timber
//
///**
// * 相机预览 -默认不预览,支持拍照
// */
//@Composable
//fun CameraCaptureLayout(
// modifier: Modifier = Modifier
//) {
// val context = LocalContext.current
// var showCamera by remember { mutableStateOf(false) }
// val lifecycleOwner = LocalLifecycleOwner.current
// var photoUri by remember { mutableStateOf<Uri?>(null) }
//
// // CameraX 控制器
// val cameraController = remember {
// LifecycleCameraController(context).apply {
// setEnabledUseCases(
// CameraController.IMAGE_CAPTURE or
// CameraController.VIDEO_CAPTURE
// )
// }
// }
//
// // 创建拍照工具实例
// val (photoCaptureHelper, takePhoto) = rememberPhotoCapture(
// cameraController = cameraController,
// onSuccess = { savedUri ->
// // 处理拍照成功的逻辑
// photoUri = savedUri
// Timber.d("photoUri = $photoUri")
// Toast.makeText(context, "图片已保存", Toast.LENGTH_SHORT).show()
// showCamera = false
// GlobalData.imageUri = photoUri
// },
// onError = { error ->
// // 处理拍照失败的逻辑
// Toast.makeText(context, error, Toast.LENGTH_SHORT).show()
// GlobalData.imageUri = null
// }
// )
//
// Column(
// modifier = modifier
// .width(428.dp)
// .padding(16.dp),
// horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.spacedBy(24.dp)
// ) {
// if (showCamera) {
// // 摄像头预览
// CameraPreview(
// modifier = Modifier
// .width(428.dp)
// .height(321.dp), controller = cameraController
// )
// } else {
// if (photoUri == null) {
// // 图片预览区域
// Column(
// modifier = Modifier
// .fillMaxWidth()
// .height(321.dp)
// .dashedBorder(strokeWidth = 2.dp, cornerRadiusDp = 15.dp)
// .clickable {
// showCamera = true
// },
// horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.Center
// ) {
// Image(
// painter = painterResource(R.mipmap.ic_camera),
// contentDescription = "默认图片",
// modifier = Modifier
// .width(96.dp)
// .height(76.dp)
// )
// Spacer(modifier = Modifier.height(24.dp))
// Text(
// "图片采集",
// style = AppTypography.grayTextStyle.copy(color = Color(0xFFB4B4C8))
// )
// }
// } else {
// Column(
// modifier = Modifier
// .fillMaxWidth()
// .height(321.dp)
// .dashedBorder(strokeWidth = 2.dp, cornerRadiusDp = 15.dp),
// horizontalAlignment = Alignment.CenterHorizontally,
// verticalArrangement = Arrangement.Center
// ) {
// AsyncImage(
// model = photoUri,
// contentDescription = "照片",
// modifier = Modifier.fillMaxSize()
// )
// }
// }
// }
//
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.End
// ) {
// CustomOutlinedButton(
// modifier = Modifier
// .weight(1f)
// .height(80.dp),
// text = "取消",
// fontSize = 30.sp,
// borderColor = colorResource(R.color.green),
// textColor = colorResource(R.color.green),
// onClick = {
// Timber.d("点击取消")
// showCamera = true
// photoUri?.let {
// FileUtils.deleteFileWithUri(context, photoUri!!)
// }
// photoUri = null
// }
// )
// Spacer(modifier = Modifier.width(20.dp))
//
// CustomButton(
// modifier = Modifier
// .weight(1f)
// .height(80.dp),
// text = "采集",
// onClick = {
// Timber.d("点击采集")
// if (!showCamera) {
// ToastUtils.showToast("请先开启图片预览")
// return@CustomButton
// }
// takePhoto()
// },
// borderColor = colorResource(R.color.green),
// textColor = colorResource(R.color.white),
// fontSize = 30.sp,
// showButtonIcon = true
// )
// }
// }
//
// // 生命周期管理
// DisposableEffect(lifecycleOwner) {
// Timber.d("cameraController")
// cameraController.bindToLifecycle(lifecycleOwner)
// onDispose { }
// }
//}
@@ -1,52 +1,52 @@
package com.sw.inbound.ui.weight
import android.net.Uri
import androidx.camera.view.LifecycleCameraController
import androidx.camera.view.PreviewView
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.viewinterop.AndroidView
import coil.compose.AsyncImage
import com.sw.inbound.R
/**
* 相机预览
*/
@Composable
fun CameraPreview(
controller: LifecycleCameraController,
modifier: Modifier = Modifier,
photoUri: Uri? = null
) {
Box(modifier = modifier) {
AndroidView(
factory = { ctx ->
PreviewView(ctx).apply {
this.controller = controller
scaleType = PreviewView.ScaleType.FILL_CENTER // 控制预览缩放
}
},
modifier = Modifier.fillMaxSize()
)
if (photoUri != null) {
AsyncImage(
modifier = Modifier.fillMaxSize(),
model = photoUri,
contentDescription = "照片",
)
}
Image(
modifier = Modifier
.fillMaxSize()
.padding(30.dp),
painter = painterResource(R.mipmap.ic_scan),
contentDescription = "扫描"
)
}
}
//package com.sw.inbound.ui.weight
//
//import android.net.Uri
//import androidx.camera.view.LifecycleCameraController
//import androidx.camera.view.PreviewView
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.padding
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.viewinterop.AndroidView
//import coil.compose.AsyncImage
//import com.sw.inbound.R
//
///**
// * 相机预览
// */
//@Composable
//fun CameraPreview(
// controller: LifecycleCameraController,
// modifier: Modifier = Modifier,
// photoUri: Uri? = null
//) {
// Box(modifier = modifier) {
// AndroidView(
// factory = { ctx ->
// PreviewView(ctx).apply {
// this.controller = controller
// scaleType = PreviewView.ScaleType.FILL_CENTER // 控制预览缩放
// }
// },
// modifier = Modifier.fillMaxSize()
// )
// if (photoUri != null) {
// AsyncImage(
// modifier = Modifier.fillMaxSize(),
// model = photoUri,
// contentDescription = "照片",
// )
// }
// Image(
// modifier = Modifier
// .fillMaxSize()
// .padding(30.dp),
// painter = painterResource(R.mipmap.ic_scan),
// contentDescription = "扫描"
// )
// }
//}
@@ -1,108 +1,108 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sw.inbound.R
/**
* 空心按钮
*/
@Composable
fun CustomOutlinedButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
textColor: Color = colorResource(R.color.blue),
borderColor: Color = Color.Blue,
cornerRadius: Dp = 8.dp,
borderWidth: Dp = 1.dp,
fontWeight: FontWeight = FontWeight.Bold,
fontSize: TextUnit = 24.sp
) {
OutlinedButton(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(cornerRadius),
border = BorderStroke(borderWidth, color = borderColor),
colors = ButtonDefaults.buttonColors(
containerColor = Color.Transparent,
contentColor = textColor
)
) {
Text(
text = text,
style = TextStyle(
fontWeight = fontWeight,
fontSize = fontSize,
color = textColor
)
)
}
}
/**
* 实心按钮
*/
@Composable
fun CustomButton(
text: String,
onClick: () -> Unit,
modifier: Modifier = Modifier,
textColor: Color = colorResource(R.color.white),
borderColor: Color = colorResource(R.color.green),
cornerRadius: Dp = 8.dp,
borderWidth: Dp = 1.dp,
fontWeight: FontWeight = FontWeight.Bold,
fontSize: TextUnit = 24.sp,
showButtonIcon: Boolean = false
) {
Button(
onClick = onClick,
modifier = modifier,
shape = RoundedCornerShape(cornerRadius),
border = BorderStroke(borderWidth, color = borderColor),
colors = ButtonDefaults.buttonColors(
containerColor = borderColor,
contentColor = textColor
)
) {
Row(verticalAlignment = Alignment.CenterVertically) {
if (showButtonIcon) {
Image(
painter = painterResource(R.mipmap.ic_camera_small),
contentDescription = "采集"
)
Spacer(modifier = Modifier.width(13.dp))
}
Text(
text = text,
style = TextStyle(
fontWeight = fontWeight,
fontSize = fontSize,
color = textColor
)
)
}
}
}
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.BorderStroke
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material3.Button
//import androidx.compose.material3.ButtonDefaults
//import androidx.compose.material3.OutlinedButton
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.unit.Dp
//import androidx.compose.ui.unit.TextUnit
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import com.sw.inbound.R
//
///**
// * 空心按钮
// */
//@Composable
//fun CustomOutlinedButton(
// text: String,
// onClick: () -> Unit,
// modifier: Modifier = Modifier,
// textColor: Color = colorResource(R.color.blue),
// borderColor: Color = Color.Blue,
// cornerRadius: Dp = 8.dp,
// borderWidth: Dp = 1.dp,
// fontWeight: FontWeight = FontWeight.Bold,
// fontSize: TextUnit = 24.sp
//) {
// OutlinedButton(
// onClick = onClick,
// modifier = modifier,
// shape = RoundedCornerShape(cornerRadius),
// border = BorderStroke(borderWidth, color = borderColor),
// colors = ButtonDefaults.buttonColors(
// containerColor = Color.Transparent,
// contentColor = textColor
// )
// ) {
// Text(
// text = text,
// style = TextStyle(
// fontWeight = fontWeight,
// fontSize = fontSize,
// color = textColor
// )
// )
// }
//}
//
///**
// * 实心按钮
// */
//@Composable
//fun CustomButton(
// text: String,
// onClick: () -> Unit,
// modifier: Modifier = Modifier,
// textColor: Color = colorResource(R.color.white),
// borderColor: Color = colorResource(R.color.green),
// cornerRadius: Dp = 8.dp,
// borderWidth: Dp = 1.dp,
// fontWeight: FontWeight = FontWeight.Bold,
// fontSize: TextUnit = 24.sp,
// showButtonIcon: Boolean = false
//) {
// Button(
// onClick = onClick,
// modifier = modifier,
// shape = RoundedCornerShape(cornerRadius),
// border = BorderStroke(borderWidth, color = borderColor),
// colors = ButtonDefaults.buttonColors(
// containerColor = borderColor,
// contentColor = textColor
// )
// ) {
// Row(verticalAlignment = Alignment.CenterVertically) {
// if (showButtonIcon) {
// Image(
// painter = painterResource(R.mipmap.ic_camera_small),
// contentDescription = "采集"
// )
// Spacer(modifier = Modifier.width(13.dp))
// }
//
// Text(
// text = text,
// style = TextStyle(
// fontWeight = fontWeight,
// fontSize = fontSize,
// color = textColor
// )
// )
// }
// }
//}
@@ -1,99 +1,99 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.unit.dp
import com.sw.inbound.R
import com.sw.inbound.ui.theme.AppTypography
import timber.log.Timber
/**
* 搜索框
*/
@Composable
fun CustomSearchView(onValueChange: (String) -> Unit = {}, onSearchClick: (String) -> Unit) {
var searchText by remember { mutableStateOf("") }
val borderColor = Color(0xFFDCDCF0)
val focusManager = LocalFocusManager.current
// 搜索框
Box(
modifier = Modifier
.fillMaxWidth()
.height(60.dp)
.border(
width = 2.dp,
color = borderColor,
shape = RoundedCornerShape(10.dp) // 圆角边框
)
.background(Color.Transparent) // 透明背景
) {
TextField(
value = searchText,
onValueChange = {
searchText = it
onValueChange
},
modifier = Modifier
.fillMaxWidth()
.padding(end = 25.dp), // 为图标留出空间
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = Color.Transparent,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent
),
placeholder = {
Text("输入物品名称", style = AppTypography.gray96a0aaTextStyle)
},
singleLine = true,
textStyle = AppTypography.black141428TextStyle,
keyboardOptions = KeyboardOptions.Default.copy(
imeAction = ImeAction.Search
),
keyboardActions = KeyboardActions(onSearch = {
focusManager.clearFocus()
onSearchClick(searchText)
}),
trailingIcon = {
Image(
painter = painterResource(R.mipmap.ic_search),
contentDescription = "搜索",
modifier = Modifier
.width(32.dp)
.height(32.dp)
.clickable {
Timber.d("搜索点击")
focusManager.clearFocus()
onSearchClick(searchText)
}
)
},
)
}
}
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.border
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.foundation.text.KeyboardActions
//import androidx.compose.foundation.text.KeyboardOptions
//import androidx.compose.material3.Text
//import androidx.compose.material3.TextField
//import androidx.compose.material3.TextFieldDefaults
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.platform.LocalFocusManager
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.input.ImeAction
//import androidx.compose.ui.unit.dp
//import com.sw.inbound.R
//import com.sw.inbound.ui.theme.AppTypography
//import timber.log.Timber
//
///**
// * 搜索框
// */
//@Composable
//fun CustomSearchView(onValueChange: (String) -> Unit = {}, onSearchClick: (String) -> Unit) {
// var searchText by remember { mutableStateOf("") }
// val borderColor = Color(0xFFDCDCF0)
// val focusManager = LocalFocusManager.current
// // 搜索框
// Box(
// modifier = Modifier
// .fillMaxWidth()
// .height(60.dp)
// .border(
// width = 2.dp,
// color = borderColor,
// shape = RoundedCornerShape(10.dp) // 圆角边框
// )
// .background(Color.Transparent) // 透明背景
// ) {
// TextField(
// value = searchText,
// onValueChange = {
// searchText = it
// onValueChange
// },
// modifier = Modifier
// .fillMaxWidth()
// .padding(end = 25.dp), // 为图标留出空间
// colors = TextFieldDefaults.colors(
// focusedContainerColor = Color.Transparent,
// unfocusedContainerColor = Color.Transparent,
// disabledContainerColor = Color.Transparent,
// focusedIndicatorColor = Color.Transparent,
// unfocusedIndicatorColor = Color.Transparent,
// disabledIndicatorColor = Color.Transparent
// ),
// placeholder = {
// Text("输入物品名称", style = AppTypography.gray96a0aaTextStyle)
// },
// singleLine = true,
// textStyle = AppTypography.black141428TextStyle,
// keyboardOptions = KeyboardOptions.Default.copy(
// imeAction = ImeAction.Search
// ),
// keyboardActions = KeyboardActions(onSearch = {
// focusManager.clearFocus()
// onSearchClick(searchText)
// }),
// trailingIcon = {
// Image(
// painter = painterResource(R.mipmap.ic_search),
// contentDescription = "搜索",
// modifier = Modifier
// .width(32.dp)
// .height(32.dp)
// .clickable {
// Timber.d("搜索点击")
// focusManager.clearFocus()
// onSearchClick(searchText)
// }
// )
// },
// )
//
// }
//}
@@ -1,29 +1,29 @@
package com.sw.inbound.ui.weight
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import com.sw.inbound.ui.theme.AppTypography
/**
* 自定义单行文本
*/
@Composable
fun CustomSingleRightText(
modifier: Modifier,
text: String,
style: TextStyle = AppTypography.blackTextStyle,
textAlign: TextAlign = TextAlign.End
) {
Text(
modifier = modifier,
text = text,
textAlign = textAlign,
style = style,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
//package com.sw.inbound.ui.weight
//
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.style.TextAlign
//import androidx.compose.ui.text.style.TextOverflow
//import com.sw.inbound.ui.theme.AppTypography
//
///**
// * 自定义单行文本
// */
//@Composable
//fun CustomSingleRightText(
// modifier: Modifier,
// text: String,
// style: TextStyle = AppTypography.blackTextStyle,
// textAlign: TextAlign = TextAlign.End
//) {
// Text(
// modifier = modifier,
// text = text,
// textAlign = textAlign,
// style = style,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// )
//}
@@ -1,226 +1,226 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.sw.inbound.ext.isValidFloat
import com.sw.inbound.ext.isValidNumber
import com.sw.inbound.ui.theme.AppTypography
import com.sw.inbound.ui.theme.Black_141428
import com.sw.inbound.ui.theme.Gray_DCDCF0
import timber.log.Timber
//@Preview(showBackground = true)
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.background
//import androidx.compose.foundation.border
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.fillMaxHeight
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.wrapContentHeight
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.foundation.text.KeyboardActions
//import androidx.compose.foundation.text.KeyboardOptions
//import androidx.compose.material3.LocalTextStyle
//import androidx.compose.material3.Text
//import androidx.compose.material3.TextField
//import androidx.compose.material3.TextFieldDefaults
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.focus.FocusDirection
//import androidx.compose.ui.focus.onFocusChanged
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.platform.LocalFocusManager
//import androidx.compose.ui.text.TextStyle
//import androidx.compose.ui.text.font.FontWeight
//import androidx.compose.ui.text.input.ImeAction
//import androidx.compose.ui.text.style.TextAlign
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import com.sw.inbound.ext.isValidFloat
//import com.sw.inbound.ext.isValidNumber
//import com.sw.inbound.ui.theme.AppTypography
//import com.sw.inbound.ui.theme.Black_141428
//import com.sw.inbound.ui.theme.Gray_DCDCF0
//import timber.log.Timber
//
////@Preview(showBackground = true)
////@Composable
////fun testTextField() {
//// Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(20.dp)) {
//// CustomTextField(value = "123", onValueChange = {}, textAlign = TextAlign.Start)
//// CustomTextField(value = "", onValueChange = {}, textAlign = TextAlign.Start)
//// CustomTextField(value = "", onValueChange = {}, textAlign = TextAlign.End)
//// CustomTextField(
//// value = "123",
//// onValueChange = {},
//// textAlign = TextAlign.End,
//// trailingLabel = "克"
//// )
//// CustomTextField(
//// enabled = false,
//// modifier = Modifier
//// .height(60.dp),
//// value = "123",
//// onValueChange = {},
//// textAlign = TextAlign.End,
//// leadingIcon =
//// {
//// Button(
//// onClick = {},
//// modifier = Modifier
//// .padding(0.dp)
//// .fillMaxHeight(),
//// shape = RoundedCornerShape(10.dp),
//// border = BorderStroke(2.dp, color = Color.White),
//// colors = ButtonDefaults.buttonColors(
//// containerColor = Color.White,
//// contentColor = Black_141428
//// ),
//// ) { Text(text = "累计", style = AppTypography.black141428TextStyle) }
//// }
//// )
//// }
////
////}
//
//enum class InputType {
// Text, // 字符串
// Number, // 数字
// Decimal, // 浮点
// Percent, // 百分比
//}
//
///**
// * 自定义输入框
// */
//@Composable
//fun testTextField() {
// Column(verticalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.padding(20.dp)) {
// CustomTextField(value = "123", onValueChange = {}, textAlign = TextAlign.Start)
// CustomTextField(value = "", onValueChange = {}, textAlign = TextAlign.Start)
// CustomTextField(value = "", onValueChange = {}, textAlign = TextAlign.End)
// CustomTextField(
// value = "123",
// onValueChange = {},
// textAlign = TextAlign.End,
// trailingLabel = "克"
// )
// CustomTextField(
// enabled = false,
// modifier = Modifier
// .height(60.dp),
// value = "123",
// onValueChange = {},
// textAlign = TextAlign.End,
// leadingIcon =
// {
// Button(
// onClick = {},
// modifier = Modifier
// .padding(0.dp)
// .fillMaxHeight(),
// shape = RoundedCornerShape(10.dp),
// border = BorderStroke(2.dp, color = Color.White),
// colors = ButtonDefaults.buttonColors(
// containerColor = Color.White,
// contentColor = Black_141428
// ),
// ) { Text(text = "累计", style = AppTypography.black141428TextStyle) }
// }
// )
//fun CustomTextField(
// value: String,
// onValueChange: (String) -> Unit,
// modifier: Modifier = Modifier.height(60.dp),
// placeholderValue: String = "请录入", // 占位文本
// trailingLabel: String? = null, // 右侧文字
// textAlign: TextAlign = TextAlign.Start,
// textStyle: TextStyle? = null,
// leadingIcon: @Composable (() -> Unit)? = null, // 左侧布局
// enabled: Boolean = true,
// inputType: InputType = InputType.Text, // 输入类型
// hasNext: Boolean = true, // 键盘显示下一个
// isInitUpdate: Boolean = false, // 是否需要根据原始数据变动
// keyboardOptions: KeyboardOptions? = null,
// keyboardActions: KeyboardActions? = null,
// onClick: () -> Unit = {}, // 点击
//) {
// val containerColor = if (enabled) Color.Transparent else Gray_DCDCF0
// var inputValue by remember(if (isInitUpdate) value else null) {
// mutableStateOf(value)
// }
// val focusManager = LocalFocusManager.current
//
// fun onEditingComplete(isFocus: Boolean) {
// Timber.d("onEditingComplete inputValue = $inputValue, isFocus = $isFocus")
// onValueChange(inputValue)
// }
//
// var newTextStyle = textStyle
// ?: LocalTextStyle.current.copy(
// color = Black_141428,
// fontSize = 24.sp,
// fontWeight = FontWeight.Bold,
// textAlign = textAlign
// )
// Box(modifier = modifier) {
// TextField(
// enabled = enabled,
// value = inputValue,
// textStyle = newTextStyle,
// onValueChange = { newValue ->
// Timber.d("onValueChange newValue = $newValue")
// when (inputType) {
// InputType.Number -> {
// if (newValue.isEmpty() || newValue.isValidNumber()) {
// inputValue = newValue
// onEditingComplete(true)
// }
// }
//
// InputType.Decimal -> {
// if (newValue.isEmpty() || newValue.isValidFloat()) {
// inputValue = newValue
// onEditingComplete(true)
// }
// }
//
// InputType.Percent -> {
// val range: ClosedFloatingPointRange<Float> = 0f..100f
// if (newValue.isEmpty() || (newValue.isValidFloat(1) && newValue.toFloat() in range)) {
// inputValue = newValue
// onEditingComplete(true)
// }
// }
//
// else -> {
// inputValue = newValue
// onEditingComplete(true)
// }
// }
// },
//
// modifier = Modifier
// .fillMaxWidth()
// .background(Color.Transparent)
// .border(
// width = 2.dp,
// color = Gray_DCDCF0,
// shape = RoundedCornerShape(10.dp)
// )
// .clickable(onClick = onClick)
//// .focusable()
// .onFocusChanged(onFocusChanged = { focusState ->
// {
// onEditingComplete(focusState.isFocused)
// }
// }),
// colors = TextFieldDefaults.colors(
// focusedContainerColor = Color.Transparent,
// unfocusedContainerColor = Color.Transparent,
// disabledContainerColor = containerColor,
// focusedIndicatorColor = Color.Transparent,
// unfocusedIndicatorColor = Color.Transparent,
// disabledIndicatorColor = Color.Transparent
// ),
// shape = RoundedCornerShape(10.dp),
// placeholder = {
// Text(
// modifier = Modifier
// .fillMaxWidth()
// .fillMaxHeight()
// .wrapContentHeight(Alignment.CenterVertically),
// text = placeholderValue,
// textAlign = textAlign,
// style = AppTypography.gray96a0aaTextStyle
// )
// },
// leadingIcon = leadingIcon,
// trailingIcon = trailingLabel?.let { label ->
// {
// Box(modifier = Modifier.padding(start = 10.dp, end = 20.dp)) {
// Text(
// text = trailingLabel,
// modifier = Modifier
// .fillMaxHeight()
// .wrapContentHeight(Alignment.CenterVertically),
// style = AppTypography.gray96a0aaTextStyle
// )
// }
// }
// },
// keyboardOptions = keyboardOptions
// ?: KeyboardOptions.Default.copy(imeAction = if (hasNext) ImeAction.Next else ImeAction.Done),
// keyboardActions = keyboardActions ?: KeyboardActions(onNext = {
// focusManager.moveFocus(focusDirection = FocusDirection.Next)
// onEditingComplete(false)
// }, onDone = {
// focusManager.clearFocus()
// onEditingComplete(false)
// })
// )
// }
//}
enum class InputType {
Text, // 字符串
Number, // 数字
Decimal, // 浮点
Percent, // 百分比
}
/**
* 自定义输入框
*/
@Composable
fun CustomTextField(
value: String,
onValueChange: (String) -> Unit,
modifier: Modifier = Modifier.height(60.dp),
placeholderValue: String = "请录入", // 占位文本
trailingLabel: String? = null, // 右侧文字
textAlign: TextAlign = TextAlign.Start,
textStyle: TextStyle? = null,
leadingIcon: @Composable (() -> Unit)? = null, // 左侧布局
enabled: Boolean = true,
inputType: InputType = InputType.Text, // 输入类型
hasNext: Boolean = true, // 键盘显示下一个
isInitUpdate: Boolean = false, // 是否需要根据原始数据变动
keyboardOptions: KeyboardOptions? = null,
keyboardActions: KeyboardActions? = null,
onClick: () -> Unit = {}, // 点击
) {
val containerColor = if (enabled) Color.Transparent else Gray_DCDCF0
var inputValue by remember(if (isInitUpdate) value else null) {
mutableStateOf(value)
}
val focusManager = LocalFocusManager.current
fun onEditingComplete(isFocus: Boolean) {
Timber.d("onEditingComplete inputValue = $inputValue, isFocus = $isFocus")
onValueChange(inputValue)
}
var newTextStyle = textStyle
?: LocalTextStyle.current.copy(
color = Black_141428,
fontSize = 24.sp,
fontWeight = FontWeight.Bold,
textAlign = textAlign
)
Box(modifier = modifier) {
TextField(
enabled = enabled,
value = inputValue,
textStyle = newTextStyle,
onValueChange = { newValue ->
Timber.d("onValueChange newValue = $newValue")
when (inputType) {
InputType.Number -> {
if (newValue.isEmpty() || newValue.isValidNumber()) {
inputValue = newValue
onEditingComplete(true)
}
}
InputType.Decimal -> {
if (newValue.isEmpty() || newValue.isValidFloat()) {
inputValue = newValue
onEditingComplete(true)
}
}
InputType.Percent -> {
val range: ClosedFloatingPointRange<Float> = 0f..100f
if (newValue.isEmpty() || (newValue.isValidFloat(1) && newValue.toFloat() in range)) {
inputValue = newValue
onEditingComplete(true)
}
}
else -> {
inputValue = newValue
onEditingComplete(true)
}
}
},
modifier = Modifier
.fillMaxWidth()
.background(Color.Transparent)
.border(
width = 2.dp,
color = Gray_DCDCF0,
shape = RoundedCornerShape(10.dp)
)
.clickable(onClick = onClick)
// .focusable()
.onFocusChanged(onFocusChanged = { focusState ->
{
onEditingComplete(focusState.isFocused)
}
}),
colors = TextFieldDefaults.colors(
focusedContainerColor = Color.Transparent,
unfocusedContainerColor = Color.Transparent,
disabledContainerColor = containerColor,
focusedIndicatorColor = Color.Transparent,
unfocusedIndicatorColor = Color.Transparent,
disabledIndicatorColor = Color.Transparent
),
shape = RoundedCornerShape(10.dp),
placeholder = {
Text(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight()
.wrapContentHeight(Alignment.CenterVertically),
text = placeholderValue,
textAlign = textAlign,
style = AppTypography.gray96a0aaTextStyle
)
},
leadingIcon = leadingIcon,
trailingIcon = trailingLabel?.let { label ->
{
Box(modifier = Modifier.padding(start = 10.dp, end = 20.dp)) {
Text(
text = trailingLabel,
modifier = Modifier
.fillMaxHeight()
.wrapContentHeight(Alignment.CenterVertically),
style = AppTypography.gray96a0aaTextStyle
)
}
}
},
keyboardOptions = keyboardOptions
?: KeyboardOptions.Default.copy(imeAction = if (hasNext) ImeAction.Next else ImeAction.Done),
keyboardActions = keyboardActions ?: KeyboardActions(onNext = {
focusManager.moveFocus(focusDirection = FocusDirection.Next)
onEditingComplete(false)
}, onDone = {
focusManager.clearFocus()
onEditingComplete(false)
})
)
}
}
@@ -1,126 +1,126 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
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 com.sw.inbound.R
@Preview
@Composable
fun BackButton() {
Row(
modifier = Modifier
.fillMaxWidth()
.padding(start = 30.dp, end = 30.dp, bottom = 20.dp)
.height(100.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
// 左侧图标+文字
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.width(220.dp)
.height(100.dp)
.background(
color = colorResource(R.color.blue),
shape = RoundedCornerShape(10.dp)
)
.clickable {
}
) {
Image(
painter = painterResource(R.mipmap.ic_back_white),
contentDescription = "返回",
modifier = Modifier.size(40.dp)
)
Spacer(modifier = Modifier.width(21.dp))
Text(
text = "返回",
style = TextStyle(
color = colorResource(R.color.white),
fontWeight = FontWeight.Bold,
fontSize = 36.sp
)
)
}
// Row {
// if (false) {
// CustomOutlinedButton(
// modifier = Modifier
// .width(300.dp)
// .height(100.dp),
// text = "ok",
// fontSize = 36.sp,
// onClick = {}
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.size
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.TextStyle
//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 com.sw.inbound.R
//
//@Preview
//@Composable
//fun BackButton() {
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .padding(start = 30.dp, end = 30.dp, bottom = 20.dp)
// .height(100.dp),
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.SpaceBetween
// ) {
// // 左侧图标+文字
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .width(220.dp)
// .height(100.dp)
// .background(
// color = colorResource(R.color.blue),
// shape = RoundedCornerShape(10.dp)
// )
// .clickable {
//
// }
// ) {
// Image(
// painter = painterResource(R.mipmap.ic_back_white),
// contentDescription = "返回",
// modifier = Modifier.size(40.dp)
// )
// Spacer(modifier = Modifier.width(21.dp))
// Text(
// text = "返回",
// style = TextStyle(
// color = colorResource(R.color.white),
// fontWeight = FontWeight.Bold,
// fontSize = 36.sp
// )
// Spacer(modifier = Modifier.width(20.dp))
// }
// CustomButton(
// modifier = Modifier
// .width(300.dp)
// .height(100.dp),
// text = "Button",
// onClick = {},
// borderColor = colorResource(R.color.blue),
// textColor = colorResource(R.color.white),
// fontSize = 36.sp
// )
// }
}
}
@Composable
fun BackButton2() {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center,
modifier = Modifier
.width(220.dp)
.height(100.dp)
.background(
color = colorResource(R.color.blue),
shape = RoundedCornerShape(10.dp)
)
.clickable {
}
) {
Image(
painter = painterResource(R.mipmap.ic_home2),
contentDescription = "返回",
modifier = Modifier.size(40.dp)
)
Spacer(modifier = Modifier.width(21.dp))
Text(
text = "返回",
style = TextStyle(
color = colorResource(R.color.white),
fontWeight = FontWeight.Bold,
fontSize = 36.sp
)
)
}
}
//
//// Row {
//// if (false) {
//// CustomOutlinedButton(
//// modifier = Modifier
//// .width(300.dp)
//// .height(100.dp),
//// text = "ok",
//// fontSize = 36.sp,
//// onClick = {}
//// )
//// Spacer(modifier = Modifier.width(20.dp))
//// }
//// CustomButton(
//// modifier = Modifier
//// .width(300.dp)
//// .height(100.dp),
//// text = "Button",
//// onClick = {},
//// borderColor = colorResource(R.color.blue),
//// textColor = colorResource(R.color.white),
//// fontSize = 36.sp
//// )
//// }
// }
//}
//@Composable
//fun BackButton2() {
// Row(
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.Center,
// modifier = Modifier
// .width(220.dp)
// .height(100.dp)
// .background(
// color = colorResource(R.color.blue),
// shape = RoundedCornerShape(10.dp)
// )
// .clickable {
//
// }
// ) {
// Image(
// painter = painterResource(R.mipmap.ic_home2),
// contentDescription = "返回",
// modifier = Modifier.size(40.dp)
// )
// Spacer(modifier = Modifier.width(21.dp))
// Text(
// text = "返回",
// style = TextStyle(
// color = colorResource(R.color.white),
// fontWeight = FontWeight.Bold,
// fontSize = 36.sp
// )
// )
// }
//}
@@ -1,145 +1,145 @@
package com.sw.inbound.ui.weight
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.sw.inbound.R
import com.sw.inbound.ext.bold
import com.sw.inbound.model.request.PurchaseWarehouseParam
import com.sw.inbound.ui.theme.AppTypography
/**
* 自采购 左侧列表
*/
@Composable
fun SelfProcurementListItem(
modifier: Modifier = Modifier,
productList: List<PurchaseWarehouseParam>,
checkedItem: PurchaseWarehouseParam? = null,
onItemCheckedClick: (PurchaseWarehouseParam) -> Unit = {},
showClose: Boolean = false,
onCloseClick: (Int, PurchaseWarehouseParam) -> Unit,
) {
Column(
modifier = modifier
// .padding(horizontal = 30.dp)
) {
// 左侧列表标题
Row(
modifier = Modifier
.fillMaxWidth()
.padding(30.dp)
) {
CustomSingleRightText(
modifier = Modifier.weight(1f),
text = "名称",
style = AppTypography.gray96a0aaTextStyle.bold(),
textAlign = TextAlign.Start
)
Spacer(modifier = Modifier.width(10.dp))
CustomSingleRightText(
modifier = Modifier.width(100.dp),
text = "单价(元)",
style = AppTypography.gray96a0aaTextStyle.bold()
)
Spacer(modifier = Modifier.width(20.dp))
CustomSingleRightText(
modifier = Modifier.width(100.dp),
text = "数量",
style = AppTypography.gray96a0aaTextStyle.bold()
)
Spacer(modifier = Modifier.width(20.dp))
CustomSingleRightText(
modifier = Modifier.width(110.dp),
text = "金额(元)",
style = AppTypography.gray96a0aaTextStyle.bold()
)
if (showClose) {
Spacer(modifier = Modifier.width(78.dp))
}
}
// Spacer(modifier = Modifier.height(31.dp))
HorizontalDivider(thickness = 1.dp, color = colorResource(R.color.divider))
// Spacer(modifier = Modifier.height(31.dp))
// 左侧列表
LazyColumn() {
itemsIndexed(items = productList)
// items(
// items = productList,
// // 取消key,列表中可以插入同一物品
//// key = { it.goodsId }
//package com.sw.inbound.ui.weight
//
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.size
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.lazy.LazyColumn
//import androidx.compose.foundation.lazy.itemsIndexed
//import androidx.compose.material3.HorizontalDivider
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.style.TextAlign
//import androidx.compose.ui.unit.dp
//import com.sw.inbound.R
//import com.sw.inbound.ext.bold
//import com.sw.inbound.model.request.PurchaseWarehouseParam
//import com.sw.inbound.ui.theme.AppTypography
//
///**
// * 自采购 左侧列表
// */
//@Composable
//fun SelfProcurementListItem(
// modifier: Modifier = Modifier,
// productList: List<PurchaseWarehouseParam>,
// checkedItem: PurchaseWarehouseParam? = null,
// onItemCheckedClick: (PurchaseWarehouseParam) -> Unit = {},
// showClose: Boolean = false,
// onCloseClick: (Int, PurchaseWarehouseParam) -> Unit,
//) {
// Column(
// modifier = modifier
//// .padding(horizontal = 30.dp)
// ) {
// // 左侧列表标题
// Row(
// modifier = Modifier
// .fillMaxWidth()
// .padding(30.dp)
// ) {
// CustomSingleRightText(
// modifier = Modifier.weight(1f),
// text = "名称",
// style = AppTypography.gray96a0aaTextStyle.bold(),
// textAlign = TextAlign.Start
// )
{ index, it ->
Row(
modifier = Modifier
.background(color = Color.Transparent)
.padding(30.dp)
.clickable {
onItemCheckedClick(it)
}, verticalAlignment = Alignment.CenterVertically
) {
CustomSingleRightText(
modifier = Modifier.weight(1f),
text = it.goodsNameStr,
textAlign = TextAlign.Start
)
Spacer(modifier = Modifier.width(10.dp))
CustomSingleRightText(
modifier = Modifier.width(100.dp),
text = it.goodsUnitPriceStr,
style = AppTypography.blackTextStyle
)
Spacer(modifier = Modifier.width(20.dp))
CustomSingleRightText(
modifier = Modifier.width(100.dp),
text = "${it.goodsCountStr}${it.unitNameStr}",
style = AppTypography.blackTextStyle
)
Spacer(modifier = Modifier.width(20.dp))
CustomSingleRightText(
modifier = Modifier.width(110.dp),
text = it.goodsPriceStr,
style = AppTypography.blackTextStyle
)
if (showClose) {
Spacer(modifier = Modifier.width(30.dp))
Image(
modifier = Modifier
.size(48.dp)
.clickable {
onCloseClick(index, it)
},
painter = painterResource(R.mipmap.ic_delete),
contentDescription = "删除"
)
}
}
// Spacer(modifier = Modifier.height(33.dp))
// if (productList.indexOf(it) != productList.lastIndex)
HorizontalDivider(
thickness = 1.dp,
color = colorResource(R.color.divider)
)
// Spacer(modifier = Modifier.height(33.dp))
}
}
}
}
// Spacer(modifier = Modifier.width(10.dp))
// CustomSingleRightText(
// modifier = Modifier.width(100.dp),
// text = "单价(元)",
// style = AppTypography.gray96a0aaTextStyle.bold()
// )
// Spacer(modifier = Modifier.width(20.dp))
// CustomSingleRightText(
// modifier = Modifier.width(100.dp),
// text = "数量",
// style = AppTypography.gray96a0aaTextStyle.bold()
// )
// Spacer(modifier = Modifier.width(20.dp))
// CustomSingleRightText(
// modifier = Modifier.width(110.dp),
// text = "金额(元)",
// style = AppTypography.gray96a0aaTextStyle.bold()
// )
// if (showClose) {
// Spacer(modifier = Modifier.width(78.dp))
// }
// }
//// Spacer(modifier = Modifier.height(31.dp))
// HorizontalDivider(thickness = 1.dp, color = colorResource(R.color.divider))
//// Spacer(modifier = Modifier.height(31.dp))
// // 左侧列表
// LazyColumn() {
// itemsIndexed(items = productList)
//// items(
//// items = productList,
//// // 取消key,列表中可以插入同一物品
////// key = { it.goodsId }
//// )
// { index, it ->
// Row(
// modifier = Modifier
// .background(color = Color.Transparent)
// .padding(30.dp)
// .clickable {
// onItemCheckedClick(it)
// }, verticalAlignment = Alignment.CenterVertically
// ) {
// CustomSingleRightText(
// modifier = Modifier.weight(1f),
// text = it.goodsNameStr,
// textAlign = TextAlign.Start
// )
// Spacer(modifier = Modifier.width(10.dp))
// CustomSingleRightText(
// modifier = Modifier.width(100.dp),
// text = it.goodsUnitPriceStr,
// style = AppTypography.blackTextStyle
// )
// Spacer(modifier = Modifier.width(20.dp))
// CustomSingleRightText(
// modifier = Modifier.width(100.dp),
// text = "${it.goodsCountStr}${it.unitNameStr}",
// style = AppTypography.blackTextStyle
// )
// Spacer(modifier = Modifier.width(20.dp))
// CustomSingleRightText(
// modifier = Modifier.width(110.dp),
// text = it.goodsPriceStr,
// style = AppTypography.blackTextStyle
// )
// if (showClose) {
// Spacer(modifier = Modifier.width(30.dp))
// Image(
// modifier = Modifier
// .size(48.dp)
// .clickable {
// onCloseClick(index, it)
// },
// painter = painterResource(R.mipmap.ic_delete),
// contentDescription = "删除"
// )
// }
// }
//// Spacer(modifier = Modifier.height(33.dp))
//// if (productList.indexOf(it) != productList.lastIndex)
// HorizontalDivider(
// thickness = 1.dp,
// color = colorResource(R.color.divider)
// )
//// Spacer(modifier = Modifier.height(33.dp))
// }
// }
// }
//}
@@ -1,142 +1,142 @@
package com.sw.inbound.ui.weight
import android.content.Intent
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.colorResource
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.TextStyle
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 com.sw.inbound.MyApp
import com.sw.inbound.R
import com.sw.inbound.activity.FoodCollectionActivity
import com.sw.inbound.ext.medium
import com.sw.inbound.model.response.User
import com.sw.inbound.ui.theme.AppTypography
import com.sw.inbound.utils.DateTimeUtils
import com.sw.inbound.utils.ext.startActivity
import kotlinx.coroutines.delay
@OptIn(ExperimentalFoundationApi::class)
@Preview(
widthDp = 1920,
heightDp = 1080,
showBackground = true
)
/**
* 标题
*/
@Composable
fun TopTitleBar(
modifier: Modifier = Modifier,
// title: String = "采购单入库",
title: String = "出入库管理",
user: User? = null,
onLogoutClick: () -> Unit = {}
) {
var currentTime by remember { mutableStateOf(DateTimeUtils.getChineseDateString()) }
// 每秒更新一次时间
LaunchedEffect(Unit) {
while (true) {
delay(1000) // 1秒间隔
currentTime = DateTimeUtils.getChineseDateString()
}
}
Row(
modifier = modifier
.fillMaxWidth()
.padding(start = 60.dp, end = 60.dp, top = 22.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Box(modifier = Modifier
.wrapContentSize()
.clickable(onClick = {
MyApp.instance?.run {
startActivity(
Intent(this, FoodCollectionActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
)
}
})) {
Text(
text = title,
style = TextStyle(
fontWeight = FontWeight.Bold,
color = colorResource(R.color.title),
fontSize = 36.sp
),
modifier = Modifier
.wrapContentSize()
.padding(10.dp)
)
}
Spacer(modifier = Modifier.weight(1f))
if (user != null) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.height(60.dp)
.clickable {
onLogoutClick()
}) {
Text(text = user.name ?: "用户", style = AppTypography.blackTextStyle.medium())
Spacer(modifier = Modifier.width(21.dp))
Image(
modifier = Modifier.size(60.dp),
painter = painterResource(R.mipmap.ic_logout),
contentDescription = "退出"
)
}
} else {
Text(
// modifier = Modifier.combinedClickable(
// onClick = {},
// onLongClick = {
// onLogoutClick()
//package com.sw.inbound.ui.weight
//
//import android.content.Intent
//import androidx.compose.foundation.ExperimentalFoundationApi
//import androidx.compose.foundation.Image
//import androidx.compose.foundation.background
//import androidx.compose.foundation.clickable
//import androidx.compose.foundation.combinedClickable
//import androidx.compose.foundation.layout.Arrangement
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.Row
//import androidx.compose.foundation.layout.Spacer
//import androidx.compose.foundation.layout.fillMaxWidth
//import androidx.compose.foundation.layout.height
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.layout.size
//import androidx.compose.foundation.layout.width
//import androidx.compose.foundation.layout.wrapContentSize
//import androidx.compose.foundation.layout.wrapContentWidth
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.LaunchedEffect
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.res.colorResource
//import androidx.compose.ui.res.painterResource
//import androidx.compose.ui.text.TextStyle
//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 com.sw.inbound.MyApp
//import com.sw.inbound.R
//import com.sw.inbound.activity.FoodCollectionActivity
//import com.sw.inbound.ext.medium
//import com.sw.inbound.model.response.User
//import com.sw.inbound.ui.theme.AppTypography
//import com.sw.inbound.utils.DateTimeUtils
//import com.sw.inbound.utils.ext.startActivity
//import kotlinx.coroutines.delay
//
//
//@OptIn(ExperimentalFoundationApi::class)
//@Preview(
// widthDp = 1920,
// heightDp = 1080,
// showBackground = true
//)
///**
// * 标题
// */
//@Composable
//fun TopTitleBar(
// modifier: Modifier = Modifier,
//// title: String = "采购单入库",
// title: String = "出入库管理",
// user: User? = null,
// onLogoutClick: () -> Unit = {}
//) {
// var currentTime by remember { mutableStateOf(DateTimeUtils.getChineseDateString()) }
//
// // 每秒更新一次时间
// LaunchedEffect(Unit) {
// while (true) {
// delay(1000) // 1秒间隔
// currentTime = DateTimeUtils.getChineseDateString()
// }
// }
//
// Row(
// modifier = modifier
// .fillMaxWidth()
// .padding(start = 60.dp, end = 60.dp, top = 22.dp),
// verticalAlignment = Alignment.CenterVertically,
// horizontalArrangement = Arrangement.SpaceBetween
// ) {
//
// Box(modifier = Modifier
// .wrapContentSize()
// .clickable(onClick = {
// MyApp.instance?.run {
// startActivity(
// Intent(this, FoodCollectionActivity::class.java).apply {
// addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
// }
// )
// }
// })) {
// Text(
// text = title,
// style = TextStyle(
// fontWeight = FontWeight.Bold,
// color = colorResource(R.color.title),
// fontSize = 36.sp
// ),
text = currentTime,
style = TextStyle(
fontWeight = FontWeight.Medium,
color = colorResource(R.color.black),
fontSize = 24.sp
)
)
}
}
}
// modifier = Modifier
// .wrapContentSize()
// .padding(10.dp)
// )
// }
//
// Spacer(modifier = Modifier.weight(1f))
//
// if (user != null) {
// Row(
// verticalAlignment = Alignment.CenterVertically,
// modifier = Modifier
// .height(60.dp)
// .clickable {
// onLogoutClick()
// }) {
// Text(text = user.name ?: "用户", style = AppTypography.blackTextStyle.medium())
// Spacer(modifier = Modifier.width(21.dp))
// Image(
// modifier = Modifier.size(60.dp),
// painter = painterResource(R.mipmap.ic_logout),
// contentDescription = "退出"
// )
// }
// } else {
// Text(
//// modifier = Modifier.combinedClickable(
//// onClick = {},
//// onLongClick = {
//// onLogoutClick()
//// }
//// ),
// text = currentTime,
// style = TextStyle(
// fontWeight = FontWeight.Medium,
// color = colorResource(R.color.black),
// fontSize = 24.sp
// )
// )
// }
// }
//}
@@ -2,9 +2,9 @@ package com.sw.inbound.utils
import android.content.Context
import android.view.View
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalView
//import androidx.compose.runtime.Composable
//import androidx.compose.ui.platform.LocalContext
//import androidx.compose.ui.platform.LocalView
/**
* Context 工具类
@@ -17,18 +17,18 @@ object ContextUtils {
* 获取当前 Composable 的 Activity Context
* 只能在 @Composable 函数中调用
*/
@Composable
fun getActivityContext(): Context {
return LocalContext.current
}
// @Composable
// fun getActivityContext(): Context {
// return LocalContext.current
// }
/**
* 获取当前 Composable 的 View
*/
@Composable
fun getLocalView(): View {
return LocalView.current
}
// @Composable
// fun getLocalView(): View {
// return LocalView.current
// }
// ========== 非 Composable 环境获取 ==========
@@ -9,7 +9,7 @@ import android.os.Build
import android.os.Handler
import android.os.Looper
import android.os.Process
import com.sw.inbound.MainActivity
import com.sw.inbound.activity.HomeActivity
import timber.log.Timber
import java.io.File
import java.io.FileOutputStream
@@ -86,7 +86,7 @@ class CrashHandler private constructor(private val context: Context) :
private fun restartApp() {
// 延迟1秒后重启应用
Handler(Looper.getMainLooper()).postDelayed({
val intent = Intent(context, MainActivity::class.java).apply {
val intent = Intent(context, HomeActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
@@ -1,223 +1,223 @@
package com.sw.inbound.utils
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
/**
* Jetpack Compose 交互工具集
* 包含快速点击过滤、防抖、节流、双击检测、长按检测等功能
*/
object InteractionUtils {
// ======================== 点击过滤 ========================
/**
* 快速点击过滤器
* @param minInterval 最小点击间隔时间(毫秒),默认500ms
*/
class ClickFilter(private val minInterval: Long = 500L) {
private var lastClickTime: Long = 0
/**
* 处理点击事件
* @return Boolean 是否允许此次点击(true=允许,false=拦截)
*/
fun processClick(): Boolean {
val currentTime = System.currentTimeMillis()
return if (currentTime - lastClickTime > minInterval) {
lastClickTime = currentTime
true
} else {
false
}
}
/**
* 处理点击事件(带回调)
*/
fun processClick(block: () -> Unit) {
if (processClick()) {
block()
}
}
}
/**
* 记住点击过滤器
*/
@Composable
fun rememberClickFilter(minInterval: Long = 500L): ClickFilter {
return remember { ClickFilter(minInterval) }
}
// ======================== 防抖处理 ========================
/**
* 防抖工具类
* @param delayMillis 防抖延迟时间(毫秒)
*/
class Debouncer(private val delayMillis: Long) {
private var lastActionTime = 0L
/**
* 执行防抖操作
* @param block 要执行的代码块
* @return Boolean 是否实际执行了操作
*/
fun debounce(block: () -> Unit): Boolean {
val currentTime = System.currentTimeMillis()
if (currentTime - lastActionTime >= delayMillis) {
lastActionTime = currentTime
block()
return true
}
return false
}
}
// ======================== 双击检测 ========================
/**
* 双击检测器
*/
class DoubleClickDetector(
private val timeout: Long = 500L,
private val onSingleClick: () -> Unit = {},
private val onDoubleClick: () -> Unit
) {
private var clickCount by mutableIntStateOf(0)
private var lastClickTime by mutableLongStateOf(0L)
/**
* 处理点击事件
*/
fun processClick(coroutineScope: CoroutineScope) {
val currentTime = System.currentTimeMillis()
if (currentTime - lastClickTime < timeout) {
clickCount++
if (clickCount == 2) {
onDoubleClick()
clickCount = 0
}
} else {
clickCount = 1
coroutineScope.launch {
delay(timeout)
if (clickCount == 1) {
onSingleClick()
}
clickCount = 0
}
}
lastClickTime = currentTime
}
}
/**
* 记住双击检测器
*/
@Composable
fun rememberDoubleClickDetector(
timeout: Long = 300L,
onSingleClick: () -> Unit = {},
onDoubleClick: () -> Unit
): () -> Unit {
val detector = remember { DoubleClickDetector(timeout, onSingleClick, onDoubleClick) }
val scope = rememberCoroutineScope()
return {
detector.processClick(scope)
}
}
// ======================== 长按检测 ========================
/**
* 长按检测器
*/
class LongPressDetector(
private val delay: Long = 1000L,
private val onLongPress: () -> Unit,
private val onClick: () -> Unit = {}
) {
private var pressJob: Job? = null
/**
* 处理按压事件
*/
fun handlePress(coroutineScope: CoroutineScope) {
pressJob = coroutineScope.launch {
delay(delay)
onLongPress()
}
}
/**
* 处理释放事件
*/
fun handleRelease() {
pressJob?.cancel()
pressJob = null
onClick()
}
}
/**
* 记住长按检测器
*/
@Composable
fun rememberLongPressDetector(
delay: Long = 1000L,
onLongPress: () -> Unit,
onClick: () -> Unit = {}
): Pair<() -> Unit, () -> Unit> {
val detector = remember { LongPressDetector(delay, onLongPress, onClick) }
val scope = rememberCoroutineScope()
return Pair(
first = { detector.handlePress(scope) },
second = { detector.handleRelease() }
)
}
// ======================== 组合工具 ========================
/**
* 带状态的按钮控制器
*/
class StatefulButtonController {
var isLoading by mutableStateOf(false)
private val clickFilter = ClickFilter()
/**
* 处理按钮点击
*/
suspend fun handleClick(block: suspend () -> Unit) {
if (clickFilter.processClick()) {
isLoading = true
try {
block()
} finally {
isLoading = false
}
}
}
}
/**
* 记住带状态的按钮控制器
*/
@Composable
fun rememberStatefulButtonController(): StatefulButtonController {
return remember { StatefulButtonController() }
}
}
//package com.sw.inbound.utils
//
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableIntStateOf
//import androidx.compose.runtime.mutableLongStateOf
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.rememberCoroutineScope
//import androidx.compose.runtime.setValue
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.Job
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.launch
//
///**
// * Jetpack Compose 交互工具集
// * 包含快速点击过滤、防抖、节流、双击检测、长按检测等功能
// */
//object InteractionUtils {
//
// // ======================== 点击过滤 ========================
//
// /**
// * 快速点击过滤器
// * @param minInterval 最小点击间隔时间(毫秒),默认500ms
// */
// class ClickFilter(private val minInterval: Long = 500L) {
// private var lastClickTime: Long = 0
//
// /**
// * 处理点击事件
// * @return Boolean 是否允许此次点击(true=允许,false=拦截)
// */
// fun processClick(): Boolean {
// val currentTime = System.currentTimeMillis()
// return if (currentTime - lastClickTime > minInterval) {
// lastClickTime = currentTime
// true
// } else {
// false
// }
// }
//
// /**
// * 处理点击事件(带回调)
// */
// fun processClick(block: () -> Unit) {
// if (processClick()) {
// block()
// }
// }
// }
//
// /**
// * 记住点击过滤器
// */
// @Composable
// fun rememberClickFilter(minInterval: Long = 500L): ClickFilter {
// return remember { ClickFilter(minInterval) }
// }
//
// // ======================== 防抖处理 ========================
//
// /**
// * 防抖工具类
// * @param delayMillis 防抖延迟时间(毫秒)
// */
// class Debouncer(private val delayMillis: Long) {
// private var lastActionTime = 0L
//
// /**
// * 执行防抖操作
// * @param block 要执行的代码块
// * @return Boolean 是否实际执行了操作
// */
// fun debounce(block: () -> Unit): Boolean {
// val currentTime = System.currentTimeMillis()
// if (currentTime - lastActionTime >= delayMillis) {
// lastActionTime = currentTime
// block()
// return true
// }
// return false
// }
// }
// // ======================== 双击检测 ========================
//
// /**
// * 双击检测器
// */
// class DoubleClickDetector(
// private val timeout: Long = 500L,
// private val onSingleClick: () -> Unit = {},
// private val onDoubleClick: () -> Unit
// ) {
// private var clickCount by mutableIntStateOf(0)
// private var lastClickTime by mutableLongStateOf(0L)
//
// /**
// * 处理点击事件
// */
// fun processClick(coroutineScope: CoroutineScope) {
// val currentTime = System.currentTimeMillis()
// if (currentTime - lastClickTime < timeout) {
// clickCount++
// if (clickCount == 2) {
// onDoubleClick()
// clickCount = 0
// }
// } else {
// clickCount = 1
// coroutineScope.launch {
// delay(timeout)
// if (clickCount == 1) {
// onSingleClick()
// }
// clickCount = 0
// }
// }
// lastClickTime = currentTime
// }
// }
//
// /**
// * 记住双击检测器
// */
// @Composable
// fun rememberDoubleClickDetector(
// timeout: Long = 300L,
// onSingleClick: () -> Unit = {},
// onDoubleClick: () -> Unit
// ): () -> Unit {
// val detector = remember { DoubleClickDetector(timeout, onSingleClick, onDoubleClick) }
// val scope = rememberCoroutineScope()
//
// return {
// detector.processClick(scope)
// }
// }
//
// // ======================== 长按检测 ========================
//
// /**
// * 长按检测器
// */
// class LongPressDetector(
// private val delay: Long = 1000L,
// private val onLongPress: () -> Unit,
// private val onClick: () -> Unit = {}
// ) {
// private var pressJob: Job? = null
//
// /**
// * 处理按压事件
// */
// fun handlePress(coroutineScope: CoroutineScope) {
// pressJob = coroutineScope.launch {
// delay(delay)
// onLongPress()
// }
// }
//
// /**
// * 处理释放事件
// */
// fun handleRelease() {
// pressJob?.cancel()
// pressJob = null
// onClick()
// }
// }
//
// /**
// * 记住长按检测器
// */
// @Composable
// fun rememberLongPressDetector(
// delay: Long = 1000L,
// onLongPress: () -> Unit,
// onClick: () -> Unit = {}
// ): Pair<() -> Unit, () -> Unit> {
// val detector = remember { LongPressDetector(delay, onLongPress, onClick) }
// val scope = rememberCoroutineScope()
//
// return Pair(
// first = { detector.handlePress(scope) },
// second = { detector.handleRelease() }
// )
// }
//
// // ======================== 组合工具 ========================
//
// /**
// * 带状态的按钮控制器
// */
// class StatefulButtonController {
// var isLoading by mutableStateOf(false)
// private val clickFilter = ClickFilter()
//
// /**
// * 处理按钮点击
// */
// suspend fun handleClick(block: suspend () -> Unit) {
// if (clickFilter.processClick()) {
// isLoading = true
// try {
// block()
// } finally {
// isLoading = false
// }
// }
// }
// }
//
// /**
// * 记住带状态的按钮控制器
// */
// @Composable
// fun rememberStatefulButtonController(): StatefulButtonController {
// return remember { StatefulButtonController() }
// }
//}
@@ -5,9 +5,9 @@ import android.net.Uri
import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCaptureException
import androidx.camera.view.CameraController
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.remember
//import androidx.compose.ui.platform.LocalContext
import androidx.core.content.ContextCompat
import timber.log.Timber
import java.io.File
@@ -101,21 +101,21 @@ class PhotoCaptureHelper(
* @param onError (String) -> Unit 拍照失败回调
* @return Pair<PhotoCaptureHelper, () -> Unit> 返回工具类实例和拍照函数
*/
@Composable
fun rememberPhotoCapture(
cameraController: CameraController,
onSuccess: (Uri) -> Unit = {},
onError: (String) -> Unit = {}
): Pair<PhotoCaptureHelper, () -> Unit> {
val context = LocalContext.current
val photoCaptureHelper = remember {
PhotoCaptureHelper(
context = context,
cameraController = cameraController,
onSuccess = onSuccess,
onError = onError
)
}
return Pair(photoCaptureHelper) { photoCaptureHelper.takePhoto() }
}
//@Composable
//fun rememberPhotoCapture(
// cameraController: CameraController,
// onSuccess: (Uri) -> Unit = {},
// onError: (String) -> Unit = {}
//): Pair<PhotoCaptureHelper, () -> Unit> {
// val context = LocalContext.current
// val photoCaptureHelper = remember {
// PhotoCaptureHelper(
// context = context,
// cameraController = cameraController,
// onSuccess = onSuccess,
// onError = onError
// )
// }
//
// return Pair(photoCaptureHelper) { photoCaptureHelper.takePhoto() }
//}
@@ -1,56 +1,56 @@
package com.sw.inbound.utils
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.delay
object ToastUtils {
private var show by mutableStateOf(false)
private var message by mutableStateOf("")
fun showToast(msg: String) {
message = msg
show = true
// Toast.makeText(ContextUtils.getAppContext(), msg, Toast.LENGTH_LONG).show()
}
@Composable
fun ToastComposable() {
if (show) {
LaunchedEffect(Unit) {
delay(2000) // 自动2秒后消失
show = false
}
Box(
modifier = Modifier
// .fillMaxWidth()
.fillMaxSize()
.padding(bottom = 156.dp),
contentAlignment = Alignment.BottomCenter
) {
Text(
text = message,
modifier = Modifier
.background(Color.Black.copy(alpha = 0.7f), RoundedCornerShape(8.dp))
.padding(horizontal = 24.dp, vertical = 12.dp),
color = Color.White,
fontSize = 24.sp
)
}
}
}
}
//package com.sw.inbound.utils
//
//import androidx.compose.foundation.background
//import androidx.compose.foundation.layout.Box
//import androidx.compose.foundation.layout.fillMaxSize
//import androidx.compose.foundation.layout.padding
//import androidx.compose.foundation.shape.RoundedCornerShape
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.LaunchedEffect
//import androidx.compose.runtime.getValue
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.setValue
//import androidx.compose.ui.Alignment
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.graphics.Color
//import androidx.compose.ui.unit.dp
//import androidx.compose.ui.unit.sp
//import kotlinx.coroutines.delay
//
//object ToastUtils {
// private var show by mutableStateOf(false)
// private var message by mutableStateOf("")
//
// fun showToast(msg: String) {
// message = msg
// show = true
//// Toast.makeText(ContextUtils.getAppContext(), msg, Toast.LENGTH_LONG).show()
// }
//
// @Composable
// fun ToastComposable() {
// if (show) {
// LaunchedEffect(Unit) {
// delay(2000) // 自动2秒后消失
// show = false
// }
// Box(
// modifier = Modifier
//// .fillMaxWidth()
// .fillMaxSize()
// .padding(bottom = 156.dp),
// contentAlignment = Alignment.BottomCenter
// ) {
// Text(
// text = message,
// modifier = Modifier
// .background(Color.Black.copy(alpha = 0.7f), RoundedCornerShape(8.dp))
// .padding(horizontal = 24.dp, vertical = 12.dp),
// color = Color.White,
// fontSize = 24.sp
// )
// }
// }
// }
//}
@@ -14,7 +14,7 @@ import com.sw.inbound.network.LoadingState
import com.sw.inbound.objbox.FoodModule
import com.sw.inbound.repository.RemoteRepository
import com.sw.inbound.utils.SPUtil
import com.sw.inbound.utils.ToastUtils
//import com.sw.inbound.utils.ToastUtils
import com.sw.inbound.utils.ext.toType
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.MutableStateFlow
@@ -113,7 +113,7 @@ abstract class BaseViewModel(
is HttpException -> "服务器错误: ${e.code()}"
else -> "操作失败: ${e.message}"
}
ToastUtils.showToast(message)
//ToastUtils.showToast(message)
}
// fun startSensorScale() {
@@ -6,7 +6,7 @@ import com.sw.inbound.model.response.EquipmentInfo
import com.sw.inbound.repository.RemoteRepository
import com.sw.inbound.utils.GsonUtils
import com.sw.inbound.utils.SPUtil
import com.sw.inbound.utils.ToastUtils
//import com.sw.inbound.utils.ToastUtils
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
@@ -45,7 +45,7 @@ class DeviceViewModel @Inject constructor(
Timber.e(e)
}
} else {
ToastUtils.showToast("获取设备信息失败")
//ToastUtils.showToast("获取设备信息失败")
}
}
}
@@ -1,8 +1,5 @@
package com.sw.inbound.viewmodel
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import com.sw.inbound.GlobalData
import com.sw.inbound.GlobalKey
import com.sw.inbound.model.request.LoginParam