改造objectbox
This commit is contained in:
@@ -71,7 +71,7 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
const val PAGE_SIZE = 30
|
||||
}
|
||||
|
||||
private var box: Box<Food>? = null
|
||||
// private var box: Box<Food>? = null
|
||||
private val collectList: MutableList<FoodCollectionBean> = mutableListOf<FoodCollectionBean>()
|
||||
private lateinit var binding: ActivityFoodCollectionBinding
|
||||
private lateinit var previewView: PreviewView
|
||||
@@ -287,11 +287,17 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private val cameraCallback: (Uri) -> Unit = { uri ->
|
||||
lifecycleScope.launch {
|
||||
handlePhoto(uri)
|
||||
}
|
||||
}
|
||||
|
||||
private suspend fun handlePhoto(uri: Uri) {
|
||||
val index = collectList.indexOfFirst { it.imageFile == null }
|
||||
if (index == -1) {
|
||||
toast("每次只允许保存${MAX_COUNT}条数据")
|
||||
showWaitingDialog2("加载中")
|
||||
rerurn@ cameraCallback
|
||||
return
|
||||
}
|
||||
// toast("index=$index")
|
||||
try {
|
||||
@@ -373,7 +379,7 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
|
||||
private fun vectorThread() {
|
||||
Loading.show(this)
|
||||
Thread {
|
||||
lifecycleScope.launch {
|
||||
collectList
|
||||
//.filter { it.bitmap != null }
|
||||
// .filter { it.imageVector != null }
|
||||
@@ -389,10 +395,10 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
toast("保存成功")
|
||||
}, 1000)
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
}
|
||||
|
||||
private fun image2VectorTask(
|
||||
private suspend fun image2VectorTask(
|
||||
bitmap: Bitmap? = null,
|
||||
imageVector: FloatArray? = null,
|
||||
position: Int
|
||||
@@ -408,9 +414,10 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
// }
|
||||
val goods = searchGoodsList[clickIndex]
|
||||
val saveName = goods.goodsName + goods.goodsCode
|
||||
ObjectBox.boxStore.runInTx {
|
||||
box?.put(Food(name = saveName, foodIdx = 0, foodVector = imageVector))
|
||||
}
|
||||
// ObjectBox.boxStore.runInTx {
|
||||
// box?.put(Food(name = saveName, foodIdx = 0, foodVector = imageVector))
|
||||
// }
|
||||
ObjectBox.put(Food(name = saveName, foodIdx = 0, foodVector = imageVector))
|
||||
collectList[position].let {
|
||||
// it.imageVector = imageVector
|
||||
it.isFinish = true
|
||||
@@ -491,9 +498,9 @@ class FoodCollectionActivity : ComponentActivity() {
|
||||
}
|
||||
|
||||
private fun initBox() {
|
||||
if (box == null) {
|
||||
box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
}
|
||||
// if (box == null) {
|
||||
// box = ObjectBox.boxStore.boxFor(Food::class)
|
||||
// }
|
||||
}
|
||||
|
||||
// private fun uploadAllImage() {
|
||||
|
||||
Reference in New Issue
Block a user