ErrorFragment.kt (2195B)
1 /* 2 * This file is part of GNU Taler 3 * (C) 2020 Taler Systems S.A. 4 * 5 * GNU Taler is free software; you can redistribute it and/or modify it under the 6 * terms of the GNU General Public License as published by the Free Software 7 * Foundation; either version 3, or (at your option) any later version. 8 * 9 * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 * A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License along with 14 * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 */ 16 17 package net.taler.cashier.withdraw 18 19 import android.os.Bundle 20 import android.view.LayoutInflater 21 import android.view.View 22 import android.view.ViewGroup 23 import androidx.fragment.app.Fragment 24 import androidx.fragment.app.activityViewModels 25 import androidx.navigation.fragment.findNavController 26 import net.taler.cashier.MainViewModel 27 import net.taler.cashier.R 28 import net.taler.cashier.databinding.FragmentErrorBinding 29 30 class ErrorFragment : Fragment() { 31 32 private val viewModel: MainViewModel by activityViewModels() 33 private val withdrawManager by lazy { viewModel.withdrawManager } 34 35 private lateinit var ui: FragmentErrorBinding 36 37 override fun onCreateView( 38 inflater: LayoutInflater, container: ViewGroup?, 39 savedInstanceState: Bundle?, 40 ): View { 41 ui = FragmentErrorBinding.inflate(inflater, container, false) 42 return ui.root 43 } 44 45 override fun onViewCreated(view: View, savedInstanceState: Bundle?) { 46 withdrawManager.withdrawStatus.observe(viewLifecycleOwner) { status -> 47 if (status == null) return@observe 48 if (status is WithdrawStatus.Aborted) { 49 ui.textView.setText(R.string.transaction_aborted) 50 } else if (status is WithdrawStatus.Error) { 51 ui.textView.text = status.msg 52 } 53 withdrawManager.completeTransaction() 54 } 55 ui.backButton.setOnClickListener { 56 findNavController().popBackStack() 57 } 58 } 59 60 }