refactor: rewrite mobile app in Compose and add error handling for wear

This commit is contained in:
2026-06-11 17:32:02 +03:00
parent 59207d3351
commit 19a571ac06
40 changed files with 1003 additions and 608 deletions
@@ -2,7 +2,6 @@ package ru.omni_devel.cards
import android.content.Context
import android.graphics.Bitmap
import android.widget.Toast
import com.google.android.gms.wearable.Wearable
import com.google.zxing.BarcodeFormat
import com.google.zxing.MultiFormatWriter
@@ -10,16 +9,14 @@ import com.journeyapps.barcodescanner.BarcodeEncoder
fun generateCode(value: String, format: BarcodeFormat): Bitmap {
val writer = MultiFormatWriter()
val matrix = writer.encode(value, format, 600, 300)
val matrix = writer.encode(value, format, 800, 400)
return BarcodeEncoder().createBitmap(matrix)
}
fun sendToWatch(context: Context, path: String, message: String, onResult: (Boolean) -> Unit): Boolean {
fun sendToWatch(context: Context, path: String, message: String, onResult: (Boolean) -> Unit) {
val nodeClient = Wearable.getNodeClient(context)
var isSuccess = false
nodeClient.connectedNodes.addOnSuccessListener { nodes ->
if (nodes.isEmpty()) {
onResult(false)
@@ -35,7 +32,7 @@ fun sendToWatch(context: Context, path: String, message: String, onResult: (Bool
node.id,
path,
message.toByteArray(Charsets.UTF_8)
).addOnCompleteListener { task ->
).addOnCompleteListener(context.mainExecutor) { task ->
completedCount++
if (task.isSuccessful) {
@@ -45,11 +42,19 @@ fun sendToWatch(context: Context, path: String, message: String, onResult: (Bool
if (completedCount == nodes.size) {
onResult(isAnySuccess)
}
}.addOnFailureListener {
}.addOnFailureListener(context.mainExecutor) {
onResult(false)
}
}
}
}
return isSuccess
fun checkCardData(name: String, value: String): String? {
if (name.trim().isEmpty()) {
return "Name should not be empty"
} else if (value.trim().isEmpty()) {
return "Code value should not be empty"
}
return null
}