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