This commit is contained in:
2026-02-02 09:15:25 +08:00
parent af120eabd0
commit 943f969e98
2 changed files with 42 additions and 33 deletions
@@ -16,6 +16,7 @@
package com.sw.inbound.objbox
import android.annotation.SuppressLint
import android.content.Context
import android.os.Environment
import android.util.Log
@@ -51,6 +52,7 @@ import kotlin.jvm.javaClass
* Singleton to keep BoxStore reference and provide current list of Notes Objects.
* Inserts demo data if no Objects are stored.
*/
@SuppressLint("LogNotTimber")
object ObjectBox {
// 确保所有设备/版本使用相同的objectbox-models/default.json
@@ -76,8 +78,8 @@ object ObjectBox {
boxStore = try {
MyObjectBox.builder()
.androidContext(context.applicationContext)
.disableMultiProcess() // 开启多进程支持(按需关闭,单进程可删)
.disableFileCompression() // 禁用文件压缩,避免存储异常
//.disableMultiProcess() // 开启多进程支持(按需关闭,单进程可删)
//.disableFileCompression() // 禁用文件压缩,避免存储异常
.build()
} catch (e: DbException) {
if (e.javaClass == DbException::class.java || e is FileCorruptException) {
@@ -149,7 +151,7 @@ object ObjectBox {
}
}
suspend fun query(floatArray: FloatArray?, queryCount: Int) = safeDbOp {
suspend fun query(floatArray: FloatArray, queryCount: Int) = safeDbOp {
val query: Query<Food>? = getBox<Food>()?.query(
Food_.foodVector
.nearestNeighbors(floatArray, queryCount)
@@ -89,9 +89,10 @@
<FrameLayout
android:id="@+id/flPreview"
android:layout_width="420dp"
android:layout_height="420dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="@id/layoutTop"
app:layout_constraintTop_toBottomOf="@id/layoutTop">
app:layout_constraintTop_toBottomOf="@id/layoutTop"
app:layout_constraintBottom_toTopOf="@+id/layoutButton">
<androidx.cardview.widget.CardView
android:id="@+id/flCameraPreview"
@@ -130,37 +131,43 @@
</LinearLayout>
</FrameLayout>
<TextView
android:id="@+id/btnTakePhoto"
android:layout_width="270dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@drawable/bg_white_stroke_blue_ripple"
android:gravity="center"
android:text="拍照"
android:textColor="#FF0032C8"
android:textSize="36sp"
android:textStyle="bold"
<LinearLayout
android:id="@+id/layoutButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@id/flPreview"
app:layout_constraintStart_toStartOf="@id/flPreview"
app:layout_constraintTop_toBottomOf="@id/flPreview" />
app:layout_constraintBottom_toBottomOf="parent"
android:orientation="vertical">
<TextView
android:id="@+id/btnClearData"
android:layout_width="270dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@drawable/bg_white_stroke_blue_ripple"
android:gravity="center"
android:text="清除"
android:textColor="#FF0032C8"
android:textSize="36sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="@id/btnTakePhoto"
app:layout_constraintStart_toStartOf="@id/btnTakePhoto"
app:layout_constraintTop_toBottomOf="@id/btnTakePhoto" />
<TextView
android:id="@+id/btnTakePhoto"
android:layout_width="270dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:background="@drawable/bg_white_stroke_blue_ripple"
android:gravity="center"
android:text="拍照"
android:textColor="#FF0032C8"
android:textSize="36sp"
android:textStyle="bold" />
<TextView
android:id="@+id/btnClearData"
android:layout_width="270dp"
android:layout_height="90dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:background="@drawable/bg_white_stroke_blue_ripple"
android:gravity="center"
android:text="清除"
android:textColor="#FF0032C8"
android:textSize="36sp"
android:textStyle="bold" />
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rvFoodCollection"