diff --git a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scalesJava/BluetoothStandardWeightProfile.java b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scalesJava/BluetoothStandardWeightProfile.java index 20a77844..bcbaa67e 100644 --- a/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scalesJava/BluetoothStandardWeightProfile.java +++ b/android_app/app/src/main/java/com/health/openscale/core/bluetooth/scalesJava/BluetoothStandardWeightProfile.java @@ -853,6 +853,42 @@ public abstract class BluetoothStandardWeightProfile extends BluetoothCommunicat choiceStrings[userList.size()] = context.getString(R.string.bluetooth_scale_info_create_user_instruction); indexArray[userList.size()] = -1; } + + if (choiceStrings != null && indexArray != null) { + StringBuilder logMessage = new StringBuilder("Preparing CHOOSE_USER interaction. "); + logMessage.append("choiceStrings (length: ").append(choiceStrings.length).append("): ["); + for (int i = 0; i < choiceStrings.length; i++) { + logMessage.append("'").append(choiceStrings[i]).append("'"); + if (i < choiceStrings.length - 1) { + logMessage.append(", "); + } + } + logMessage.append("]. "); + + logMessage.append("indexArray (length: ").append(indexArray.length).append("): ["); + for (int i = 0; i < indexArray.length; i++) { + logMessage.append(indexArray[i]); + if (i < indexArray.length - 1) { + logMessage.append(", "); + } + } + logMessage.append("]."); + LogManager.d(TAG, logMessage.toString()); + + // Check for potential issues that might lead to UI errors + if (choiceStrings.length != indexArray.length) { + LogManager.w(TAG, "CHOOSE_USER: Mismatch in lengths: choiceStrings (" + choiceStrings.length + + ") vs indexArray (" + indexArray.length + ").", null); + } + if (choiceStrings.length == 0) { + LogManager.w(TAG, "CHOOSE_USER: choiceStrings array is empty. No options will be presented to the user.", null); + } + + } else { + // This is a critical error state if either array is null + LogManager.e(TAG, "CHOOSE_USER: choiceStrings or indexArray is null. Cannot request user interaction.", null); + } + Pair choices = new Pair(choiceStrings, indexArray); requestUserInteraction(UserInteractionType.CHOOSE_USER, choices); } diff --git a/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt b/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt index c41f6927..1c6f5296 100644 --- a/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt +++ b/android_app/app/src/main/java/com/health/openscale/ui/navigation/AppNavigation.kt @@ -19,6 +19,8 @@ package com.health.openscale.ui.navigation import android.app.Application import android.content.res.Resources +import android.net.http.SslCertificate.restoreState +import android.net.http.SslCertificate.saveState import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.layout.Box @@ -108,6 +110,7 @@ import com.health.openscale.R import com.health.openscale.core.bluetooth.BluetoothEvent.UserInteractionType import com.health.openscale.core.bluetooth.scalesJava.BluetoothCommunication import com.health.openscale.core.data.User +import com.health.openscale.core.utils.LogManager import com.health.openscale.ui.navigation.Routes.getIconForRoute import com.health.openscale.ui.screen.SharedViewModel import com.health.openscale.ui.screen.bluetooth.BluetoothViewModel @@ -146,6 +149,7 @@ import kotlinx.coroutines.launch @OptIn(ExperimentalMaterial3Api::class) @Composable fun AppNavigation(sharedViewModel: SharedViewModel) { + val TAG = "AppNavigation" val context = LocalContext.current val resources = context.resources // Get resources for non-composable string access val application = context.applicationContext as Application @@ -294,13 +298,18 @@ fun AppNavigation(sharedViewModel: SharedViewModel) { when (interactionEvent.interactionType) { UserInteractionType.CHOOSE_USER -> { val choicesData = interactionEvent.data - // Wir erwarten Pair, IntArray> oder Pair, IntArray> + LogManager.d(TAG, "CHOOSE_USER interaction received. Data: $choicesData") + + // Expecting Pair, IntArray> or Pair, IntArray> if (choicesData is Pair<*, *> && choicesData.first is Array<*> && choicesData.second is IntArray) { @Suppress("UNCHECKED_CAST") val choices = choicesData as Pair, IntArray> val choiceDisplayNames = choices.first val choiceIndices = choices.second + LogManager.d(TAG, "CHOOSE_USER: DisplayNames (length ${choiceDisplayNames.size}): ${choiceDisplayNames.joinToString { "'$it'" }}") + LogManager.d(TAG, "CHOOSE_USER: Indices (length ${choiceIndices.size}): ${choiceIndices.joinToString()}") + if (choiceDisplayNames.isNotEmpty() && choiceDisplayNames.size == choiceIndices.size) { LazyColumn(modifier = Modifier.padding(top = 8.dp)) { itemsIndexed(choiceDisplayNames) { itemIndex, choiceName -> @@ -309,7 +318,10 @@ fun AppNavigation(sharedViewModel: SharedViewModel) { .fillMaxWidth() .selectable( selected = (choiceIndices[itemIndex] == selectedUserIndexState), - onClick = { selectedUserIndexState = choiceIndices[itemIndex] } + onClick = { + selectedUserIndexState = + choiceIndices[itemIndex] + } ) .padding(vertical = 8.dp), verticalAlignment = Alignment.CenterVertically