制作模式、采样模式数据保存支持多食堂模式,制作模式查询菜品列表和搜索菜品增加餐次字段,设置页面增加隐藏默认数据导入功能
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
|
||||
import android.content.Context
|
||||
import com.google.gson.Gson
|
||||
import org.json.JSONObject
|
||||
import java.io.BufferedReader
|
||||
import java.io.InputStreamReader
|
||||
|
||||
object JsonAssetsLoader {
|
||||
// 方法1:使用BufferedReader逐行读取(适合大文件)
|
||||
fun loadJsonFromAssets(context: Context, fileName: String): String {
|
||||
val stringBuilder = StringBuilder()
|
||||
try {
|
||||
context.assets.open(fileName).use { inputStream ->
|
||||
BufferedReader(InputStreamReader(inputStream)).use { reader ->
|
||||
var line: String?
|
||||
while (reader.readLine().also { line = it } != null) {
|
||||
stringBuilder.append(line)
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return stringBuilder.toString()
|
||||
}
|
||||
|
||||
// 方法2:使用Gson解析到数据类
|
||||
inline fun <reified T> parseJsonFromAssets(
|
||||
context: Context,
|
||||
fileName: String
|
||||
): T? {
|
||||
return try {
|
||||
Gson().fromJson(
|
||||
loadJsonFromAssets(context, fileName),
|
||||
T::class.java
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
// 方法3:使用原生JSONObject解析
|
||||
fun getJsonObjectFromAssets(
|
||||
context: Context,
|
||||
fileName: String
|
||||
): JSONObject? {
|
||||
return try {
|
||||
JSONObject(loadJsonFromAssets(context, fileName))
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.shuwei.dish.match.utils
|
||||
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.os.SystemClock
|
||||
import android.view.View
|
||||
import java.util.Arrays
|
||||
|
||||
class MultiClickDetector(private val targetCount: Int = 10,
|
||||
private val intervalMs: Long = 500) {
|
||||
private var clickCount = 0
|
||||
private val clickTimestamps = LongArray(targetCount)
|
||||
private val handler = Handler(Looper.getMainLooper())
|
||||
private lateinit var callback: () -> Unit
|
||||
|
||||
fun setOnMultiClickListener(view: View, action: () -> Unit) {
|
||||
callback = action
|
||||
view.setOnClickListener {
|
||||
System.arraycopy(clickTimestamps, 1, clickTimestamps, 0, targetCount - 1)
|
||||
clickTimestamps[targetCount - 1] = SystemClock.uptimeMillis()
|
||||
|
||||
if (clickTimestamps[0] >= SystemClock.uptimeMillis() - intervalMs) {
|
||||
callback.invoke()
|
||||
resetCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 使用Handler的延迟检测方案
|
||||
fun setOnDelayedMultiClickListener(view: View, action: () -> Unit) {
|
||||
callback = action
|
||||
view.setOnClickListener {
|
||||
clickCount++
|
||||
handler.removeCallbacks(resetTask)
|
||||
handler.postDelayed(resetTask, intervalMs)
|
||||
|
||||
if (clickCount >= targetCount) {
|
||||
callback.invoke()
|
||||
resetCount()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val resetTask = Runnable { resetCount() }
|
||||
private fun resetCount() {
|
||||
clickCount = 0
|
||||
Arrays.fill(clickTimestamps, 0L)
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,9 @@ class SwipeCallback(
|
||||
viewHolder: RecyclerView.ViewHolder
|
||||
): Int {
|
||||
val position = viewHolder.getBindingAdapterPosition()
|
||||
if (position < 0) {
|
||||
return makeMovementFlags(0, 0)
|
||||
}
|
||||
// 默认的拖动和滑动方向
|
||||
val dragFlags = 0
|
||||
// ItemTouchHelper.UP or ItemTouchHelper.DOWN
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.os.Build
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
import android.util.Log
|
||||
import android.util.SparseIntArray
|
||||
import com.aithings.Weigher
|
||||
import com.shuwei.dish.match.base.BaseApp
|
||||
import com.shuwei.dish.match.utils.ext.toast
|
||||
@@ -11,6 +12,8 @@ import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||
|
||||
object WeightUtil {
|
||||
|
||||
val weightArray = SparseIntArray()
|
||||
|
||||
fun connect(initCallback: (connect: Boolean) -> Unit) {
|
||||
Weigher.setListener(object : WeightListenerImpl() {
|
||||
override fun onInit(connect: Boolean) {
|
||||
@@ -39,7 +42,8 @@ object WeightUtil {
|
||||
else -> ""
|
||||
}
|
||||
val result1 = String.format("$stateStr 重量:%s kg", weight / 1000f)
|
||||
Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
|
||||
//Log.d("WeightUtil", "ttlReturn, address:$address,$result1")
|
||||
weightArray.put(address, weight)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -163,7 +163,7 @@ fun EditText.addOnActionSearchListener(searchCallback: () -> Unit) {
|
||||
}
|
||||
|
||||
|
||||
fun View.clickWithDebounce(delay: Long = 500, action: () -> Unit) {
|
||||
fun View.clickWithDebounce(delay: Long = 300, action: () -> Unit) {
|
||||
var job: Job? = null
|
||||
setOnClickListener {
|
||||
job?.cancel()
|
||||
|
||||
Reference in New Issue
Block a user