refactor: updated sync with WearOS logic

This commit is contained in:
2026-06-24 20:11:19 +03:00
parent bdde3d8fbf
commit ff214eb3d2
6 changed files with 54 additions and 18 deletions
@@ -14,7 +14,9 @@ import com.journeyapps.barcodescanner.BarcodeEncoder
import org.json.JSONObject
import java.io.ByteArrayOutputStream
import android.util.Base64
import android.widget.Toast
import androidx.compose.ui.graphics.asImageBitmap
import kotlinx.serialization.json.Json
fun generateCode(value: String, format: BarcodeFormat): Bitmap {
val writer = MultiFormatWriter()
@@ -33,12 +35,14 @@ fun generateCode(value: String, format: BarcodeFormat): Bitmap {
return BarcodeEncoder().createBitmap(matrix)
}
fun sendToWatch(context: Context, path: String, message: String, onResult: (Boolean) -> Unit) {
fun sendToWatch(context: Context, path: String, message: String): Boolean {
val nodeClient = Wearable.getNodeClient(context)
var isSuccess = false
nodeClient.connectedNodes.addOnSuccessListener { nodes ->
if (nodes.isEmpty()) {
onResult(false)
isSuccess = false
return@addOnSuccessListener
}
@@ -59,13 +63,19 @@ fun sendToWatch(context: Context, path: String, message: String, onResult: (Bool
}
if (completedCount == nodes.size) {
onResult(isAnySuccess)
isSuccess = isAnySuccess
}
}.addOnFailureListener(context.mainExecutor) {
onResult(false)
isSuccess = false
}
}
}
return isSuccess
}
fun syncCardsWithWatch(context: Context, cards: List<CardInfo>): Boolean {
return sendToWatch(context, "/updateCards", Json.encodeToString(cards))
}
fun checkCardData(name: String, value: String): Int? {