commit 31ba592d70bbc008f1472ac09fe2e022f3eb3d56 parent 5d4364f5a5c8e710d2224e54f07b594f8834da85 Author: fsb2 <benjamin.fehrensen@bfh.ch> Date: Thu, 3 Apr 2025 14:53:09 +0200 Crashing problem fixed. The WalleeResponseHandler must not update the paused activity Diffstat:
6 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/wallee-c2ec/.idea/runConfigurations.xml b/wallee-c2ec/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RunConfigurationProducerService"> + <option name="ignoredProducers"> + <set> + <option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" /> + <option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" /> + <option value="com.intellij.execution.junit.PatternConfigurationProducer" /> + <option value="com.intellij.execution.junit.TestInClassConfigurationProducer" /> + <option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" /> + <option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" /> + <option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" /> + <option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" /> + </set> + </option> + </component> +</project> +\ No newline at end of file diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/client/wallee/WalleeResponseHandler.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/client/wallee/WalleeResponseHandler.kt @@ -19,8 +19,11 @@ package ch.bfh.habej2.wallee_c2ec.client.wallee import android.app.Activity +import android.content.Intent +import ch.bfh.habej2.wallee_c2ec.withdrawal.WithdrawalActivity import ch.bfh.habej2.wallee_c2ec.withdrawal.WithdrawalViewModel import com.wallee.android.till.sdk.ResponseHandler +import com.wallee.android.till.sdk.Utils import com.wallee.android.till.sdk.data.FinalBalanceResult import com.wallee.android.till.sdk.data.TransactionCompletionResponse import com.wallee.android.till.sdk.data.TransactionResponse @@ -31,12 +34,10 @@ class WalleeResponseHandler( private val enableDebugLogs = true - lateinit var model: WithdrawalViewModel override fun authorizeTransactionReply(response: TransactionResponse?) { if (response == null) { - model.withdrawalOperationFailed(activity) activity.finish() return } @@ -44,13 +45,16 @@ class WalleeResponseHandler( if (enableDebugLogs) this.printTransactionResponse(response) - model.updateWalleeTransactionReply(response) + val intent = Intent(activity, WithdrawalActivity::class.java) + intent.putExtras(Utils.toBundle(response)) + intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + activity.startActivity(intent) } override fun completeTransactionReply(response: TransactionCompletionResponse?) { if (response == null) { - model.withdrawalOperationFailed(activity) + //model.withdrawalOperationFailed(activity) activity.finish() return } @@ -58,7 +62,10 @@ class WalleeResponseHandler( if (enableDebugLogs) this.printCompletionResponse(response) - model.updateWalleeTransactionCompletion(response) + val intent = Intent(activity, WithdrawalActivity::class.java) + intent.putExtras(Utils.toBundle(response)) + intent.flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP + activity.startActivity(intent) } override fun executeFinalBalanceReply(result: FinalBalanceResult?) { diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/AuthorizePaymentScreen.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/AuthorizePaymentScreen.kt @@ -61,8 +61,9 @@ fun AuthorizePaymentScreen(model: WithdrawalViewModel, activity: Activity, clien .build() try { - client.authorizeTransaction(transaction) // STOPPED + println("Authorizing transaction ...") model.setAuthorizing() + client.authorizeTransaction(transaction) // STOPPED } catch (e: Exception) { println("FAILED authorizing transaction ${e.message}") model.withdrawalOperationFailed(activity) diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/ManageActivity.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/ManageActivity.kt @@ -132,8 +132,6 @@ class ManageActivity : ComponentActivity() { val responseHandler = WalleeResponseHandler(this) walleeClient = ApiClient(responseHandler) walleeClient.bind(this) - val model = WithdrawalViewModel(walleeClient) - responseHandler.model = model walleeClient.checkApiServiceCompatibility() } diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/WithdrawalActivity.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/WithdrawalActivity.kt @@ -18,6 +18,7 @@ package ch.bfh.habej2.wallee_c2ec.withdrawal +import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent @@ -26,11 +27,13 @@ import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import ch.bfh.habej2.wallee_c2ec.client.wallee.WalleeResponseHandler import com.wallee.android.till.sdk.ApiClient +import com.wallee.android.till.sdk.Utils class WithdrawalActivity : ComponentActivity() { private lateinit var walleeClient: ApiClient + private lateinit var model: WithdrawalViewModel override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -40,8 +43,7 @@ class WithdrawalActivity : ComponentActivity() { walleeClient.bind(this) walleeClient.checkApiServiceCompatibility() - val model = WithdrawalViewModel(walleeClient) - walleeResponseHandler.model = model + model = WithdrawalViewModel(walleeClient) setContent { @@ -70,6 +72,34 @@ class WithdrawalActivity : ComponentActivity() { } } + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + println("onNewIntent called ... setting new intent") + intent?.let { + setIntent(it) // important to update the current intent + } + } + + override fun onResume() { + super.onResume() + println("onResume called") + + + val extras = intent.extras + extras?.let { + when { + it.containsKey("transactionResponse") -> { + val transactionResponse = Utils.getTransactionResponse(it) + model.updateWalleeTransactionReply(transactionResponse) + } + it.containsKey("transactionCompletionResponse") -> { + val transactionCompletionResponse = Utils.getTransactionCompletionResponse(it) + model.updateWalleeTransactionCompletion(transactionCompletionResponse) + } + } + } + } + override fun onDestroy() { super.onDestroy() diff --git a/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/WithdrawalViewModel.kt b/wallee-c2ec/app/src/main/java/ch/bfh/habej2/wallee_c2ec/withdrawal/WithdrawalViewModel.kt @@ -278,6 +278,8 @@ class WithdrawalViewModel( if (!it.isPresent) { println("setting retry because no status was present") _uiState.value.setupWithdrawalRetries += 1 + } else if (uiState.value.withdrawalState == WithdrawalState.AUTHORIZATION_TRIGGERED) { + println("authorization triggered, waiting for completion") } else { println("withdrawal status: ${it.get().status }") _uiState.value.withdrawalState = WithdrawalState.READY_FOR_AUTHORIZATION