/* This file is part of GNU Taler (C) 2019 Taler Systems S.A. GNU Taler is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Taler; see the file COPYING. If not, see */ package net.taler.wallet import android.annotation.SuppressLint import android.os.Bundle import android.util.Log import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Button import android.widget.TextView import androidx.lifecycle.Observer import androidx.lifecycle.ViewModelProviders import androidx.navigation.findNavController import com.google.android.material.snackbar.Snackbar import me.zhanghai.android.materialprogressbar.MaterialProgressBar /** * Show a payment and ask the user to accept/decline. */ class PromptPayment : Fragment() { lateinit var model: WalletViewModel var fragmentView: View? = null private fun triggerLoading() { val loading = model.payStatus.value == null || (model.payStatus.value is PayStatus.Loading) val progressBar = requireActivity().findViewById(R.id.progress_bar) if (loading) { progressBar.visibility = View.VISIBLE } else { progressBar.visibility = View.INVISIBLE } } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) model = activity?.run { ViewModelProviders.of(this)[WalletViewModel::class.java] } ?: throw Exception("Invalid Activity") } override fun onResume() { super.onResume() Log.v("taler-wallet", "called onResume on PromptPayment") triggerLoading() } private fun fillOrderInfo(view: View, contractTerms: ContractTerms, totalFees: Amount?) { val feesAmountView = view.findViewById(R.id.order_fees_amount) val amountView = view.findViewById(R.id.order_amount) val summaryView = view.findViewById(R.id.order_summary) summaryView.text = contractTerms.summary val amount = contractTerms.amount @SuppressLint("SetTextI18n") amountView.text = "${amount.amount} ${amount.currency}" val feesBox = view.findViewById(R.id.order_fees_box) if (totalFees != null) { @SuppressLint("SetTextI18n") feesAmountView.text = "${totalFees.amount} ${totalFees.currency}" feesBox.visibility = View.VISIBLE } else { feesBox.visibility = View.INVISIBLE } } private fun showPayStatus(view: View, payStatus: PayStatus) { val promptPaymentDetails = view.findViewById(R.id.prompt_payment_details) val balanceInsufficientWarning = view.findViewById(R.id.balance_insufficient_warning) val errorTextView = view.findViewById(R.id.pay_error_text) val confirmPaymentButton = view.findViewById