WithdrawalActivity.kt (4507B)
1 // This file is part of taler-cashless2ecash. 2 // Copyright (C) 2024 Joel Häberli 3 // 4 // taler-cashless2ecash is free software: you can redistribute it and/or modify it 5 // under the terms of the GNU Affero General Public License as published 6 // by the Free Software Foundation, either version 3 of the License, 7 // or (at your option) any later version. 8 // 9 // taler-cashless2ecash is distributed in the hope that it will be useful, but 10 // WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 // Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 // 17 // SPDX-License-Identifier: AGPL3.0-or-later 18 19 package ch.bfh.habej2.wallee_c2ec.withdrawal 20 21 import android.content.Intent 22 import android.os.Bundle 23 import androidx.activity.ComponentActivity 24 import androidx.activity.compose.setContent 25 import androidx.navigation.compose.NavHost 26 import androidx.navigation.compose.composable 27 import androidx.navigation.compose.rememberNavController 28 import ch.bfh.habej2.wallee_c2ec.client.wallee.WalleeResponseHandler 29 import ch.bfh.habej2.wallee_c2ec.ui.theme.Walleec2ecTheme 30 import com.wallee.android.till.sdk.ApiClient 31 import com.wallee.android.till.sdk.Utils 32 33 34 class WithdrawalActivity : ComponentActivity() { 35 36 private lateinit var walleeClient: ApiClient 37 private lateinit var model: WithdrawalViewModel 38 39 override fun onCreate(savedInstanceState: Bundle?) { 40 super.onCreate(savedInstanceState) 41 42 val walleeResponseHandler = WalleeResponseHandler(this) 43 walleeClient = ApiClient(walleeResponseHandler) 44 walleeClient.bind(this) 45 walleeClient.checkApiServiceCompatibility() 46 model = WithdrawalViewModel(walleeClient) 47 48 setContent { 49 50 val navController = rememberNavController() 51 52 var startDestination = "chooseExchangeScreen" 53 if (exchanges.size == 1) { 54 model.chooseExchange(exchanges[0], this@WithdrawalActivity) 55 startDestination = "amountScreen" 56 } 57 58 Walleec2ecTheme { 59 NavHost(navController = navController, startDestination = startDestination) { 60 composable("chooseExchangeScreen") { 61 ExchangeSelectionScreen(model, this@WithdrawalActivity) { 62 navController.navigate("amountScreen") 63 } 64 } 65 composable("amountScreen") { 66 AmountScreen(model, this@WithdrawalActivity) { 67 navController.navigate("registerParametersScreen") 68 } 69 } 70 composable("registerParametersScreen") { 71 RegisterParametersScreen(model, this@WithdrawalActivity) { 72 navController.navigate("authorizePaymentScreen") 73 } 74 } 75 composable("authorizePaymentScreen") { 76 AuthorizePaymentScreen(model, this@WithdrawalActivity, walleeClient) 77 } 78 } 79 } 80 } 81 } 82 83 override fun onNewIntent(intent: Intent?) { 84 super.onNewIntent(intent) 85 println("onNewIntent called ... setting new intent") 86 intent?.let { 87 setIntent(it) // important to update the current intent 88 } 89 } 90 91 override fun onResume() { 92 super.onResume() 93 println("onResume called") 94 95 val extras = intent.extras 96 extras?.let { 97 when { 98 it.containsKey("transactionResponse") -> { 99 val transactionResponse = Utils.getTransactionResponse(it) 100 model.updateWalleeTransactionReply(transactionResponse) 101 } 102 it.containsKey("transactionCompletionResponse") -> { 103 val transactionCompletionResponse = Utils.getTransactionCompletionResponse(it) 104 model.updateWalleeTransactionCompletion(transactionCompletionResponse) 105 } 106 } 107 } 108 } 109 110 override fun onDestroy() { 111 super.onDestroy() 112 113 try { 114 walleeClient.unbind(this) 115 } catch (ex: Exception) { 116 println("unbinding from wallee service throw error: ${ex.message}") 117 } 118 } 119 }