搜索菜品入库改为自动拍照保存,取消手动拍照操作;增加向量数据库相关日志

This commit is contained in:
mazengfei
2026-03-03 15:39:11 +08:00
parent b034e9371f
commit 9a5258ad34
10 changed files with 157 additions and 95 deletions
@@ -13,14 +13,14 @@ class CameraUtils(private var activity: ComponentActivity) {
private var photoCaptureHelper: PhotoCaptureHelper? = null
// private var isCameraReady = false
fun takePhoto(callback: (Uri) -> Unit) {
fun takePhoto(successCallback: (Uri) -> Unit) {
cameraController?.let {
if (photoCaptureHelper == null) {
initCaptureHelper()
}
}
photoCaptureHelper?.let {
it.addSuccessCallback(callback)
it.addSuccessCallback(successCallback)
it.bindCameraCallback {
bind()
}
@@ -28,6 +28,11 @@ class CameraUtils(private var activity: ComponentActivity) {
}
}
private var failCallback:(()-> Unit)?=null
fun addFailCallback(callback:()->Unit) {
failCallback = callback
}
private fun initCaptureHelper() {
photoCaptureHelper = PhotoCaptureHelper(
context = activity,
@@ -35,6 +40,7 @@ class CameraUtils(private var activity: ComponentActivity) {
onSuccess = {},
onError = { msg ->
//toast(msg)
failCallback?.invoke()
}
)
}
@@ -29,7 +29,6 @@ class CrashHandler private constructor(private val context: Context) :
companion object {
private const val TAG = "CrashHandler"
private const val CRASH_REPORTS_DIR = "crash_reports"
private const val LOG_LINES = 500 // 收集最近500行日志
@Volatile
@@ -109,7 +108,7 @@ class CrashHandler private constructor(private val context: Context) :
val crashInfo = collectCrashInfo(thread, ex)
// 保存日志文件
saveCrashInfoToFile(crashInfo)
LogSaveUtil.saveLogFile("yyyy-MM-dd_HH-mm-ss",crashInfo)
// 这里可以添加其他处理逻辑,比如上传到服务器等
}
@@ -203,36 +202,11 @@ class CrashHandler private constructor(private val context: Context) :
}
}
private fun saveLog(logInfo:String) {
val time = SimpleDateFormat("yyyy-MM-dd_HH-mm-ss", Locale.getDefault()).format(Date())
val fileName = "crash_$time.log"
val crashDir = getCrashDir()
val crashFile = File(crashDir, fileName)
FileOutputStream(crashFile).use { it.write(logInfo.toByteArray()) }
Timber.tag(TAG).d("Crash info saved to: ${crashFile.absolutePath}")
}
private fun saveCrashInfoToFile(crashInfo: String) {
try {
saveLog(crashInfo)
} catch (e: Exception) {
Timber.tag(TAG).e(e, "Error saving crash info to file")
try {
saveLog("Error saving crash info to file:${e.message}")
} catch (e: Exception) {
Timber.tag(TAG).e(e, "save exception")
}
}
}
/**
* 清理旧的崩溃日志
*/
fun cleanupOldCrashReports(maxAgeDays: Int = 7) {
val crashDir = getCrashDir()
val crashDir = LogSaveUtil.getCrashDir()
if (!crashDir.exists() || !crashDir.isDirectory) return
val now = System.currentTimeMillis()
@@ -245,17 +219,4 @@ class CrashHandler private constructor(private val context: Context) :
}
}
private fun getCrashDir():File {
//val crashDir = File(context.getExternalFilesDir(null), CRASH_REPORTS_DIR)
var crashDir = File(context.filesDir, CRASH_REPORTS_DIR)
if (!crashDir.exists()) {
crashDir.mkdirs()
}
if (!(crashDir.exists())) {
crashDir = File(context.cacheDir, CRASH_REPORTS_DIR)
}
return crashDir
}
}
@@ -0,0 +1,60 @@
package com.sw.inbound.utils
import com.sw.inbound.MyApp
import timber.log.Timber
import java.io.File
import java.io.FileOutputStream
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
object LogSaveUtil {
private const val TAG = "LogSaveUtil"
private const val CRASH_REPORTS_DIR = "crash_reports"
public fun saveLogFile(msg: String) {
saveLogFile("yyyy-MM-dd", msg)
}
public fun saveLogFile(pattern: String, msg: String) {
try {
saveLog(pattern, msg)
} catch (e: Exception) {
Timber.tag(TAG).e(e, "Error saving crash info to file")
try {
saveLog(pattern, "Error saving crash info to file:${e.message}")
} catch (e: Exception) {
Timber.tag(TAG).e(e, "save exception")
}
}
}
fun saveLog(pattern: String, logInfo: String) {
val time = SimpleDateFormat(pattern, Locale.getDefault()).format(Date())
val fileName = "crash_$time.log"
val crashDir = getCrashDir()
val crashFile = File(crashDir, fileName)
val saveTime = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault()).format(Date())
FileOutputStream(crashFile, true).use { it.write("$saveTime||$logInfo\n".toByteArray()) }
Timber.tag(TAG).d("Crash info saved to: ${crashFile.absolutePath}")
}
fun getCrashDir(): File {
//val crashDir = File(context.getExternalFilesDir(null), CRASH_REPORTS_DIR)
var crashDir = File(MyApp.instance!!.filesDir, CRASH_REPORTS_DIR)
if (!crashDir.exists()) {
crashDir.mkdirs()
}
if (!(crashDir.exists())) {
crashDir = File(MyApp.instance!!.cacheDir, CRASH_REPORTS_DIR)
}
return crashDir
}
}