From db8b71418b766258a7a4bda91e496b1b03cb28cd Mon Sep 17 00:00:00 2001 From: Torsten Grote Date: Fri, 20 Mar 2020 15:43:23 -0300 Subject: Let all apps use the same Amount class The wallet now also uses taler-kotlin-common --- .../java/net/taler/wallet/payment/ContractTerms.kt | 56 ---------------------- .../net/taler/wallet/payment/PaymentManager.kt | 5 +- .../wallet/payment/PaymentSuccessfulFragment.kt | 2 +- .../net/taler/wallet/payment/ProductAdapter.kt | 3 +- .../taler/wallet/payment/PromptPaymentFragment.kt | 14 +++--- 5 files changed, 12 insertions(+), 68 deletions(-) delete mode 100644 wallet/src/main/java/net/taler/wallet/payment/ContractTerms.kt (limited to 'wallet/src/main/java/net/taler/wallet/payment') diff --git a/wallet/src/main/java/net/taler/wallet/payment/ContractTerms.kt b/wallet/src/main/java/net/taler/wallet/payment/ContractTerms.kt deleted file mode 100644 index da91dea..0000000 --- a/wallet/src/main/java/net/taler/wallet/payment/ContractTerms.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of GNU Taler - * (C) 2020 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.payment - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties -import com.fasterxml.jackson.annotation.JsonProperty -import net.taler.wallet.Amount - - -@JsonIgnoreProperties(ignoreUnknown = true) -data class ContractTerms( - val summary: String, - val products: List, - val amount: Amount -) - -interface Product { - val id: String? - val description: String - val price: Amount - val location: String? - val image: String? -} - -@JsonIgnoreProperties("totalPrice") -data class ContractProduct( - @JsonProperty("product_id") - override val id: String?, - override val description: String, - override val price: Amount, - @JsonProperty("delivery_location") - override val location: String?, - override val image: String?, - val quantity: Int -) : Product { - - val totalPrice: Amount by lazy { - val amount = price.amount.toDouble() * quantity - Amount(price.currency, amount.toString()) - } - -} diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt index ee0edaf..8aaebbc 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentManager.kt @@ -22,7 +22,8 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.module.kotlin.readValue -import net.taler.wallet.Amount +import net.taler.common.Amount +import net.taler.common.ContractTerms import net.taler.wallet.TAG import net.taler.wallet.backend.WalletBackendApi import org.json.JSONObject @@ -79,7 +80,7 @@ class PaymentManager( "payment-possible" -> PayStatus.Prepared( contractTerms = getContractTerms(json), proposalId = json.getString("proposalId"), - totalFees = Amount.fromJson(json.getJSONObject("totalFees")) + totalFees = Amount.fromJsonObject(json.getJSONObject("totalFees")) ) "paid" -> PayStatus.AlreadyPaid(getContractTerms(json)) "insufficient-balance" -> PayStatus.InsufficientBalance(getContractTerms(json)) diff --git a/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt index 2084c45..2a868b0 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PaymentSuccessfulFragment.kt @@ -23,8 +23,8 @@ import android.view.ViewGroup import androidx.fragment.app.Fragment import androidx.navigation.fragment.findNavController import kotlinx.android.synthetic.main.fragment_payment_successful.* +import net.taler.common.fadeIn import net.taler.wallet.R -import net.taler.wallet.fadeIn /** * Fragment that shows the success message for a payment. diff --git a/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt b/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt index 4b1b062..24bbd27 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/ProductAdapter.kt @@ -28,6 +28,7 @@ import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.ViewHolder +import net.taler.common.ContractProduct import net.taler.wallet.R import net.taler.wallet.payment.ProductAdapter.ProductViewHolder @@ -76,7 +77,7 @@ internal class ProductAdapter(private val listener: ProductImageClickListener) : } else { image.visibility = VISIBLE // product.image was validated before, so non-null below - val match = REGEX_PRODUCT_IMAGE.matchEntire(product.image)!! + val match = REGEX_PRODUCT_IMAGE.matchEntire(product.image!!)!! val decodedString = Base64.decode(match.groups[2]!!.value, Base64.DEFAULT) val bitmap = decodeByteArray(decodedString, 0, decodedString.size) image.setImageBitmap(bitmap) diff --git a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt index 44dcf26..2eea59e 100644 --- a/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt +++ b/wallet/src/main/java/net/taler/wallet/payment/PromptPaymentFragment.kt @@ -16,7 +16,6 @@ package net.taler.wallet.payment -import android.annotation.SuppressLint import android.graphics.Bitmap import android.os.Bundle import android.view.LayoutInflater @@ -33,11 +32,12 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.transition.TransitionManager.beginDelayedTransition import kotlinx.android.synthetic.main.payment_bottom_bar.* import kotlinx.android.synthetic.main.payment_details.* -import net.taler.wallet.Amount +import net.taler.common.Amount +import net.taler.common.ContractTerms +import net.taler.common.fadeIn +import net.taler.common.fadeOut import net.taler.wallet.R import net.taler.wallet.WalletViewModel -import net.taler.wallet.fadeIn -import net.taler.wallet.fadeOut /** * Show a payment and ask the user to accept/decline. @@ -144,11 +144,9 @@ class PromptPaymentFragment : Fragment(), ProductImageClickListener { adapter.setItems(contractTerms.products) if (contractTerms.products.size == 1) paymentManager.toggleDetailsShown() val amount = contractTerms.amount - @SuppressLint("SetTextI18n") - totalView.text = "${amount.amount} ${amount.currency}" + totalView.text = amount.toString() if (totalFees != null && !totalFees.isZero()) { - val fee = "${totalFees.amount} ${totalFees.currency}" - feeView.text = getString(R.string.payment_fee, fee) + feeView.text = getString(R.string.payment_fee, totalFees) feeView.fadeIn() } else { feeView.visibility = GONE -- cgit v1.2.3