提交昨天的修改:优化多个模块和UI效果

This commit is contained in:
2026-03-17 13:42:09 +08:00
parent 3cf9818dad
commit 28c7628321
41 changed files with 991 additions and 358 deletions
@@ -1,4 +1,4 @@
package com.sw.inbound.utils
package com.shuwei.dish.match.utils
import android.content.Context
import android.graphics.Bitmap
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
import android.content.Context
import android.graphics.Bitmap
import android.os.Environment
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
import android.net.Uri
import androidx.activity.ComponentActivity
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
/**
* 防抖工具
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
import android.content.Context
import android.graphics.Bitmap
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
import android.content.Context
import android.graphics.Bitmap
@@ -1,7 +1,7 @@
package com.sw.inbound.utils
package com.shuwei.dish.match.utils
import com.sw.inbound.MyApp
import timber.log.Timber
import android.util.Log
import com.shuwei.dish.match.base.BaseApp
import java.io.File
import java.io.FileOutputStream
import java.text.SimpleDateFormat
@@ -21,11 +21,11 @@ object LogSaveUtil {
try {
saveLog(pattern, msg)
} catch (e: Exception) {
Timber.tag(TAG).e(e, "Error saving crash info to file")
Log.d(TAG, "Error saving crash info to file:${e.message}")
try {
saveLog(pattern, "Error saving crash info to file:${e.message}")
} catch (e: Exception) {
Timber.tag(TAG).e(e, "save exception")
Log.d(TAG, "save exception:${e.message}")
}
}
}
@@ -41,18 +41,18 @@ object LogSaveUtil {
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}")
Log.d(TAG,"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)
var crashDir = File(BaseApp.instance!!.filesDir, CRASH_REPORTS_DIR)
if (!crashDir.exists()) {
crashDir.mkdirs()
}
if (!(crashDir.exists())) {
crashDir = File(MyApp.instance!!.cacheDir, CRASH_REPORTS_DIR)
crashDir = File(BaseApp.instance!!.cacheDir, CRASH_REPORTS_DIR)
}
return crashDir
}
@@ -1,4 +1,4 @@
package com.sw.dualscreen.utils
package com.shuwei.dish.match.utils
import android.content.Context
import android.net.Uri
@@ -6,7 +6,6 @@ import androidx.camera.core.ImageCapture
import androidx.camera.core.ImageCaptureException
import androidx.camera.view.CameraController
import androidx.core.content.ContextCompat
import timber.log.Timber
import java.io.File
/**
@@ -43,7 +42,7 @@ class PhotoCaptureHelper(
fileNamePrefix: String = "IMG_",
fileExtension: String = ".jpg"
) {
Timber.d("开始拍照采集")
// Timber.d("开始拍照采集")
try {
val executor = ContextCompat.getMainExecutor(context)
@@ -62,7 +61,7 @@ class PhotoCaptureHelper(
object : ImageCapture.OnImageSavedCallback {
override fun onImageSaved(outputFileResults: ImageCapture.OutputFileResults) {
val photoUri = outputFileResults.savedUri ?: Uri.fromFile(photoFile)
Timber.d("照片保存成功: $photoUri")
// Timber.d("照片保存成功: $photoUri")
onSuccess(photoUri)
callbackList.forEach {
it(photoUri)
@@ -78,14 +77,14 @@ class PhotoCaptureHelper(
}
}
Timber.e(exception, errorMsg)
// Timber.e(exception, errorMsg)
onError(errorMsg)
}
}
)
} catch (e: Exception) {
val errorMsg = "创建临时文件失败: ${e.message}"
Timber.e(e, errorMsg)
// Timber.e(e, errorMsg)
onError(errorMsg)
}
}
@@ -1,6 +1,8 @@
package com.shuwei.dish.match.utils
import android.content.Context
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@@ -11,7 +13,20 @@ import com.shuwei.dish.match.R
object ToastUtil {
fun show(context: Context, message: String, duration:Int = Toast.LENGTH_SHORT) {
private val mainHandler = Handler(Looper.getMainLooper())
fun show(context: Context, message: String, duration: Int = Toast.LENGTH_SHORT) {
// 确保在主线程中执行
if (Thread.currentThread() == Looper.getMainLooper().thread) {
showToast(context, message, duration)
} else {
mainHandler.post {
showToast(context, message, duration)
}
}
}
private fun showToast(context: Context, message: String, duration: Int) {
val inflater = LayoutInflater.from(context)
val layout: View = inflater.inflate(R.layout.custom_toast, null)
val textView = layout.findViewById<TextView>(R.id.tvMessage)
@@ -22,7 +37,6 @@ object ToastUtil {
toast.setGravity(Gravity.CENTER, 0, 0) // 调整位置居中显示
toast.setDuration(duration)
toast.show()
}
}
@@ -82,6 +82,10 @@ object WeightUtil {
}
}
fun removeWeightListener(weightKey: String){
weightFuncMap?.remove(weightKey)
}
fun addWeightListener(
weightKey: String,
getWeight: WeightCallback = { _, _, _ -> }
@@ -11,11 +11,13 @@ import android.util.TypedValue
import android.view.View
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.ImageView
import android.widget.Toast
import androidx.core.app.ActivityOptionsCompat
import androidx.fragment.app.Fragment
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.shuwei.dish.match.utils.GlideUtils
import com.shuwei.dish.match.utils.ToastUtil
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
@@ -181,3 +183,6 @@ fun Double.roundedDecimalPlace(num: Int): Double {
fun Double.roundedOneDecimalPlace(): Double {
return this.roundedDecimalPlace(1)
}
fun ImageView.load(url: Any?) {
GlideUtils.loadImage(context, url, this)
}